开始使用免费开始使用

运行一个 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 ____])
编辑并运行代码