Skip to main content

Modern BERTScore for Fast Inference

CI Python 3.12 Python 3.13 Python 3.14 License

Performance

Modern-BERT-Score is a reimplementation of the BERTScore metric introduced by Zhang et al., 2019, optimized for modern inference workflows using SentenceTransformers and vLLM.

This library provides fast, GPU-accelerated scoring for text generation evaluation, making BERTScore practical for large-scale inference tasks.


⚡ Features

  • Fast, efficient computation with optional vLLM support
  • Compatible with all Hugging Face transformer models
  • Supports truncated and optimized model versions for faster inference
  • Works seamlessly with both CPU and GPU setups

📦 Installation

Modern-BERT-Score comes in two variants: a base version and a vLLM-enhanced version. For vLLM, an NVIDIA GPU is strongly recommended.

Base Version

pip install modern-bert-score

vLLM Version

pip install modern-bert-score[vllm]

This implementation is significantly faster than the original BERTScore, especially with GPU acceleration.

📝 BERTScore

BERTScore (Zhang et al., 2019) evaluates the similarity between candidate and reference texts by comparing their contextual embeddings from a pre-trained transformer model. For each token in the candidate, it finds the most similar token in the reference (using cosine similarity) and aggregates these scores to compute precision, recall, and F1. Optionally, IDF-weighting can be applied to give more importance to rare and informative words, improving the metric’s sensitivity to meaningful content over common words. Additionally, optional Baseline Rescaling shifts the scores such that the score is in the range of [0,1]. This approach captures semantic similarity beyond exact word matches, making it robust for tasks such as machine translation and text generation evaluation.

The following figure, taken from the original paper, illustrates how BERTScore works:

BERTScore

🛠 Usage

Example

from modern_bert_score import BertScore

candidates = ["Hello World!", "A robin is a bird."]
references = ["Hi World!", "A robin is not a bird."]

metric = BertScore(model_id="roberta-base")
scores = metric(candidates, references)

# scores is a list of (Precision, Recall, F1) tuples
# To get separate lists of P, R, F1:
P, R, F1 = zip(*scores)

print("Precision scores:", P)
print("Recall scores:", R)
print("F1 scores:", F1)

⚠️ NOTICE

Some pre-truncated models optimized for vLLM are available on Hugging Face and directly available in this library:

  • LazerLambda/ModernBERT-base-ModBERTScore-12 -> ModernBERTBaseScore
  • LazerLambda/ModernBERT-large-ModBERTScore-19 -> ModernBERTLargeScore
  • LazerLambda/roberta-base-ModBERTScore-10 -> RobertaBaseScore
  • LazerLambda/roberta-large-ModBERTScore-17 -> RobertaLargeScore
  • LazerLambda/roberta-large-mnli-ModBERTScore-19 -> RobertaLargeMNLIScore

🗺 Roadmap

  • Implement base version and vLLM addon
  • Add IDF-weighted scoring
  • Add baseline-rescaling and scripts for identifying optimal baselines
  • Add model (vLLM-)adaptation script for slicing the model
  • Add multilingual support
  • Add CLI tool

Metadata

Release files for modern-bert-score 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for modern-bert-score 0.0.2
File Size Uploaded
modern_bert_score-0.0.2.tar.gz 14.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for modern-bert-score 0.0.2
File Interpreter ABI Platform
modern_bert_score-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 25.1 kB

Release files / modern_bert_score-0.0.2.tar.gz

Download URL modern_bert_score-0.0.2.tar.gz
Size 14.5 kB
Tags Source
SHA-256 checksum
How to use checksums
5108515b3e7dc1840af1563139cbc200bc8b38159877eb55e876c9b8e55cfa40
BLAKE2b-256 checksum
How to use checksums
2bce7918919cf59b9b766a1a5a6ccb46637b62a3f035c7cc4fcf3cdcc035ad06
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release files / modern_bert_score-0.0.2-py3-none-any.whl

Download URL modern_bert_score-0.0.2-py3-none-any.whl
Size 10.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
11d51899339ee03c01ba82301cc0b98eca8d9359d6515ef5f93d3e8d7dc19530
BLAKE2b-256 checksum
How to use checksums
26bf5807f9cad5aac9fc5fa614b7c2b2e439e8e10880a4c03bcf80eb6b40193a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page