IlyaGusev/gazeta
Viewer • Updated • 74.1k • 2.09k • 28
How to use IlyaGusev/rugpt3medium_sum_gazeta with Transformers:
# Use a pipeline as a high-level helper
# Warning: Pipeline type "summarization" is no longer supported in transformers v5.
# You must load the model directly (see below) or downgrade to v4.x with:
# 'pip install "transformers<5.0.0'
from transformers import pipeline
pipe = pipeline("summarization", model="IlyaGusev/rugpt3medium_sum_gazeta") # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("IlyaGusev/rugpt3medium_sum_gazeta")
model = AutoModelForCausalLM.from_pretrained("IlyaGusev/rugpt3medium_sum_gazeta")This is the model for abstractive summarization for Russian based on rugpt3medium_based_on_gpt2.
Colab: link
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
model_name = "IlyaGusev/rugpt3medium_sum_gazeta"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)
article_text = "..."
text_tokens = tokenizer(
article_text,
max_length=600,
add_special_tokens=False,
padding=False,
truncation=True
)["input_ids"]
input_ids = text_tokens + [tokenizer.sep_token_id]
input_ids = torch.LongTensor([input_ids])
output_ids = model.generate(
input_ids=input_ids,
no_repeat_ngram_size=4
)
summary = tokenizer.decode(output_ids[0], skip_special_tokens=False)
summary = summary.split(tokenizer.sep_token)[1]
summary = summary.split(tokenizer.eos_token)[0]
print(summary)
| Model | R-1-f | R-2-f | R-L-f | chrF | METEOR | BLEU | Avg char length |
|---|---|---|---|---|---|---|---|
| mbart_ru_sum_gazeta | 32.4 | 14.3 | 28.0 | 39.7 | 26.4 | 12.1 | 371 |
| rut5_base_sum_gazeta | 32.2 | 14.4 | 28.1 | 39.8 | 25.7 | 12.3 | 330 |
| rugpt3medium_sum_gazeta | 26.2 | 7.7 | 21.7 | 33.8 | 18.2 | 4.3 | 244 |
| Model | R-1-f | R-2-f | R-L-f | chrF | METEOR | BLEU | Avg char length |
|---|---|---|---|---|---|---|---|
| mbart_ru_sum_gazeta | 28.7 | 11.1 | 24.4 | 37.3 | 22.7 | 9.4 | 373 |
| rut5_base_sum_gazeta | 28.6 | 11.1 | 24.5 | 37.2 | 22.0 | 9.4 | 331 |
| rugpt3medium_sum_gazeta | 24.1 | 6.5 | 19.8 | 32.1 | 16.3 | 3.6 | 242 |
Evaluation script: evaluate.py
Flags: --language ru --tokenize-after --lower