
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, Task, Task และ 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 การสนทนาที่หลากหลายเป็นตัวอย่างและสามารถฝึกอบรมโมเดลหลายงานในขั้นตอนง่าย ๆ ที่กล่าวถึงในสมุดบันทึก
(การตั้งค่า: Multi-Task, ประเภทงาน: Multiple)
การตรวจจับเจตนา (ประเภทงาน: การจำแนกประโยคเดียว)
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
สมุดบันทึก :- คำตอบ _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
(การตั้งค่า: Multi-Task, ประเภทงาน: การติดฉลากลำดับ)
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