运行一个 spaCy 流水线
您已经在一段文本上运行过一次 spaCy 的 NLP 流水线,并从一组 Doc 容器中提取过 token。本练习中,您将练习在 texts(一个文本字符串列表)上运行 spaCy 流水线的初始步骤。
本练习将使用 en_core_web_sm 模型。spaCy 包已为您导入。
本练习是课程的一部分
使用 spaCy 的自然语言处理
练习说明
- 将
en_core_web_sm模型加载为nlp。 - 对
texts中的每个元素运行nlp()模型,并将对应的Doc容器追加到documents列表。 - 打印
documents列表中每个Doc容器的 token 文本。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Load en_core_web_sm model as nlp
nlp = spacy.____(____)
# Run an nlp model on each item of texts and append the Doc container to documents
documents = []
for text in ____:
documents.append(____)
# Print the token texts for each Doc container
for doc in documents:
print([____ for ____ in ____])