Persian Xlm Roberta Large
基於XLM-RoBERTA多語言預訓練模型,在波斯語問答數據集PQuAD上微調的問答模型
下載量 77
發布時間 : 9/18/2022
模型概述
該模型是針對波斯語問答任務優化的XLM-RoBERTA大型模型,在PQuAD數據集上微調,支持波斯語問答任務。
模型特點
多語言預訓練基礎
基於支持100種語言的XLM-RoBERTA大型模型
波斯語優化
在最大的波斯語問答數據集PQuAD上專門微調
高效訓練
採用梯度累積等技術在有限GPU資源下完成訓練
模型能力
波斯語問答
跨語言遷移學習
文本理解
使用案例
教育
波斯語學習輔助
幫助學習者通過問答方式理解波斯語文本
精確匹配率66.56%,F1分數87.31%
信息檢索
波斯語文檔問答系統
從波斯語文檔中提取答案
🚀 用於問答任務的波斯語XLM - RoBERTA大模型
本模型基於XLM - RoBERTA,這是一個在2.5TB經過篩選的CommonCrawl數據(涵蓋100種語言)上預訓練的多語言語言模型。該模型由Conneau等人在論文大規模無監督跨語言表徵學習中提出。
多語言的適用於多種語言問答的XLM - RoBERTa大模型在多個問答數據集上進行了微調,但不包括PQuAD,PQuAD是目前最大的波斯語問答數據集。本模型就是基於該多語言模型進一步微調得到的。
介紹PQuAD數據集的論文:arXiv:2202.06219
🚀 快速開始
本模型在PQuAD訓練集上進行了微調,可直接使用。由於訓練時間很長,為了方便有需要的人,我將這個模型發佈了出來。
✨ 主要特性
- 基於強大的XLM - RoBERTA多語言預訓練模型。
- 在PQuAD波斯語問答數據集上進行了微調,適用於波斯語問答任務。
- 在PQuAD測試集上的表現優於ParsBert模型。
📦 安裝指南
此部分文檔未提及具體安裝步驟,跳過。
💻 使用示例
基礎用法
from transformers import AutoTokenizer, AutoModelForQuestionAnswering
path = 'pedramyazdipoor/persian_xlm_roberta_large'
tokenizer = AutoTokenizer.from_pretrained(path)
model = AutoModelForQuestionAnswering.from_pretrained(path)
高級用法
def generate_indexes(start_logits, end_logits, N, min_index):
output_start = start_logits
output_end = end_logits
start_indexes = np.arange(len(start_logits))
start_probs = output_start
list_start = dict(zip(start_indexes, start_probs.tolist()))
end_indexes = np.arange(len(end_logits))
end_probs = output_end
list_end = dict(zip(end_indexes, end_probs.tolist()))
sorted_start_list = sorted(list_start.items(), key=lambda x: x[1], reverse=True) #Descending sort by probability
sorted_end_list = sorted(list_end.items(), key=lambda x: x[1], reverse=True)
final_start_idx, final_end_idx = [[] for l in range(2)]
start_idx, end_idx, prob = 0, 0, (start_probs.tolist()[0] + end_probs.tolist()[0])
for a in range(0,N):
for b in range(0,N):
if (sorted_start_list[a][1] + sorted_end_list[b][1]) > prob :
if (sorted_start_list[a][0] <= sorted_end_list[b][0]) and (sorted_start_list[a][0] > min_index) :
prob = sorted_start_list[a][1] + sorted_end_list[b][1]
start_idx = sorted_start_list[a][0]
end_idx = sorted_end_list[b][0]
final_start_idx.append(start_idx)
final_end_idx.append(end_idx)
return final_start_idx[0], final_end_idx[0]
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
model.eval().to(device)
text = 'سلام من پدرامم 26 سالمه'
question = 'چند سالمه؟'
encoding = tokenizer(question,text,add_special_tokens = True,
return_token_type_ids = True,
return_tensors = 'pt',
padding = True,
return_offsets_mapping = True,
truncation = 'only_first',
max_length = 32)
out = model(encoding['input_ids'].to(device),encoding['attention_mask'].to(device), encoding['token_type_ids'].to(device))
#we had to change some pieces of code to make it compatible with one answer generation at a time
#If you have unanswerable questions, use out['start_logits'][0][0:] and out['end_logits'][0][0:] because <s> (the 1st token) is for this situation and must be compared with other tokens.
#you can initialize min_index in generate_indexes() to put force on tokens being chosen to be within the context(startindex must be greater than seperator token).
answer_start_index, answer_end_index = generate_indexes(out['start_logits'][0][1:], out['end_logits'][0][1:], 5, 0)
print(tokenizer.tokenize(text + question))
print(tokenizer.tokenize(text + question)[answer_start_index : (answer_end_index + 1)])
>>> ['▁سلام', '▁من', '▁پدر', 'ام', 'م', '▁26', '▁سالم', 'ه', 'چند', '▁سالم', 'ه', '؟']
>>> ['▁26']
📚 詳細文檔
訓練超參數
由於Google Colab中GPU內存的限制,我將批量大小設置為4。
batch_size = 4
n_epochs = 1
base_LM_model = "deepset/xlm-roberta-large-squad2"
max_seq_len = 256
learning_rate = 3e-5
evaluation_strategy = "epoch",
save_strategy = "epoch",
learning_rate = 3e-5,
warmup_ratio = 0.1,
gradient_accumulation_steps = 8,
weight_decay = 0.01,
性能評估
在PQuAD波斯語測試集上進行評估,使用官方PQuAD鏈接。 我也進行了超過1個epoch的訓練,但結果更差。 我們的XLM - Roberta模型在PQuAD數據集上的表現優於我們的ParsBert模型,但前者的規模是後者的3倍多,因此比較這兩個模型並不公平。
PQuAD數據集測試集上的問答性能
指標 | 我們的XLM - Roberta大模型 | 我們的ParsBert模型 |
---|---|---|
精確匹配 | 66.56* | 47.44 |
F1值 | 87.31* | 81.96 |
推理注意事項
- 答案的起始索引必須小於結束索引。
- 答案的範圍必須在上下文中。
- 所選的範圍必須是N對候選答案中最可能的選擇。
🔧 技術細節
本模型基於XLM - RoBERTA大模型,在PQuAD訓練集上進行微調。訓練過程中,由於GPU內存限制,設置了合適的批量大小和其他超參數。在推理階段,通過generate_indexes
函數來確定答案的起始和結束索引。
📄 致謝
我們在此對Newsha Shahbodaghkhan在數據集收集方面提供的便利表示感謝。
👥 貢獻者
- Pedram Yazdipoor : 領英
📢 版本發佈
版本v0.2 (2022年9月18日)
這是我們的波斯語XLM - Roberta大模型的第二個版本。之前的版本在使用中存在一些問題。
Distilbert Base Cased Distilled Squad
Apache-2.0
DistilBERT是BERT的輕量級蒸餾版本,參數量減少40%,速度提升60%,保留95%以上性能。本模型是在SQuAD v1.1數據集上微調的問答專用版本。
問答系統 英語
D
distilbert
220.76k
244
Distilbert Base Uncased Distilled Squad
Apache-2.0
DistilBERT是BERT的輕量級蒸餾版本,參數量減少40%,速度提升60%,在GLUE基準測試中保持BERT 95%以上的性能。本模型專為問答任務微調。
問答系統
Transformers 英語

D
distilbert
154.39k
115
Tapas Large Finetuned Wtq
Apache-2.0
TAPAS是基於BERT架構的表格問答模型,通過自監督方式在維基百科表格數據上預訓練,支持對錶格內容進行自然語言問答
問答系統
Transformers 英語

T
google
124.85k
141
T5 Base Question Generator
基於t5-base的問答生成模型,輸入答案和上下文,輸出相應問題
問答系統
Transformers

T
iarfmoose
122.74k
57
Bert Base Cased Qa Evaluator
基於BERT-base-cased的問答對評估模型,用於判斷問題和答案是否語義相關
問答系統
B
iarfmoose
122.54k
9
Tiny Doc Qa Vision Encoder Decoder
MIT
一個基於MIT許可證的文檔問答模型,主要用於測試目的。
問答系統
Transformers

T
fxmarty
41.08k
16
Dpr Question Encoder Single Nq Base
DPR(密集段落檢索)是用於開放領域問答研究的工具和模型。該模型是基於BERT的問題編碼器,使用自然問題(NQ)數據集訓練。
問答系統
Transformers 英語

D
facebook
32.90k
30
Mobilebert Uncased Squad V2
MIT
MobileBERT是BERT_LARGE的輕量化版本,在SQuAD2.0數據集上微調而成的問答系統模型。
問答系統
Transformers 英語

M
csarron
29.11k
7
Tapas Base Finetuned Wtq
Apache-2.0
TAPAS是一個基於Transformer的表格問答模型,通過自監督學習在維基百科表格數據上預訓練,並在WTQ等數據集上微調。
問答系統
Transformers 英語

T
google
23.03k
217
Dpr Question Encoder Multiset Base
基於BERT的密集段落檢索(DPR)問題編碼器,用於開放領域問答研究,在多個QA數據集上訓練
問答系統
Transformers 英語

D
facebook
17.51k
4
精選推薦AI模型
Llama 3 Typhoon V1.5x 8b Instruct
專為泰語設計的80億參數指令模型,性能媲美GPT-3.5-turbo,優化了應用場景、檢索增強生成、受限生成和推理任務
大型語言模型
Transformers 支持多種語言

L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一個基於SODA數據集訓練的超小型對話模型,專為邊緣設備推理設計,體積僅為Cosmo-3B模型的2%左右。
對話系統
Transformers 英語

C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基於RoBERTa架構的中文抽取式問答模型,適用於從給定文本中提取答案的任務。
問答系統 中文
R
uer
2,694
98