当前位置:   article > 正文

Python-Spacy 实现英文命名实体识别(NER)_spacy实体识别

spacy实体识别

环境准备

  1. # 清华源安装spacy包
  2. pip install -U spacy -i https://pypi.tuna.tsinghua.edu.cn/simple
  3. python -m spacy download en_core_web_sm
  4. # 如果安装失败可以使用手动安装的方法
  5. # wget https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.6.0/en_core_web_sm-3.6.0-py3-none-any.whl
  6. # pip install en_core_web_sm-3.6.0-py3-none-any.whl

代码实现

  1. import spacy
  2. # Load English tokenizer, tagger, parser and NER
  3. nlp = spacy.load("en_core_web_sm")
  4. # Process whole documents
  5. text = ("When Sebastian Thrun started working on self-driving cars at "
  6. "Google in 2007, few people outside of the company took him "
  7. "seriously. “I can tell you very senior CEOs of major American "
  8. "car companies would shake my hand and turn away because I wasn’t "
  9. "worth talking to,” said Thrun, in an interview with Recode earlier "
  10. "this week.")
  11. doc = nlp(text)
  12. # Analyze syntax
  13. print("Noun phrases:", [chunk.text for chunk in doc.noun_chunks])
  14. print("Verbs:", [token.lemma_ for token in doc if token.pos_ == "VERB"])
  15. # Find named entities, phrases and concepts
  16. for entity in doc.ents:
  17. print(entity.text, entity.label_)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/神奇cpp/article/detail/787624
推荐阅读
相关标签
  

闽ICP备14008679号