始める無料で始める

互換性のある学習データ

生テキストをそのまま spaCy に渡すことはできません。代わりに、各学習例ごとに Example オブジェクトを作成する必要があります。この演習では、1文のみがアノテーションされた training_data を、Example オブジェクトのリストに変換する練習をします。

en_core_web_sm モデルはすでに読み込まれており、nlp として使用できます。Example クラスもインポート済みです。

この演習はコースの一部です

spaCyで学ぶNatural Language Processing

コースを見る

演習の手順

  • training_data の中のテキストとアノテーションを順に取り出し、テキストを Doc コンテナに変換して doc に保存します。
  • 各学習データポイントの doc オブジェクトとアノテーションを使って Example オブジェクトを作成し、example_sentence に保存します。
  • example_sentenceall_examples のリストに追加します。

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

example_text = 'A patient with chest pain had hyperthyroidism.'
training_data = [(example_text, {'entities': [(15, 25, 'SYMPTOM'), (30, 45, 'DISEASE')]})]

all_examples = []
# Iterate through text and annotations and convert text to a Doc container
for text, annotations in training_data:
  doc = nlp(____)
  
  # Create an Example object from the doc contianer and annotations
  example_sentence = ____.____(doc, ____)
  print(example_sentence.to_dict(), "\n")
  
  # Append the Example object to the list of all examples
  all_examples.append(____)
  
print("Number of formatted training data: ", len(____))
コードを編集して実行