🚀 西班牙RoBERTa2RoBERTa (roberta-base-bne) 在MLSUM ES數據集上微調用於摘要生成
本項目是將西班牙RoBERTa2RoBERTa (roberta-base-bne) 模型在MLSUM ES數據集上進行微調,以實現文本摘要生成功能。該模型能夠對文本進行有效概括,為用戶提供簡潔的文本摘要。
🚀 快速開始
模型使用示例
以下是使用該模型進行文本摘要生成的Python代碼示例:
import torch
from transformers import RobertaTokenizerFast, EncoderDecoderModel
device = 'cuda' if torch.cuda.is_available() else 'cpu'
ckpt = 'Narrativa/bsc_roberta2roberta_shared-spanish-finetuned-mlsum-summarization'
tokenizer = RobertaTokenizerFast.from_pretrained(ckpt)
model = EncoderDecoderModel.from_pretrained(ckpt).to(device)
def generate_summary(text):
inputs = tokenizer([text], padding="max_length", truncation=True, max_length=512, return_tensors="pt")
input_ids = inputs.input_ids.to(device)
attention_mask = inputs.attention_mask.to(device)
output = model.generate(input_ids, attention_mask=attention_mask)
return tokenizer.decode(output[0], skip_special_tokens=True)
text = "Your text here..."
generate_summary(text)
✨ 主要特性
📦 安裝指南
文檔中未提及具體安裝步驟,若需使用該模型,可參考Hugging Face相關庫的安裝方式,確保安裝 torch
和 transformers
庫。
💻 使用示例
基礎用法
import torch
from transformers import RobertaTokenizerFast, EncoderDecoderModel
device = 'cuda' if torch.cuda.is_available() else 'cpu'
ckpt = 'Narrativa/bsc_roberta2roberta_shared-spanish-finetuned-mlsum-summarization'
tokenizer = RobertaTokenizerFast.from_pretrained(ckpt)
model = EncoderDecoderModel.from_pretrained(ckpt).to(device)
def generate_summary(text):
inputs = tokenizer([text], padding="max_length", truncation=True, max_length=512, return_tensors="pt")
input_ids = inputs.input_ids.to(device)
attention_mask = inputs.attention_mask.to(device)
output = model.generate(input_ids, attention_mask=attention_mask)
return tokenizer.decode(output[0], skip_special_tokens=True)
text = "Your text here..."
generate_summary(text)
高級用法
文檔中未提及高級用法相關代碼,可根據模型的API文檔進一步探索模型的參數調整等高級功能。
📚 詳細文檔
模型
使用的基礎模型為 BSC-TeMU/roberta-base-bne ,這是一個RoBERTa檢查點模型。
數據集
MLSUM 是第一個大規模多語言摘要數據集。它從在線報紙獲取,包含超過150萬篇文章及其摘要對,涵蓋五種不同語言,即法語、德語、西班牙語、俄語和土耳其語。與流行的CNN/Daily mail數據集中的英文報紙文章一起,收集的數據形成了一個大規模多語言數據集,為文本摘要社區開闢了新的研究方向。
MLSUM es
結果
屬性 |
詳情 |
測試集Rouge2 - mid - precision |
11.42 |
測試集Rouge2 - mid - recall |
10.58 |
測試集Rouge2 - mid - fmeasure |
10.69 |
測試集Rouge1 - fmeasure |
28.83 |
測試集RougeL - fmeasure |
23.15 |
原始指標計算代碼如下:
rouge = datasets.load_metric("rouge")
rouge.compute(predictions=results["pred_summary"], references=results["summary"])
{'rouge1': AggregateScore(low=Score(precision=0.30393366820245, recall=0.27905239591639935, fmeasure=0.283148902808752), mid=Score(precision=0.3068521142101569, recall=0.2817252494122592, fmeasure=0.28560373425206464), high=Score(precision=0.30972608774202665, recall=0.28458152325781716, fmeasure=0.2883786700591887)),
'rougeL': AggregateScore(low=Score(precision=0.24184668819794716, recall=0.22401171380621518, fmeasure=0.22624104698839514), mid=Score(precision=0.24470388406868163, recall=0.22665793214539162, fmeasure=0.2289118878817394), high=Score(precision=0.2476594458951327, recall=0.22932683203591905, fmeasure=0.23153001570662513))}
rouge.compute(predictions=results["pred_summary"], references=results["summary"], rouge_types=["rouge2"])["rouge2"].mid
Score(precision=0.11423200347113865, recall=0.10588038944902506, fmeasure=0.1069921217219595)
🔧 技術細節
文檔中未提及具體技術細節相關內容,可參考模型的官方文檔或相關研究論文獲取更多信息。
📄 許可證
文檔中未提及許可證相關信息。
本項目由 Narrativa 創建。關於Narrativa:專注於自然語言生成 (NLG) ,其基於機器學習的平臺Gabriele可構建和部署自然語言解決方案。 #NLG #AI