MATCHA: Matching Text via Contrastive Semantic Alignment
Paper • 2605.27345 • Published
MATCHA is a learned text similarity metric that captures both semantic alignment and contradiction through contrastive training. It learns a dual-view semantic space in which semantically aligned texts are pulled closer while contradictory or irrelevant texts are pushed apart.
Paper: MATCHA: Matching Text via Contrastive Semantic Alignment Code: GitHub
| File | Description |
|---|---|
max_diff.pth |
Best checkpoint (selected by max pos–neg similarity difference) |
config.yaml |
Training hyperparameters |
model_config.json |
Model architecture configuration |
model.py |
Model architecture code |
matcha.py |
Simple inference interface |
pip install matcha-metric
from matcha_metric import MATCHA
model = MATCHA.from_pretrained("Siran-Li/MATCHA")
# Score a pair of texts
similarity = model.score("The vaccine was proven effective.", "Clinical trials confirmed the vaccine works.")
print(f"Similarity: {similarity:.4f}")
# Batch scoring
scores = model.score(
["The cat sat on the mat.", "It is raining outside."],
["A feline rested on the rug.", "The weather is sunny and clear."],
)
# Get embeddings directly
embeddings = model.encode(["Hello world", "Hi there"])
Token-level attribution via Integrated Gradients:
# Get raw token attributions
result = model.interpret("The cat sat on the mat.", "A feline rested on the rug.")
for token, attr in zip(result["tokens"], result["attributions"]):
print(f"{token:>15s} {attr:+.4f}")
# Save interactive HTML heatmap
model.visualize(
"The cat sat on the mat.",
"A feline rested on the rug.",
label="Correct",
output_path="attribution.html",
)
Aligned pair ("The cat sat on the mat." vs. "A feline rested on the rug."):
Contradictory pair ("It is raining outside." vs. "The weather is sunny and clear."):
Evaluated on 7 benchmarks: SNLI, MultiNLI, MedNLI, TruthfulQA, COCO-Caption, NEWTS, and Climate-FEVER.
@article{li2026matcha,
title={MATCHA: Matching Text via Contrastive Semantic Alignment},
author={Li, Siran and Etoglu, Ece Sena and Eickhoff, Carsten and Bahrainian, Seyed Ali},
journal={arXiv preprint arXiv:2605.27345},
year={2026}
}