首页 > 解决方案 > 基于上下文的实体识别

问题描述

有没有办法根据句子的上下文来获取一个词属于一个实体的概率。例如(实体:server_name)

“我想检查 mogo 服务器” 结果将是例如:

莫戈:服务器名称,0.5688999

“检查服务器 mogo 的状态” 结果将是例如:

莫戈:服务器名称,0.6272772

一种解决方案是,例如将所有服务器名称映射到 txt 文件或实体记录中以执行此操作……但在这种情况下,服务器的名称可能是一个很大的数字,因此每次我们想要一个单词确实存在的概率服务器名称,然后检查数据库/json中的服务器名称(如果存在,我们继续)如果不是,我们根据该概率询问用户(mogo)是否确实是服务器名称就像我们将它添加到数据库中所以有什么方法可以使用 nltk、spacy 或 rasa 根据句子(而不是单词 .txt 或标签)将单词提取为实体,并获得最有可能属于命名实体的单词的概率?

标签: pythonnltkspacyrasa-nlunamed-entity-recognition

解决方案


尝试使用CRF分类器。对于句子中的每个单词,您可以获得概率分数。

CRF期望训练数据为IOB 格式

这是一篇关于使用 CRF 进行 NER 检测的好博客。

例子

crf_.predict_marginals_single(sent2features_for_prediction("Bengaluru"))


[{'O': 0.0008245389052411774,
  'B-entity__location': 0.9764201257123432,
  'I-entity__location': 0.003916777298076389,
  'B-entity__other_ent': 0.003445348786883558,
  'I-entity__other_ent': 0.00012730443363195458,
  'B-entity__other_ent_2': 0.005445385992475527,
  'B-entity__other_ent_3': 3.704781572842554e-05,
  'I-entity__other_ent_3': 2.1092149059526482e-05,
  'I-entity__other_ent_2': 0.00011894529348380328,
  'B-entity__other_ent_4': 2.0753893397695066e-05,
  'I-entity__other_ent_4': 6.333056114953314e-05,
  'B-entity__other_ent_5': 0.009492141753363492,
  'I-entity__other_ent_5': 6.720740516588521e-05}]

希望这可以帮助


推荐阅读