
Multi_task_nlp는 NLP 개발자가 여러 작업에 대한 단일 모델을 쉽게 교육하고 추론 할 수있는 유틸리티 툴킷입니다. 우리는 대부분의 NLU 작업 및 다중 변압기 기반 인코더에 대한 다양한 데이터 형식을 지원합니다 (예 : Bert, Distil-Bert, Albert, Roberta, Xlnet 등).
이 라이브러리에 대한 전체 문서는 문서를 참조하십시오.
모든 대화식 AI 시스템에는 다양한 작업을 수행하기 위해 여러 구성 요소를 구축하고 모든 구성 요소를 함께 스티칭하는 파이프 라인을 수행하는 것이 포함됩니다. NLP에서 최근 변압기 기반 모델의 효과가 있다면 사용 사례를 해결하기 위해 변압기 기반 모델을 구축하는 것이 매우 일반적입니다. 그러나 대화식 AI 시스템을 위해 여러 모델을 함께 실행하면 값 비싼 자원 소비가 발생하고 예측의 대기 시간이 증가하고 시스템을 관리하기 어렵게 만들 수 있습니다. 이것은 단순한 방식으로 대화식 AI 시스템을 구축하고자하는 사람에게는 진정한 도전을 제기합니다.
multi_task_nlp는 여러 작업을 함께 정의하고 정의 된 모든 작업에서 동시에 학습하는 단일 모델을 훈련시키는 기능을 제공합니다. 이는 단일 작업과 동등한 대기 시간 및 리소스 소비로 여러 작업을 수행 할 수 있음을 의미합니다.
멀티 태스킹 -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 사용하여 구축 및 테스트되었습니다. 가상 환경에 요구 사항을 설치하는 것이 좋습니다.
3 가지 간단한 단계로 단일/다중 NLU 작업을 위해 모델을 훈련시키는 방법을 보여주는 빠른 안내서와 코드가 필요하지 않습니다 !!
멀티 태스킹 모델을 훈련시키기 위해 다음 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 스크립트와 그 주장에 대해
작업에 대한 멀티 태스킹 모델이 있으면 추론 파이프 라인을 통해 샘플을 예측할 수있는 편리하고 쉬운 방법을 제공합니다.
Say Taska, TaskB and 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 에 대해 알기 위해서는 lent를 참조하십시오.
여기서는 다양한 대화 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_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_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
노트 :- answerability_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_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_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_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_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_analysis
변환 파일 :- transform_file_imdb
작업 파일 :- Tasks_File_IMDB