NLP & Text Metrics

Code-based metrics for reference overlap, lexical diversity, readability, and code structure.

These are code-based metrics, not LLM judges. Some compare generated text against a reference (meteor, chrf, gleu, code_bleu, translation_edit_rate, squad), some measure a text’s own diversity or structure (type_token_ratio, distinct_n, repetition_rate, sentence_count, readability_score), and one measures code structure directly (code_complexity).

Metrics

MetricWhat it measuresRequired inputsOutput
meteor_scoreUnigram precision/recall with stemming and a fragmentation penalty, correlates with human judgment better than BLEU on many tasksreference, hypothesisscore (0-1)
chrf_scoreCharacter n-gram F-score (order up to 6, recall-weighted), robust for morphologically rich languages and short textsreference, hypothesisscore (0-1)
gleu_scoreSentence-level BLEU variant taking the min of precision and recall per n-gram orderreference, hypothesisscore (0-1)
code_bleuN-gram BLEU blended with code-keyword matching (def, if, return, etc), weighted 0.7 BLEU / 0.3 keyword overlapreference, hypothesisscore (0-1)
code_complexityCyclomatic complexity of Python code via AST (branch points from if, for, while, except, boolean ops); lower complexity scores highertextscore (0-1), derived from a decision-point count
type_token_ratioLexical diversity: unique tokens divided by total tokenstextratio (0-1)
distinct_nVocabulary diversity: unique n-grams divided by total n-grams (n configurable, default 1)textratio (0-1)
repetition_rateRepeated n-gram rate, returned as 1 minus the rate so higher means less repetitive; flags degenerate/looping outputtextscore (0-1)
readability_scoreFlesch Reading Ease, normalized to 0-1 (Flesch-Kincaid grade level also reported in the reason)textscore (0-1)
sentence_countSentence count checked against a min_sentences/max_sentences range you configuretextPass/Fail
translation_edit_rateWord-level edit distance to transform hypothesis into reference, normalized by reference length, returned as 1-TERreference, hypothesisscore (0-1)
squad_scoreSQuAD-style QA scoring: average of exact match and token F1 after normalizing case, articles, and punctuationoutput, expectedscore (0-1)

Run a metric from code

Call evaluate() with the template id and the metric’s required inputs. Swap the template id to run any metric in this table.

Note

Before running: install the SDK and set FI_API_KEY / FI_SECRET_KEY. The model argument in the snippets is the evaluator model Future AGI uses to run the eval; turing_flash is a fast default.

from fi.evals import evaluate

result = evaluate(
    "meteor_score",
    reference="The cat sat quietly on the warm windowsill.",
    hypothesis="A cat sat quietly on the warm windowsill.",
    model="turing_flash",
)

print(result.score)
print(result.reason)
import { evaluate } from "@future-agi/ai-evaluation";

const result = await evaluate(
  "meteor_score",
  {
    reference: "The cat sat quietly on the warm windowsill.",
    hypothesis: "A cat sat quietly on the warm windowsill.",
  },
  { modelName: "turing_flash" }
);

console.log(result);

When to use

Reach for these when you need a fast, deterministic score instead of an LLM judge.

  • Translation or generation tasks where you have a reference text to score overlap against (meteor, chrf, gleu, translation_edit_rate)
  • Code generation, where code_bleu rewards matching structure and keywords, not just exact tokens
  • QA pipelines with a gold answer, using squad_score for exact match plus F1
  • Diversity and repetition checks on generated text (type_token_ratio, distinct_n, repetition_rate), useful for catching degenerate or looping output
  • Enforcing structural constraints like sentence count, or checking readability level for a target audience
  • Flagging overly complex generated code with code_complexity before it ships
Was this page helpful?

Questions & Discussion