python - 扩展 NLP 实体提取

标签 python machine-learning nlp polyglot named-entity-extraction

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

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

最佳答案

看看 HuggingFace 的预训练模型。

  • 他们有一个多语言 NER 模型,训练了 40 种语言,包括俄语等西里尔语。它是 RoBERTa 的微调版本,因此准确性似乎非常好。在此处查看详细信息:https://huggingface.co/jplu/tf-xlm-r-ner-40-lang
  • 他们还有一个多语言 DistilBERT 模型,用于基于 GitHub Typo Corpus 进行错字检测训练。语料库似乎包括来自 15 种不同语言的错别字,包括俄语。在此处查看详细信息:https://huggingface.co/mrm8488/distilbert-base-multi-cased-finetuned-typo-detection

  • 以下是文档中的一些示例代码,针对您的用例略有改动:
    from transformers import pipeline
    
    typo_checker = pipeline("ner", model="mrm8488/distilbert-base-multi-cased-finetuned-typo-detection",
                            tokenizer="mrm8488/distilbert-base-multi-cased-finetuned-typo-detection")
    
    result = typo_checker("я живу в Мосве")
    result[1:-1]
    
     #[{'word': 'я', 'score': 0.7886862754821777, 'entity': 'ok', 'index': 1},
     #{'word': 'жив', 'score': 0.6303715705871582, 'entity': 'ok', 'index': 2},
     #{'word': '##у', 'score': 0.7259598970413208, 'entity': 'ok', 'index': 3},
     #{'word': 'в', 'score': 0.7102937698364258, 'entity': 'ok', 'index': 4},
     #{'word': 'М', 'score': 0.5045614242553711, 'entity': 'ok', 'index': 5},
     #{'word': '##ос', 'score': 0.560469925403595, 'entity': 'typo', 'index': 6},
     #{'word': '##ве', 'score': 0.8228507041931152, 'entity': 'ok', 'index': 7}]
    
    result = typo_checker("I live in Moskkow")
    result[1:-1]
    
     #[{'word': 'I', 'score': 0.7598089575767517, 'entity': 'ok', 'index': 1},
     #{'word': 'live', 'score': 0.8173692226409912, 'entity': 'ok', 'index': 2},
     #{'word': 'in', 'score': 0.8289134502410889, 'entity': 'ok', 'index': 3},
     #{'word': 'Mo', 'score': 0.7344270944595337, 'entity': 'ok', 'index': 4},
     #{'word': '##sk', 'score': 0.6559176445007324, 'entity': 'ok', 'index': 5},
     #{'word': '##kow', 'score': 0.8762879967689514, 'entity': 'ok', 'index': 6}]
    
    不幸的是,它似乎并不总是有效,但对于您的用例来说可能已经足够了。
    另一种选择是 SpaCy 。他们没有针对不同语言的那么多模型,但是使用 SpaCy's EntityRuler 可以轻松手动定义新实体,即“扩展实体识别数据库”。

    关于python - 扩展 NLP 实体提取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44763499/

    相关文章:

    python - 使用 NumPy 屏蔽 QImage 的 alpha 值时出现意外结果

    nlp - 波特和兰卡斯特阻止澄清

    tensorflow - 无法使用 LSTM 进行机器翻译生成正确的英语到 SQL 翻译

    python - Pandas 应用一个函数将列表返回到更多列

    python - 将社区检测与图形或其他库重叠

    python - 如何阻止和等待异步、基于回调的 Python 函数调用

    python - TensorFlow:Compat 弃用警告

    python - 使用 GPy Multiple-output coregionalized 预测

    machine-learning - RNN : Back-propagation through time when output is taken only at final timestep

    python - 如何使用 scikit learn 向量化标记的二元组?