扩展NLP实体提取

Dor*_*don 5 python nlp machine-learning polyglot named-entity-extraction

我们想从一个简单的搜索社区和各个城市的街道中进行识别。我们不仅使用英语,还使用其他西里尔语言。我们需要能够识别位置的拼写错误。在查看python库时,我发现了这个库:http : //polyglot.readthedocs.io/en/latest/NamedEntityRecognition.html

我们尝试使用它,但是找不到扩展实体识别数据库的方法。那怎么办?
如果不是,那么对于多语言nlp是否有其他建议,可以帮助进行拼写检查并提取与自定义数据库匹配的各种实体?

Mor*_*itz 1

看看HuggingFace的预训练模型。

\n
    \n
  1. 他们有一个经过 40 种语言训练的多语言 NER 模型,其中包括俄语等西里尔语言。这是 RoBERTa 的微调版本,因此准确性似乎非常好。请参阅此处的详细信息:https ://huggingface.co/jplu/tf-xlm-r-ner-40-lang
  2. \n
  3. 他们还有一个基于GitHub Typo Corpus训练的多语言 DistilBERT 模型,用于拼写错误检测。该语料库似乎包含 15 种不同语言的拼写错误,其中包括俄语。请参阅此处的详细信息: https: //huggingface.co/mrm8488/distilbert-base-multi-cased-finetuned-typo-detection
  4. \n
\n

以下是文档中的一些示例代码,根据您的用例稍作修改:

\n
from transformers import pipeline\n\ntypo_checker = pipeline("ner", model="mrm8488/distilbert-base-multi-cased-finetuned-typo-detection",\n                        tokenizer="mrm8488/distilbert-base-multi-cased-finetuned-typo-detection")\n\nresult = typo_checker("\xd1\x8f \xd0\xb6\xd0\xb8\xd0\xb2\xd1\x83 \xd0\xb2 \xd0\x9c\xd0\xbe\xd1\x81\xd0\xb2\xd0\xb5")\nresult[1:-1]\n\n #[{\'word\': \'\xd1\x8f\', \'score\': 0.7886862754821777, \'entity\': \'ok\', \'index\': 1},\n #{\'word\': \'\xd0\xb6\xd0\xb8\xd0\xb2\', \'score\': 0.6303715705871582, \'entity\': \'ok\', \'index\': 2},\n #{\'word\': \'##\xd1\x83\', \'score\': 0.7259598970413208, \'entity\': \'ok\', \'index\': 3},\n #{\'word\': \'\xd0\xb2\', \'score\': 0.7102937698364258, \'entity\': \'ok\', \'index\': 4},\n #{\'word\': \'\xd0\x9c\', \'score\': 0.5045614242553711, \'entity\': \'ok\', \'index\': 5},\n #{\'word\': \'##\xd0\xbe\xd1\x81\', \'score\': 0.560469925403595, \'entity\': \'typo\', \'index\': 6},\n #{\'word\': \'##\xd0\xb2\xd0\xb5\', \'score\': 0.8228507041931152, \'entity\': \'ok\', \'index\': 7}]\n\nresult = typo_checker("I live in Moskkow")\nresult[1:-1]\n\n #[{\'word\': \'I\', \'score\': 0.7598089575767517, \'entity\': \'ok\', \'index\': 1},\n #{\'word\': \'live\', \'score\': 0.8173692226409912, \'entity\': \'ok\', \'index\': 2},\n #{\'word\': \'in\', \'score\': 0.8289134502410889, \'entity\': \'ok\', \'index\': 3},\n #{\'word\': \'Mo\', \'score\': 0.7344270944595337, \'entity\': \'ok\', \'index\': 4},\n #{\'word\': \'##sk\', \'score\': 0.6559176445007324, \'entity\': \'ok\', \'index\': 5},\n #{\'word\': \'##kow\', \'score\': 0.8762879967689514, \'entity\': \'ok\', \'index\': 6}]\n
Run Code Online (Sandbox Code Playgroud)\n

不幸的是,它似乎并不总是有效,但也许它足以满足您的用例。

\n

另一种选择是SpaCy。他们没有针对不同语言的那么多模型,但是使用SpaCy 的 EntityRuler可以轻松手动定义新实体,即“扩展实体识别数据库”。

\n