トランスフォーマー・モデルのトレーニングは、CPU とメモリーを集中的に使用します。 事前定義環境の大きさが不足しているため、トレーニングを完了できません。 CPU とメモリーの量が多いカスタム・ノートブック環境を作成し、それを使用してノートブックを実行します。 使用可能な GPU がある場合は、それらを使用することを強くお勧めします。 独自の環境テンプレートの作成を参照してください。
入力データ・フォーマット
Copy link to section
トレーニング・データは、複数の JSON オブジェクトを持つ配列として表されます。 各 JSON オブジェクトは 1 つのトレーニング・インスタンスを表し、 text フィールドと mentions フィールドが必要です。 text フィールドはトレーニング・センテンス・テキストを表し、 mentions は各メンションのテキスト、タイプ、および場所を含む JSON オブジェクトの配列です。
[{"text": str,"mentions":[{"location":{"begin": int,"end": int
},"text": str,"type": str
},...]},...
]
Copy to clipboardクリップボードにコピーされました
例:
[{"id":38863234,"text":"I'm moving to Colorado in a couple months.","mentions":[{"text":"Colorado","type":"Location","location":{"begin":14,"end":22}},{"text":"couple months","type":"Duration","location":{"begin":28,"end":41}}]}]
import watson_nlp
from watson_nlp.toolkit.entity_mentions_utils.train_util import prepare_stream_of_train_records_from_JSON_collection
# load the syntax models for all languages to be supported
syntax_model = watson_nlp.load('syntax_izumo_en_stock')
syntax_models = [syntax_model]
# load the pretrained Slate model
pretrained_model_resource = watson_nlp.load('<pretrained Slate model>')
# prepare the train and dev data# entity_train_data is a directory with one or more json files in the input format specified above
train_data_stream = prepare_stream_of_train_records_from_JSON_collection('entity_train_data')
dev_data_stream = prepare_stream_of_train_records_from_JSON_collection('entity_train_data')
# train a transformer workflow model
trained_workflow = watson_nlp.workflows.entity_mentions.transformer.Transformer.train(
train_data_stream=train_data_stream,
dev_data_stream=dev_data_stream,
syntax_models=syntax_models,
template_resource=pretrained_model_resource,
num_train_epochs=3,
)