🚀 MBARTRuSumGazeta
このモデルは、自動要約タスクに特化したモデルで、ロシア語のニュース記事を効率的に要約することができます。
🚀 クイックスタート
モデルの説明
これはfairseqモデルの移植バージョンです。
詳細については、Dataset for Automatic Summarization of Russian Newsを参照してください。
想定される用途と制限
使い方
Colab: リンク
from transformers import MBartTokenizer, MBartForConditionalGeneration
model_name = "IlyaGusev/mbart_ru_sum_gazeta"
tokenizer = MBartTokenizer.from_pretrained(model_name)
model = MBartForConditionalGeneration.from_pretrained(model_name)
article_text = "..."
input_ids = tokenizer(
[article_text],
max_length=600,
padding="max_length",
truncation=True,
return_tensors="pt",
)["input_ids"]
output_ids = model.generate(
input_ids=input_ids,
no_repeat_ngram_size=4
)[0]
summary = tokenizer.decode(output_ids, skip_special_tokens=True)
print(summary)
制限とバイアス
- このモデルはGazeta.ruの記事では良好に動作するはずですが、他の機関の記事ではドメインシフトの影響を受ける可能性があります。
訓練データ
訓練手順
評価結果
- 訓練データセット: Gazeta v1 train
- テストデータセット: Gazeta v1 test
- ソースの最大トークン数: 600
- ターゲットの最大トークン数: 200
- 繰り返しを避けるn-gramサイズ: 4
- ビームサーチのビーム数: 5
- 訓練データセット: Gazeta v1 train
- テストデータセット: Gazeta v2 test
- ソースの最大トークン数: 600
- ターゲットの最大トークン数: 200
- 繰り返しを避けるn-gramサイズ: 4
- ビームサーチのビーム数: 5
すべての要約を予測するコード:
import json
import torch
from transformers import MBartTokenizer, MBartForConditionalGeneration
from datasets import load_dataset
def gen_batch(inputs, batch_size):
batch_start = 0
while batch_start < len(inputs):
yield inputs[batch_start: batch_start + batch_size]
batch_start += batch_size
def predict(
model_name,
input_records,
output_file,
max_source_tokens_count=600,
batch_size=4
):
device = "cuda" if torch.cuda.is_available() else "cpu"
tokenizer = MBartTokenizer.from_pretrained(model_name)
model = MBartForConditionalGeneration.from_pretrained(model_name).to(device)
predictions = []
for batch in gen_batch(inputs, batch_size):
texts = [r["text"] for r in batch]
input_ids = tokenizer(
batch,
return_tensors="pt",
padding="max_length",
truncation=True,
max_length=max_source_tokens_count
)["input_ids"].to(device)
output_ids = model.generate(
input_ids=input_ids,
no_repeat_ngram_size=4
)
summaries = tokenizer.batch_decode(output_ids, skip_special_tokens=True)
for s in summaries:
print(s)
predictions.extend(summaries)
with open(output_file, "w") as w:
for p in predictions:
w.write(p.strip().replace("\n", " ") + "\n")
gazeta_test = load_dataset('IlyaGusev/gazeta', script_version="v1.0")["test"]
predict("IlyaGusev/mbart_ru_sum_gazeta", list(gazeta_test), "mbart_predictions.txt")
評価: https://github.com/IlyaGusev/summarus/blob/master/evaluate.py
フラグ: --language ru --tokenize-after --lower
BibTeXエントリと引用情報
@InProceedings{10.1007/978-3-030-59082-6_9,
author="Gusev, Ilya",
editor="Filchenkov, Andrey and Kauttonen, Janne and Pivovarova, Lidia",
title="Dataset for Automatic Summarization of Russian News",
booktitle="Artificial Intelligence and Natural Language",
year="2020",
publisher="Springer International Publishing",
address="Cham",
pages="122--134",
isbn="978-3-030-59082-6"
}
📄 ライセンス
このモデルは、Apache-2.0ライセンスの下で提供されています。