執行 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 ____])