🚀 BART-LARGE在SQuADv2上微調
這是一個在SQuADv2數據集上針對問答任務進行微調的bart-large模型。該模型可有效處理問答相關問題,為自然語言處理領域的問答場景提供了有力支持。
🚀 快速開始
你可以通過以下代碼示例快速使用該模型進行問答任務:
from transformers import BartTokenizer, BartForQuestionAnswering
import torch
tokenizer = BartTokenizer.from_pretrained('a-ware/bart-squadv2')
model = BartForQuestionAnswering.from_pretrained('a-ware/bart-squadv2')
question, text = "Who was Jim Henson?", "Jim Henson was a nice puppet"
encoding = tokenizer(question, text, return_tensors='pt')
input_ids = encoding['input_ids']
attention_mask = encoding['attention_mask']
start_scores, end_scores = model(input_ids, attention_mask=attention_mask, output_attentions=False)[:2]
all_tokens = tokenizer.convert_ids_to_tokens(input_ids[0])
answer = ' '.join(all_tokens[torch.argmax(start_scores) : torch.argmax(end_scores)+1])
answer = tokenizer.convert_tokens_to_ids(answer.split())
answer = tokenizer.decode(answer)
#answer => 'a nice puppet'
✨ 主要特性
- 多任務適用性:BART是一個seq2seq模型,適用於自然語言生成(NLG)和自然語言理解(NLU)任務。
- 長序列處理能力:能夠處理長達1024個標記的序列。
- 性能表現:在SQuAD數據集上,bart-large取得了與ROBERTa相當的成績。
📚 詳細文檔
模型詳情
BART在論文 BART: Denoising Sequence-to-Sequence Pre-training for Natural Language Generation, Translation, and Comprehension 中被提出。為了將BART用於問答任務,我們將完整的文檔輸入到編碼器和解碼器中,並使用解碼器的頂層隱藏狀態作為每個單詞的表示,該表示用於對標記進行分類。
屬性 |
詳情 |
編碼器層數 |
12 |
解碼器層數 |
12 |
隱藏層大小 |
4096 |
注意力頭數量 |
16 |
磁盤佔用大小 |
1.63GB |
模型訓練
該模型使用simpletransformers包裝器並通過以下參數進行訓練:
train_args = {
'learning_rate': 1e-5,
'max_seq_length': 512,
'doc_stride': 512,
'overwrite_output_dir': True,
'reprocess_input_data': False,
'train_batch_size': 8,
'num_train_epochs': 2,
'gradient_accumulation_steps': 2,
'no_cache': True,
'use_cached_eval_features': False,
'save_model_every_epoch': False,
'output_dir': "bart-squadv2",
'eval_batch_size': 32,
'fp16_opt_level': 'O2',
}
你甚至可以使用這個Colab筆記本訓練自己的模型
模型效果
{"correct": 6832, "similar": 4409, "incorrect": 632, "eval_loss": -14.950117511952177}
由A-ware UG ❤️創建 