🚀 土耳其語BERT2BERT(共享)在MLSUM TR上微調用於文本摘要
本項目是一個基於土耳其語的文本摘要模型,通過在MLSUM TR數據集上對BERT2BERT(共享)模型進行微調,實現了對新聞等文本的有效摘要提取。
🚀 快速開始
代碼示例
import torch
from transformers import BertTokenizerFast, EncoderDecoderModel
device = 'cuda' if torch.cuda.is_available() else 'cpu'
ckpt = 'mrm8488/bert2bert_shared-turkish-summarization'
tokenizer = BertTokenizerFast.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)
✨ 主要特性
📦 安裝指南
文檔未提供安裝步驟,暫無法展示。
💻 使用示例
基礎用法
import torch
from transformers import BertTokenizerFast, EncoderDecoderModel
device = 'cuda' if torch.cuda.is_available() else 'cpu'
ckpt = 'mrm8488/bert2bert_shared-turkish-summarization'
tokenizer = BertTokenizerFast.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)
高級用法
文檔未提供高級用法示例,暫無法展示。
📚 詳細文檔
模型
使用的基礎模型為 dbmdz/bert-base-turkish-cased(BERT檢查點)。
數據集
MLSUM 是第一個大規模的多語言摘要數據集。它從在線報紙獲取,包含五種不同語言(法語、德語、西班牙語、俄語和 土耳其語)的超過150萬篇文章及其摘要對。結合來自流行的CNN/Daily mail數據集的英文報紙文章,收集的數據形成了一個大規模的多語言數據集,為文本摘要領域的研究提供了新的方向。
數據集鏈接:MLSUM tu/tr
結果
屬性 |
詳情 |
測試集Rouge2 - mid - 精確率 |
32.41 |
測試集Rouge2 - mid - 召回率 |
28.65 |
測試集Rouge2 - mid - F值 |
29.48 |
🔧 技術細節
文檔未提供具體的技術實現細節,暫無法展示。
📄 許可證
文檔未提供許可證信息,暫無法展示。
Created by Manuel Romero/@mrm8488 with the support of Narrativa
Made with ♥ in Spain