开始使用免费开始使用

句子中的命名实体

在本练习中,您将使用 spaCy 的统计模型之一,从一段文本中识别并分类各种命名实体的标签。我们还会验证这些标签的准确性。

本练习是课程的一部分

Python 中的 NLP 特征工程

查看课程

练习说明

  • 使用 spacy.load() 加载 en_core_web_sm 模型。
  • 使用 textnlp 创建一个 Doc 实例 doc
  • 遍历 doc.ents,打印所有命名实体及其对应的标签。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Load the required model
nlp = ____.____(____)

# Create a Doc instance 
text = 'Sundar Pichai is the CEO of Google. Its headquarters is in Mountain View.'
doc = ____

# Print all named entities and their labels
for ent in ____:
    print(____, ____)
编辑并运行代码