Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Explodinggradients Ragas Collections BleuScore Metric

From Leeroopedia
Revision as of 14:53, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Explodinggradients_Ragas_Collections_BleuScore_Metric.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Field Value
source Repo
domains Metrics, NLP
last_updated 2026-02-10 00:00 GMT

Overview

BleuScore is a v2 class-based metric that calculates the BLEU (Bilingual Evaluation Understudy) score between a reference and response text using the sacrebleu library.

Description

BleuScore extends BaseMetric to provide an async-first BLEU score implementation. BLEU is a precision-based metric originally designed for machine translation evaluation that measures n-gram overlap between a candidate and reference text. The implementation splits both reference and response into sentences (on period-space boundaries), formats them for sacrebleu's corpus_bleu function, and normalizes the score to a 0.0--1.0 range by dividing by 100. No LLM or embedding components are required.

Usage

Instantiate with an optional name and kwargs dict (forwarded to sacrebleu.corpus_bleu). Call ascore(reference, response) for single evaluations or abatch_score(inputs) for batch evaluations. Requires the sacrebleu package.

Code Reference

Property Value
Source Location src/ragas/metrics/collections/_bleu_score.py L1--87
Signature class BleuScore(BaseMetric)
Import from ragas.metrics.collections import BleuScore

I/O Contract

Inputs

Parameter Type Required Description
reference str Yes The reference / ground truth text
response str Yes The response text to evaluate

Constructor Parameters

Parameter Type Default Description
name str "bleu_score" Metric name
kwargs Optional[Dict[str, Any]] None Extra arguments forwarded to sacrebleu.corpus_bleu

Outputs

Field Type Description
MetricResult.value float BLEU score in range 0.0--1.0

Usage Examples

from ragas.metrics.collections import BleuScore

# Basic usage
metric = BleuScore()
result = await metric.ascore(
    reference="The capital of France is Paris.",
    response="Paris is the capital of France."
)
print(f"BLEU Score: {result.value}")

# With custom sacrebleu arguments
metric = BleuScore(kwargs={"smooth_method": "exp"})
result = await metric.ascore(
    reference="The quick brown fox jumps over the lazy dog.",
    response="A quick brown fox jumped over the lazy dog."
)

# Batch evaluation
results = await metric.abatch_score([
    {"reference": "Text one.", "response": "Response one."},
    {"reference": "Text two.", "response": "Response two."},
])
for r in results:
    print(r.value)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment