File size: 2,475 Bytes
7476daa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import os, json, time, warnings
os.environ['HF_HUB_DISABLE_XET'] = '1'
os.environ['TOKENIZERS_PARALLELISM'] = 'false'
warnings.filterwarnings('ignore')

import mteb
import datasets
import pandas as pd
from pathlib import Path
from huggingface_hub import snapshot_download

MODEL = 'mixedbread-ai/deepset-mxbai-embed-de-large-v1'

benchmark = None
for b in mteb.get_benchmarks():
    if getattr(b, 'name', None) == 'MTEB(eng, v2)':
        benchmark = b
        break

mind_task = [t for t in benchmark.tasks if t.metadata.name == 'MindSmallReranking'][0]
print(f'Task: {mind_task.metadata.name}', flush=True)

# Download dataset to HF cache
print('Downloading dataset...', flush=True)
t0 = time.time()
snapshot_download(
    repo_id='mteb/MindSmallReranking',
    repo_type='dataset',
    revision='227478e3235572039f4f7661840e059f31ef6eb1',
)
print(f'Downloaded: {time.time()-t0:.1f}s', flush=True)

# Load data in offline mode
print('Loading data...', flush=True)
os.environ['HF_DATASETS_OFFLINE'] = '1'
t0 = time.time()
mind_task.load_data()
print(f'Data loaded: {time.time()-t0:.1f}s', flush=True)

# Load model
print('Loading model...', flush=True)
t0 = time.time()
model = mteb.get_model(MODEL)
print(f'Model loaded: {time.time()-t0:.1f}s', flush=True)

# Evaluate
print('Running evaluation...', flush=True)
outdir = Path('/tmp/output')
outdir.mkdir(parents=True, exist_ok=True)
t0 = time.time()
results = mteb.evaluate(
    model, tasks=[mind_task],
    prediction_folder=str(outdir),
    overwrite_strategy='always', raise_error=True,
)
print(f'Completed: {time.time()-t0:.0f}s', flush=True)

for tr in results.task_results:
    for split, sv in tr.scores.items():
        if isinstance(sv, list):
            for s in sv:
                ms = s.get('main_score')
                if ms is not None:
                    print(f'SCORE: {tr.task_name} [{split}]: {ms:.4f}', flush=True)
        elif isinstance(sv, dict):
            ms = sv.get('main_score')
            if ms is not None:
                print(f'SCORE: {tr.task_name} [{split}]: {ms:.4f}', flush=True)

from mteb.results.task_result import TaskResult
tr_data = results.task_results[0]
task_result = TaskResult.model_validate(tr_data.model_dump())
json_text = task_result.model_dump_json(indent=2)

# Save to file
with open('/data/mindsmall_result.json', 'w') as f:
    f.write(json_text)
print('Saved to /data/mindsmall_result.json', flush=True)

print('JSON_START')
print(json_text)
print('JSON_END')