
Multi_Task_NLPは、NLP開発者が複数のタスクの単一のモデルを簡単にトレーニングおよび推測できるユーティリティツールキットです。 NLUタスクの大部分と複数の変圧器ベースのエンコーダー(例:Bert、Distil-Bert、Albert、Roberta、XLNetなど)のさまざまなデータ形式をサポートしています。
このライブラリの完全なドキュメントについては、ドキュメントを参照してください
会話型AIシステムでは、さまざまなタスクとパイプラインを実行するための複数のコンポーネントを構築して、すべてのコンポーネントを一緒に縫い合わせます。 NLPにおけるトランスベースのモデルの最近の有効性を提供すると、ユースケースを解決するためにトランスベースのモデルを構築することが非常に一般的です。しかし、会話型AIシステムのために一緒に実行される複数のこのようなモデルを持つことで、高価なリソース消費、予測のレイテンシの増加につながり、システムの管理が困難になります。これは、会話型AIシステムを単純な方法で構築したい人にとって、本当の課題をもたらします。
multi_task_nlpは、複数のタスクを一緒に定義し、定義されたすべてのタスクで同時に学習する単一のモデルをトレーニングする機能を提供します。これは、単一のタスクに相当するレイテンシとリソース消費を備えた複数のタスクを実行できることを意味します。
Multi-Task-NLPを使用するには、次のターミナルコマンドを使用して、システム上の目的の場所にリポジトリをクローンできます。
$ cd /desired/location/
$ git clone https://github.com/hellohaptik/multi-task-NLP.git
$ cd multi-task-NLP
$ pip install -r requirements.txt 注: - ライブラリは、 Python 3.7.3を使用して構築およびテストされています。仮想環境に要件をインストールすることをお勧めします。
単一/複数のNLUタスクのモデルをわずか3つの簡単な手順でトレーニングする方法を示すためのクイックガイド。
これらの3つの簡単な手順に従って、マルチタスクモデルをトレーニングしてください!
タスクファイルは、マルチタスクモデルをトレーニングするすべてのタスクを追加できるYAMLフォーマットファイルです。
TaskA :
model_type : BERT
config_name : bert-base-uncased
dropout_prob : 0.05
label_map_or_file :
- label1
- label2
- label3
metrics :
- accuracy
loss_type : CrossEntropyLoss
task_type : SingleSenClassification
file_names :
- taskA_train.tsv
- taskA_dev.tsv
- taskA_test.tsv
TaskB :
model_type : BERT
config_name : bert-base-uncased
dropout_prob : 0.3
label_map_or_file : data/taskB_train_label_map.joblib
metrics :
- seq_f1
- seq_precision
- seq_recall
loss_type : NERLoss
task_type : NER
file_names :
- taskB_train.tsv
- taskB_dev.tsv
- taskB_test.tsvタスクファイルを作成するタスクファイルパラメーターを知るために、タスクファイルパラメーター。
タスクファイルを定義した後、次のコマンドを実行してデータを準備します。
$ python data_preparation.py
--task_file 'sample_task_file.yml'
--data_dir 'data'
--max_seq_len 50 data_preparation.pyスクリプトとその引数について知るには、実行中のデータ準備を参照してください。
最後に、次のコマンドを使用してトレーニングを開始できます。
$ python train.py
--data_dir 'data/bert-base-uncased_prepared_data'
--task_file 'sample_task_file.yml'
--out_dir 'sample_out'
--epochs 5
--train_batch_size 4
--eval_batch_size 8
--grad_accumulation_steps 2
--log_per_updates 25
--save_per_updates 1000
--eval_while_train True
--test_while_train True
--max_seq_len 50
--silent True train.pyスクリプトとその議論について知っているには、ランニングトレインを参照してください
タスクでトレーニングされたマルチタスクモデルを作成したら、推論パイプラインを介してサンプルを予測するためにそれを使用する便利で簡単な方法を提供します。
たとえばTASKA、TASKB、およびTASKCの訓練されたモデルを使用してサンプルの推論を実行するには、このクラスのオブジェクトを作成して、 InferPipelineクラスをインポートし、対応するマルチタスクモデルをロードできます。
> >> from infer_pipeline import inferPipeline
> >> pipe = inferPipeline ( modelPath = 'sample_out_dir/multi_task_model.pt' , maxSeqLen = 50 ) infer関数を呼び出すと、上記のタスクの入力サンプルの予測を取得できます。
> >> samples = [ [ 'sample_sentence_1' ], [ 'sample_sentence_2' ] ]
> >> tasks = [ 'TaskA' , 'TaskB' ]
> >> pipe . infer ( samples , tasks ) infer_pipelineを知っているには、[推奨]を参照してください。
ここでは、さまざまな会話型AIタスクを例として見つけることができ、ノートブックに記載されている簡単な手順でマルチタスクモデルをトレーニングできます。
(セットアップ:マルチタスク、タスクタイプ:複数)
意図検出(タスクタイプ:単一文の分類)
Query: I need a reservation for a bar in bangladesh on feb the 11th 2032
Intent: BookRestaurant
ner(タスクタイプ:シーケンスラベル付け)
Query: ['book', 'a', 'spot', 'for', 'ten', 'at', 'a', 'top-rated', 'caucasian', 'restaurant', 'not', 'far', 'from', 'selmer']
NER tags: ['O', 'O', 'O', 'O', 'B-party_size_number', 'O', 'O', 'B-sort', 'B-cuisine', 'B-restaurant_type', 'B-spatial_relation', 'I-spatial_relation', 'O', 'B-city']
フラグメント検出(タスクタイプ:単一文の分類)
Query: a reservation for
Label: fragment
ノートブック:-intent_ner_fragment
Transformファイル:-Transform_File_Snips
タスクファイル:-tasks_file_snips
(セットアップ:シングルタスク、タスクタイプ:文ペアの分類)
Query1: An old man with a package poses in front of an advertisement.
Query2: A man poses in front of an ad.
Label: entailment
Query1: An old man with a package poses in front of an advertisement.
Query2: A man poses in front of an ad for beer.
Label: non-entailment
ノートブック: - entailment_snli
Transformファイル:-Transform_File_Snli
タスクファイル:-tasks_file_snli
(セットアップ:シングルタスク、タスクタイプ:文ペアの分類)
Query: how much money did evander holyfield make
Context: Evander Holyfield Net Worth. How much is Evander Holyfield Worth? Evander Holyfield Net Worth: Evander Holyfield is a retired American professional boxer who has a net worth of $500 thousand. A professional boxer, Evander Holyfield has fought at the Heavyweight, Cruiserweight, and Light-Heavyweight Divisions, and won a Bronze medal a the 1984 Olympic Games.
Label: answerable
ノートブック:-Ensurnability_Detection_msmarco
ファイル:-Transform_File_Answerability
タスクファイル:-tasks_file_answerability
(セットアップ:シングルタスク、タスクタイプ:単一文の分類)
Query: what's the distance between destin florida and birmingham alabama?
Label: NUMERIC
Query: who is suing scott wolter
Label: PERSON
ノートブック:-query_type_detection
Transformファイル:-Transform_File_QueryType
タスクファイル:-tasks_file_queryType
(セットアップ:マルチタスク、タスクタイプ:シーケンスラベル付け)
Query: ['Despite', 'winning', 'the', 'Asian', 'Games', 'title', 'two', 'years', 'ago', ',', 'Uzbekistan', 'are', 'in', 'the', 'finals', 'as', 'outsiders', '.']
NER tags: ['O', 'O', 'O', 'I-MISC', 'I-MISC', 'O', 'O', 'O', 'O', 'O', 'I-LOC', 'O', 'O', 'O', 'O', 'O', 'O', 'O']
POS tags: ['I-PP', 'I-VP', 'I-NP', 'I-NP', 'I-NP', 'I-NP', 'B-NP', 'I-NP', 'I-ADVP', 'O', 'I-NP', 'I-VP', 'I-PP', 'I-NP', 'I-NP', 'I-SBAR', 'I-NP', 'O']
ノートブック:-NER_POS_TAGGING_CONLL
Transformファイル:-transform_file_conll
タスクファイル:-tasks_file_conll
(セットアップ:シングルタスク、タスクタイプ:単一文の分類)
Query: What places have the oligarchy government ?
Label: well-formed
Query: What day of Diwali in 1980 ?
Label: not well-formed
ノートブック:-query_correctness
Transformファイル:-Transform_File_Query_Correctness
タスクファイル:-tasks_file_query_correctness
(セットアップ:シングルタスク、タスクタイプ:単一文の分類)
Query1: What is the most used word in Malayalam?
Query2: What is meaning of the Malayalam word ""thumbatthu""?
Label: not similar
Query1: Which is the best compliment you have ever received?
Query2: What's the best compliment you've got?
Label: similar
ノートブック:-query_similarity
Transformファイル:-transform_file_qqp
タスクファイル:-tasks_file_qqp
(セットアップ:シングルタスク、タスクタイプ:単一文の分類)
Review: What I enjoyed most in this film was the scenery of Corfu, being Greek I adore my country and I liked the flattering director's point of view. Based on a true story during the years when Greece was struggling to stand on her own two feet through war, Nazis and hardship. An Italian soldier and a Greek girl fall in love but the times are hard and they have a lot of sacrifices to make. Nicholas Cage looking great in a uniform gives a passionate account of this unfulfilled (in the beginning) love. I adored Christian Bale playing Mandras the heroine's husband-to-be, he looks very very good as a Greek, his personality matched the one of the Greek patriot! A true fighter in there, or what! One of the movies I would like to buy and keep it in my collection...for ever!
Label: positive
ノートブック:-IMDB_SENTIMENT_ANALYSISS
Transformファイル:-transform_file_imdb
タスクファイル:-tasks_file_imdb