🚀 RuT5SumGazeta
このモデルは、rut5-base をベースにした、ロシア語の要約生成用モデルです。要約生成により、大量のテキスト情報を短くまとめることができます。
🚀 クイックスタート
使い方
Colab: リンク
from transformers import AutoTokenizer, T5ForConditionalGeneration
model_name = "IlyaGusev/rut5_base_sum_gazeta"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = T5ForConditionalGeneration.from_pretrained(model_name)
article_text = "..."
input_ids = tokenizer(
[article_text],
max_length=600,
add_special_tokens=True,
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)
✨ 主な機能
- ロシア語のテキストを要約することができます。
- モデルは
rut5-base
をベースにしており、精度の高い要約生成が期待できます。
📦 インストール
このモデルを使用するには、transformers
ライブラリが必要です。以下のコマンドでインストールできます。
pip install transformers
💻 使用例
基本的な使用法
from transformers import AutoTokenizer, T5ForConditionalGeneration
model_name = "IlyaGusev/rut5_base_sum_gazeta"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = T5ForConditionalGeneration.from_pretrained(model_name)
article_text = "..."
input_ids = tokenizer(
[article_text],
max_length=600,
add_special_tokens=True,
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)
高度な使用法
全ての要約を予測するコード例です。
import json
import torch
from transformers import AutoTokenizer, T5ForConditionalGeneration
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=8
):
device = "cuda" if torch.cuda.is_available() else "cpu"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = T5ForConditionalGeneration.from_pretrained(model_name).to(device)
predictions = []
for batch in gen_batch(input_records, batch_size):
texts = [r["text"] for r in batch]
input_ids = tokenizer(
texts,
add_special_tokens=True,
max_length=max_source_tokens_count,
padding="max_length",
truncation=True,
return_tensors="pt"
)["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/rut5_base_sum_gazeta", list(gazeta_test), "t5_predictions.txt")
📚 ドキュメント
学習データ
学習手順
評価結果
Gazeta v1 データセット
- 学習データセット: Gazeta v1 train
- テストデータセット: Gazeta v1 test
- 入力の最大トークン数: 600
- 出力の最大トークン数: 200
- no_repeat_ngram_size: 4
- num_beams: 5
Gazeta v2 データセット
- 学習データセット: Gazeta v1 train
- テストデータセット: Gazeta v2 test
- 入力の最大トークン数: 600
- 出力の最大トークン数: 200
- no_repeat_ngram_size: 4
- num_beams: 5
評価スクリプト
評価スクリプト: evaluate.py
フラグ: --language ru --tokenize-after --lower
📄 ライセンス
このモデルは、Apache-2.0 ライセンスの下で提供されています。