開始使用免費開始

訓練前的準備步驟

在訓練 spaCy 模型之前與過程中,你需要:(1)停用其他 pipeline 元件,才能只訓練目標元件;(2)把含有一筆訓練資料點及其對應 annotationsDoc 容器轉換為 Example 類別。

在這個練習中,你會用預先載入、可由 nlp 存取的 en_core_web_sm 模型,練習以上兩個步驟。Example 類別已匯入,且已提供可使用的 text 字串與相關 annotations

本練習屬於課程

使用 spaCy 的自然語言處理

檢視課程

練習說明

  • 停用 nlp 模型中除 ner 之外的所有 pipeline 元件。
  • text 字串及其 annotations 轉換為可用於訓練的正確格式。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

nlp = spacy.load("en_core_web_sm")

# Disable all pipeline components of  except `ner`
other_pipes = [____ for ____ in nlp.____ if ____ != 'ner']
nlp.____(*other_pipes)

# Convert a text and its annotations to the correct format usable for training
doc = nlp.____(text)
example = Example.____(____, ____)
print("Example object for training: \n", example.to_dict())
編輯並執行程式碼