π― Evaluationο
Measure the quality of your sentence embeddings using correlation metrics.
π Overviewο
AnglE provides evaluation tools to assess embedding quality using:
Spearmanβs Correlation: Measures monotonic relationships
Pearsonβs Correlation: Measures linear relationships
These metrics compare predicted similarities against ground truth labels, commonly used in semantic textual similarity (STS) tasks.
π― Spearman and Pearson Correlationο
Two methods are available for evaluation:
Method 1: Using angle.evaluate()ο
The simplest way to evaluate your model on a dataset.
Example:
from angle_emb import AnglE
from datasets import load_dataset
# Load model
angle = AnglE.from_pretrained('WhereIsAI/UAE-Large-V1').cuda()
# Load and prepare dataset (Format A: text1, text2, label)
ds = load_dataset('mteb/stsbenchmark-sts', split='test')
ds = ds.map(lambda obj: {
"text1": str(obj["sentence1"]),
"text2": str(obj['sentence2']),
"label": obj['score']
})
ds = ds.select_columns(["text1", "text2", "label"])
# Evaluate with Spearman correlation
score = angle.evaluate(ds, metric='spearman_cosine')
print(f"Spearman's correlation: {score:.4f}")
Available Metrics:
spearman_cosine: Spearman correlation with cosine similaritypearson_cosine: Pearson correlation with cosine similarity
Method 2: Using CorrelationEvaluatorο
More flexible evaluation with explicit control over inputs.
Example:
from angle_emb import AnglE, CorrelationEvaluator
from datasets import load_dataset
# Load model
angle = AnglE.from_pretrained('WhereIsAI/UAE-Large-V1').cuda()
# Load and prepare dataset
ds = load_dataset('mteb/stsbenchmark-sts', split='test')
ds = ds.map(lambda obj: {
"text1": str(obj["sentence1"]),
"text2": str(obj['sentence2']),
"label": obj['score']
})
ds = ds.select_columns(["text1", "text2", "label"])
# Create evaluator and run
metric = CorrelationEvaluator(
text1=ds['text1'],
text2=ds['text2'],
labels=ds['label']
)(angle, show_progress=True)
print(metric)
Output Format:
{
'spearman_cosine': 0.8521,
'pearson_cosine': 0.8432
}
π Next Stepsο
Learn how to π Training and Finetuning models for better performance
Follow the complete π¨βπ« Tutorial for hands-on practice
Check π Quick Start for basic inference
Explore ποΈ Official Pretrained Models for ready-to-use models