CoolFace
Modelpublic

assemsabry/Research-News-AI-Summarizer

sourceHugging Faceapache-2.0updated 4mo agoView on Hugging Face
0likes15downloads
Model Card

Research & News AI Summarizer

[image]

Model Type: NLP / Text Summarization


Model Description

Research & News AI Summarizer is a fine-tuned Longformer Encoder-Decoder (LED) model optimized for abstractive summarization of long-form research articles and news content. It is trained using a custom 3-stage curriculum learning strategy across multiple versions of the CNN/DailyMail dataset, and is powered by the STAM (Stable Training with Adaptive Momentum) optimizer.

The model supports input sequences of up to 8,192 tokens (base configuration) or 16,384 tokens (large configuration), making it suitable for summarizing lengthy documents that exceed the context limits of standard transformer models.

Developer


STAM Optimizer

This model is trained exclusively with the STAM optimizer, a next-generation adaptive momentum optimizer designed for stable convergence in large-scale NLP training.

[image]

STAM dynamically adjusts first-momentum coefficients based on gradient alignment statistics, reducing training instability and improving generalization across long-context summarization tasks.

Key STAM Hyperparameters:

ParameterValueDescription
learning_rate1.0e-4Initial learning rate
b1_base0.9Base first-momentum coefficient
b20.999Second-moment decay rate
weight_decay0.01Decoupled weight decay
adapt_strength0.2Momentum adaptation strength [0, 0.5]

References:


Model Specifications

AttributeValue
Base Modelallenai/led-base-16384
ArchitectureLongformer Encoder-Decoder (LED)
Context Length8,192 tokens (base) / 16,384 tokens (large)
Max Summary Length512 tokens (base) / 768 tokens (large)
Min Summary Length64 tokens (base) / 80 tokens (large)
Vocabulary Size50,265
Parameters~162M
OptimizerSTAM (Stable Training with Adaptive Momentum)
Training TypeFull Fine-Tuning (no LoRA / PEFT)
PrecisionFP16 mixed precision
Gradient CheckpointingEnabled

Training Details

Hardware

  • GPUs: 2x NVIDIA Tesla T4
  • Total VRAM: 32 GB (16 GB per GPU)
  • Environment: CUDA 12.1, PyTorch 2.0+

Training Regime

  • Effective Batch Size: 32 (1 per device x 16 gradient accumulation steps x 2 GPUs)
  • Total Training Time: ~26 hours
  • Seed: 42
  • Warmup Ratio: 3%
  • Max Gradient Norm: 1.0
  • Early Stopping Patience: 2 evaluations

Training Stages (Curriculum Learning)

StageDataset VersionTrain SamplesMax StepsEval Steps
Stage 1CNN/DailyMail v1.0.050,0001,562500
Stage 2CNN/DailyMail v2.0.030,000937500
Stage 3CNN/DailyMail v3.0.030,000937500
Total110,0003,436

Training History

The model was trained over approximately 26 hours using the STAM optimizer with adaptive momentum. The training loss curve demonstrated stable convergence throughout all three curriculum stages.

Loss Progression:

StageStep RangeInitial LossFinal LossNotes
Stage 11 - 1,5622.821.74Warmup completed at step 46. Loss stabilized after step 400.
Stage 21,563 - 2,4991.681.45Curriculum shift to v2.0.0 data. Minor spike at step 1,600 then smooth descent.
Stage 32,500 - 3,4361.421.38Final refinement on v3.0.0. Convergence reached by step 3,200.

Validation ROUGE-Lsum Progression:

StageInitial ROUGE-LsumFinal ROUGE-LsumBest Checkpoint Step
Stage 128.4535.12Step 1,500
Stage 235.8038.94Step 2,450
Stage 339.1042.36Step 3,350

Training Throughput:

  • Average step time: ~27 seconds
  • Peak GPU memory usage: ~14.9 GB per GPU
  • Total tokens processed: ~898M (input + target)

Dataset Details

  • Source: abisee/cnn_dailymail
  • Versions Used: 1.0.0, 2.0.0, 3.0.0
  • Splits: train (for training), validation (for evaluation), test (for final testing)
  • Text Normalization: HTML stripping, whitespace normalization, sentence-level validation
  • Filtering: Articles with fewer than 120 words or summaries outside the 8-350 word range are excluded

Data Preprocessing

python
# Example preprocessing pipeline
from transformers import LEDTokenizer

tokenizer = LEDTokenizer.from_pretrained("assemsabry/Research-News-AI-Summarizer")

# Article tokenization (max 8,192 tokens)
inputs = tokenizer(article, max_length=8192, truncation=True)

# Summary tokenization (max 512 tokens)
labels = tokenizer(text_target=summary, max_length=512, truncation=True)

Evaluation Results

Test Set Performance (CNN/DailyMail v3.0.0, 500 samples)

MetricScore
ROUGE-143.82
ROUGE-220.65
ROUGE-L40.28
ROUGE-Lsum42.36
BERTScore Precision91.24
BERTScore Recall90.18
BERTScore F190.71
Avg Generation Length142.3 tokens

Performance by Summary Length Bucket

Length BucketROUGE-1ROUGE-2ROUGE-LBERTScore F1
Short (0-80 words)46.1222.8542.6591.85
Medium (80-160 words)44.3821.2040.9490.92
Long (160-320 words)41.2518.4538.1289.45
Very Long (320+ words)38.9016.2035.8088.12

Usage

Quick Start

python
from transformers import LEDForConditionalGeneration, LEDTokenizer
import torch

model = LEDForConditionalGeneration.from_pretrained(
    "assemsabry/Research-News-AI-Summarizer"
)
tokenizer = LEDTokenizer.from_pretrained(
    "assemsabry/Research-News-AI-Summarizer"
)

article = """
Your long article text here. This model is designed to handle up to 8,192 tokens
of input context, making it suitable for research papers, news articles, and
other long-form content that exceeds the limits of standard BART or T5 models.
"""

inputs = tokenizer(
    article,
    max_length=8192,
    truncation=True,
    return_tensors="pt"
)

# LED global attention mask: attend to the first token globally
global_attention_mask = torch.zeros_like(inputs["input_ids"])
global_attention_mask[:, 0] = 1

summary_ids = model.generate(
    **inputs,
    global_attention_mask=global_attention_mask,
    max_length=512,
    min_length=64,
    num_beams=4,
    length_penalty=2.0,
    no_repeat_ngram_size=3,
    early_stopping=True,
)

summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
print(summary)

Batch Inference

python
articles = [article1, article2, article3]
inputs = tokenizer(
    articles,
    max_length=8192,
    truncation=True,
    padding=True,
    return_tensors="pt"
)
global_attention_mask = torch.zeros_like(inputs["input_ids"])
global_attention_mask[:, 0] = 1

summary_ids = model.generate(
    **inputs,
    global_attention_mask=global_attention_mask,
    max_length=512,
    num_beams=4,
)
summaries = tokenizer.batch_decode(summary_ids, skip_special_tokens=True)

Repository Structure

.
├── src/
│   ├── config.py          # Training configuration with large sequence settings
│   ├── dataset.py         # CNN/DailyMail dataset processing
│   ├── metrics.py         # ROUGE and BERTScore evaluation
│   ├── model.py           # LED model loading and setup
│   ├── optimizer.py       # STAM and STAMLite PyTorch optimizers
│   └── trainer.py         # Custom Seq2Seq trainer with STAM
├── scripts/
│   ├── train.py           # Main multi-stage training script
│   └── evaluate.py        # Evaluation and inference script
├── configs/
│   ├── base_config.yaml   # Base training configuration
│   └── large_config.yaml  # Large-scale training configuration
├── tests/
│   └── test_model.py      # Unit tests for components
├── media/
│   └── stam.png           # STAM optimizer diagram
├── requirements.txt       # Python dependencies
├── setup.py              # Package installation
└── README.md             # This file

Installation

bash
git clone https://github.com/assemsabry/Research-News-AI-Summarizer
cd Research-News-AI-Summarizer
pip install -r requirements.txt

Training

Set your Hugging Face token as an environment variable:

bash
export HF_TOKEN="your_token_here"

Run multi-stage training:

bash
python scripts/train.py --output-dir ./outputs --stages 1 2 3

Run specific stages only:

bash
python scripts/train.py --stages 2 3

Skip Hub upload (local training only):

bash
python scripts/train.py --skip-upload

Training with Custom Config

python
from src.config import Config
from src.model import load_model_and_tokenizer, setup_system
from src.trainer import build_training_args, build_trainer

config = Config()
config.data.max_input_length = 16384
config.data.max_target_length = 768
config.training.gradient_accumulation_steps = 32

setup_system(config)
model, tokenizer = load_model_and_tokenizer(config)

Evaluation

Evaluate a trained checkpoint:

bash
python scripts/evaluate.py \
    --model-path ./outputs/artifacts/stage_3_cnn_v3 \
    --output-dir ./reports \
    --num-samples 50

The evaluation script produces:

  • human_evaluation.csv: Generated summaries with per-sample ROUGE and BERTScore
  • error_analysis.csv: Length-based error analysis with ratio statistics
  • evaluation_stats.json: Aggregate metrics by length bucket

Testing

Run unit tests:

bash
python -m unittest tests/test_model.py

Tests cover:

  • Text normalization and HTML stripping
  • Dataset validation (min/max word counts)
  • STAM and STAMLite optimizer initialization and step logic
  • Configuration defaults and effective batch size computation

Limitations and Biases

  • The model is trained exclusively on English news articles (CNN/DailyMail). Performance on non-English text or highly technical research papers outside the news domain may vary.
  • Summaries may inherit biases present in the original CNN/DailyMail dataset.
  • The model does not fact-check generated content. Hallucinations can occur on out-of-domain inputs.
  • Maximum input length is 8,192 tokens (base) or 16,384 tokens (large). Documents exceeding this length are truncated from the end.

License

Apache 2.0


Citation

If you use this model in your research, please cite:

bibtex
@misc{research-news-ai-summarizer,
  title={Research & News AI Summarizer: Fine-tuned LED with STAM Optimizer},
  author={Sabry, Assem},
  year={2025},
  howpublished={\url{https://huggingface.co/assemsabry/Research-News-AI-Summarizer}}
}

Acknowledgments