命名实体识别

Python 中的 NLP 特征工程

Rounak Banik

Data Scientist

应用场景

  • 高效搜索算法
  • 问答系统
  • 新闻分类
  • 客服
Python 中的 NLP 特征工程

命名实体识别

  • 识别并将命名实体归类到预定义类别。
  • 类别包括人名、组织、国家等。
    "John Doe is a software engineer working at Google. He lives in France."
    
  • 命名实体
  • John Doe → 人名
  • Google → 组织
  • France → 国家(地缘政治实体)
Python 中的 NLP 特征工程

使用 spaCy 的 NER

import spacy
string = "John Doe is a software engineer working at Google. He lives in France."

# Load model and create Doc object
nlp = spacy.load('en_core_web_sm')
doc = nlp(string)

# Generate named entities ne = [(ent.text, ent.label_) for ent in doc.ents] print(ne)
[('John Doe', 'PERSON'), ('Google', 'ORG'), ('France', 'GPE')]
Python 中的 NLP 特征工程

spaCy 中的 NER 标注

spaCy 文档:NER 标注

Python 中的 NLP 特征工程

注意事项

  • 并非完美
  • 结果取决于训练与测试数据
  • 对细微场景需用专门数据训练模型
  • 与语言相关
Python 中的 NLP 特征工程

Passons à la pratique !

Python 中的 NLP 特征工程

Preparing Video For Download...