開始使用免費開始

執行 spaCy pipeline

你已經在單一文字上執行過一次 spaCy 的 NLP pipeline,並從一組 Doc 容器中擷取過 token。這個練習要讓你練習在 texts(一個字串清單)上執行 spaCy pipeline 的起始步驟。

你會使用 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 ____])
編輯並執行程式碼