CoolFace
Modelpublic

data-silence/any-news-sum

sourceHugging Faceupdated 2y agoView on Hugging Face
3likes87downloads
Model Card

data-silence/any-news-sum

This repository contains the mT5 checkpoint finetuned on the 45 languages of my sumnews dataset which based on popular XL-Sum. The model solves the news summarization task: it's designed to simultaneously generate a headline and a summary of a news article based on its full content. The primary focus of the training was on Russian language operation, but to some extent the model will work on text in any language supported by the mT5 mother model and XL-Sum dataset.

Testing this model on Spaces

You can try out the trained model here

Using this model in transformers

python
import torch
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, DataCollatorForSeq2Seq
# Загрузка модели и токенизатора
model_name = "data-silence/any-news-sum"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
def generate_summary_with_special_tokens(text, max_length=512):
    inputs = tokenizer(text, return_tensors="pt", max_length=max_length, truncation=True).to(device)
    
    outputs = model.generate(
        **inputs,
        max_length=max_length,
        num_return_sequences=1,
        no_repeat_ngram_size=4,
    )
    
    generated_text = tokenizer.decode(outputs[0], skip_special_tokens=False)
    
    # Разделение на заголовок и резюме
    parts = generated_text.split('<title_resume_sep>')
    title = parts[0].replace("<pad> ", "").strip()
    resume = parts[1].replace("</s>", "").strip() if len(parts) > 1 else ""
    
    return title, resume
title, resume = generate_summary_with_special_tokens('Пациенты с сердечными заболеваниями зачастую имеют низкий уровень мелатонина и нарушение цикла сна-бодрствования. До сих пор механизмы, лежащие в основе этого явления, оставались неясными. В статье, опубликованной в журнале Science, команда Мюнхенского технического университета (TUM) показывает, каким именно образом сердечные заболевания влияют на выработку гормона сна в шишковидной железе. А в качестве связующего звена между двумя органами оказывается ганглий в области шеи.')
print(title)  # Ученые показал, каким именно образом сердечные заболевания влияют на выработку гормона сна в шишковидной железе
print(resume)  # Ученые опубликовали статью, опубликованную в журнале Science, команда Мюнхенского технического университета (TUM) показывает, каким образом кардиальные заболевания влияет на выработку гормона сна в шишковидной железе.

Training hyperparameters

The following hyperparameters were used during training:

  • learning_rate: 2e-05
  • trainbatchsize: 6
  • evalbatchsize: 6
  • seed: 42
  • gradientaccumulationsteps: 6
  • totaltrainbatch_size: 36
  • optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
  • lrschedulertype: linear
  • lrschedulerwarmup_steps: 500
  • num_epochs: 4

Evaluation result

This model achieves the following results on the evaluation set:

MetricSignificanceROUGE-1ROUGE-2ROUGE-L
Training Loss0.4487---
Epoch4.0---
Step20496---
Evaluation Runtime (s)3433.4702---
Evaluation Samples/Sec9.37---
Evaluation Steps/Sec1.562---
Evaluation Loss0.2748---
Evaluation Title-0.13730.04890.1220
Evaluation Resume-0.00160.00050.0015

"""

Framework versions

  • Transformers 4.42.4
  • Pytorch 2.3.1+cu121
  • Datasets 2.21.0
  • Tokenizers 0.19.1