学習の準備ステップ
spaCy モデルを学習する前後では、(1) 対象のコンポーネントだけを学習するために他のパイプラインコンポーネントを無効化し、(2) 学習データの Doc コンテナと対応する annotations を Example クラスに変換する必要があります。
この演習では、事前に読み込まれた en_core_web_sm モデル(nlp として利用可能)を使って、これら2つのステップを練習します。Example クラスはすでにインポート済みで、text 文字列と関連する annotations も用意されています。
この演習はコースの一部です
spaCyで学ぶNatural Language Processing
演習の手順
nlpモデルのパイプラインコンポーネントのうち、ner以外をすべて無効化してください。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())