句子中的命名实体
在本练习中,您将使用 spaCy 的统计模型之一,从一段文本中识别并分类各种命名实体的标签。我们还会验证这些标签的准确性。
本练习是课程的一部分
Python 中的 NLP 特征工程
练习说明
- 使用
spacy.load()加载en_core_web_sm模型。 - 使用
text和nlp创建一个 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(____, ____)