mteb 2.7.13__py3-none-any.whl → 2.7.15__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mteb/abstasks/pair_classification.py +13 -7
- mteb/models/get_model_meta.py +14 -2
- mteb/models/model_implementations/bm25.py +1 -1
- mteb/models/model_implementations/human.py +1 -1
- mteb/models/model_implementations/opensearch_neural_sparse_models.py +5 -5
- mteb/models/model_meta.py +169 -18
- mteb/results/model_result.py +23 -0
- mteb/results/task_result.py +4 -4
- mteb/tasks/pair_classification/fas/fars_tail.py +2 -34
- {mteb-2.7.13.dist-info → mteb-2.7.15.dist-info}/METADATA +1 -1
- {mteb-2.7.13.dist-info → mteb-2.7.15.dist-info}/RECORD +15 -15
- {mteb-2.7.13.dist-info → mteb-2.7.15.dist-info}/WHEEL +0 -0
- {mteb-2.7.13.dist-info → mteb-2.7.15.dist-info}/entry_points.txt +0 -0
- {mteb-2.7.13.dist-info → mteb-2.7.15.dist-info}/licenses/LICENSE +0 -0
- {mteb-2.7.13.dist-info → mteb-2.7.15.dist-info}/top_level.txt +0 -0
|
@@ -25,6 +25,8 @@ from mteb.types.statistics import (
|
|
|
25
25
|
if TYPE_CHECKING:
|
|
26
26
|
from pathlib import Path
|
|
27
27
|
|
|
28
|
+
from numpy.typing import NDArray
|
|
29
|
+
|
|
28
30
|
from mteb._evaluators.pair_classification_evaluator import (
|
|
29
31
|
PairClassificationDistances,
|
|
30
32
|
)
|
|
@@ -36,7 +38,6 @@ if TYPE_CHECKING:
|
|
|
36
38
|
TextStatistics,
|
|
37
39
|
)
|
|
38
40
|
|
|
39
|
-
|
|
40
41
|
logger = logging.getLogger(__name__)
|
|
41
42
|
|
|
42
43
|
|
|
@@ -138,7 +139,7 @@ class AbsTaskPairClassification(AbsTask):
|
|
|
138
139
|
self, similarity_scores: PairClassificationDistances, labels: list[int]
|
|
139
140
|
) -> dict[str, float]:
|
|
140
141
|
logger.info("Computing metrics...")
|
|
141
|
-
np_labels = np.asarray(labels)
|
|
142
|
+
np_labels: NDArray[np.int64] = np.asarray(labels, dtype=np.int64)
|
|
142
143
|
output_scores = {}
|
|
143
144
|
max_scores = defaultdict(list)
|
|
144
145
|
for short_name, scores, reverse in [
|
|
@@ -281,7 +282,10 @@ class AbsTaskPairClassification(AbsTask):
|
|
|
281
282
|
)
|
|
282
283
|
|
|
283
284
|
def _compute_metrics_values(
|
|
284
|
-
self,
|
|
285
|
+
self,
|
|
286
|
+
scores: list[float],
|
|
287
|
+
labels: NDArray[np.int64],
|
|
288
|
+
high_score_more_similar: bool,
|
|
285
289
|
) -> dict[str, float]:
|
|
286
290
|
"""Compute the metrics for the given scores and labels.
|
|
287
291
|
|
|
@@ -315,7 +319,10 @@ class AbsTaskPairClassification(AbsTask):
|
|
|
315
319
|
)
|
|
316
320
|
|
|
317
321
|
def _find_best_acc_and_threshold(
|
|
318
|
-
self,
|
|
322
|
+
self,
|
|
323
|
+
scores: list[float],
|
|
324
|
+
labels: NDArray[np.int64],
|
|
325
|
+
high_score_more_similar: bool,
|
|
319
326
|
) -> tuple[float, float]:
|
|
320
327
|
rows = list(zip(scores, labels))
|
|
321
328
|
rows = sorted(rows, key=lambda x: x[0], reverse=high_score_more_similar)
|
|
@@ -323,7 +330,7 @@ class AbsTaskPairClassification(AbsTask):
|
|
|
323
330
|
max_acc = 0
|
|
324
331
|
best_threshold = -1.0
|
|
325
332
|
positive_so_far = 0
|
|
326
|
-
remaining_negatives = sum(
|
|
333
|
+
remaining_negatives = sum(labels == 0)
|
|
327
334
|
|
|
328
335
|
for i in range(len(rows) - 1):
|
|
329
336
|
score, label = rows[i]
|
|
@@ -339,10 +346,9 @@ class AbsTaskPairClassification(AbsTask):
|
|
|
339
346
|
return max_acc, best_threshold
|
|
340
347
|
|
|
341
348
|
def _find_best_f1_and_threshold(
|
|
342
|
-
self, scores, labels, high_score_more_similar: bool
|
|
349
|
+
self, scores, labels: NDArray[np.int64], high_score_more_similar: bool
|
|
343
350
|
) -> tuple[float, float, float, float]:
|
|
344
351
|
scores = np.asarray(scores)
|
|
345
|
-
labels = np.asarray(labels)
|
|
346
352
|
|
|
347
353
|
rows = list(zip(scores, labels))
|
|
348
354
|
|
mteb/models/get_model_meta.py
CHANGED
|
@@ -2,6 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import difflib
|
|
4
4
|
import logging
|
|
5
|
+
import warnings
|
|
5
6
|
from typing import TYPE_CHECKING, Any
|
|
6
7
|
|
|
7
8
|
from mteb.models import (
|
|
@@ -122,6 +123,11 @@ def get_model(
|
|
|
122
123
|
return model
|
|
123
124
|
|
|
124
125
|
|
|
126
|
+
_MODEL_RENAMES: dict[str, str] = {
|
|
127
|
+
"bm25s": "baseline/bm25s",
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
|
|
125
131
|
def get_model_meta(
|
|
126
132
|
model_name: str,
|
|
127
133
|
revision: str | None = None,
|
|
@@ -134,11 +140,17 @@ def get_model_meta(
|
|
|
134
140
|
model_name: Name of the model to fetch
|
|
135
141
|
revision: Revision of the model to fetch
|
|
136
142
|
fetch_from_hf: Whether to fetch the model from HuggingFace Hub if not found in the registry
|
|
137
|
-
fill_missing:
|
|
143
|
+
fill_missing: Fill missing attributes from the metadata including number of parameters and memory usage.
|
|
138
144
|
|
|
139
145
|
Returns:
|
|
140
146
|
A model metadata object
|
|
141
147
|
"""
|
|
148
|
+
if model_name in _MODEL_RENAMES:
|
|
149
|
+
new_name = _MODEL_RENAMES[model_name]
|
|
150
|
+
msg = f"The model '{model_name}' has been renamed to '{new_name}'. To prevent this warning use the new name."
|
|
151
|
+
warnings.warn(msg, DeprecationWarning, stacklevel=2)
|
|
152
|
+
model_name = new_name
|
|
153
|
+
|
|
142
154
|
if model_name in MODEL_REGISTRY:
|
|
143
155
|
model_meta = MODEL_REGISTRY[model_name]
|
|
144
156
|
|
|
@@ -149,7 +161,7 @@ def get_model_meta(
|
|
|
149
161
|
|
|
150
162
|
if fill_missing and fetch_from_hf:
|
|
151
163
|
original_meta_dict = model_meta.model_dump()
|
|
152
|
-
new_meta = ModelMeta.from_hub(model_name)
|
|
164
|
+
new_meta = ModelMeta.from_hub(model_name, fill_missing=fill_missing)
|
|
153
165
|
new_meta_dict = new_meta.model_dump(exclude_none=True)
|
|
154
166
|
|
|
155
167
|
updates = {
|
|
@@ -134,7 +134,7 @@ class SparseEncoderWrapper(AbsEncoder):
|
|
|
134
134
|
|
|
135
135
|
opensearch_neural_sparse_encoding_doc_v3_gte = ModelMeta(
|
|
136
136
|
name="opensearch-project/opensearch-neural-sparse-encoding-doc-v3-gte",
|
|
137
|
-
model_type=["
|
|
137
|
+
model_type=["sparse"],
|
|
138
138
|
languages=["eng-Latn"],
|
|
139
139
|
open_weights=True,
|
|
140
140
|
revision="a8abaa916125ee512a7a8f4d706d07eb0128a8e6",
|
|
@@ -161,7 +161,7 @@ opensearch_neural_sparse_encoding_doc_v3_gte = ModelMeta(
|
|
|
161
161
|
|
|
162
162
|
opensearch_neural_sparse_encoding_doc_v3_distill = ModelMeta(
|
|
163
163
|
name="opensearch-project/opensearch-neural-sparse-encoding-doc-v3-distill",
|
|
164
|
-
model_type=["
|
|
164
|
+
model_type=["sparse"],
|
|
165
165
|
languages=["eng-Latn"],
|
|
166
166
|
open_weights=True,
|
|
167
167
|
revision="babf71f3c48695e2e53a978208e8aba48335e3c0",
|
|
@@ -184,7 +184,7 @@ opensearch_neural_sparse_encoding_doc_v3_distill = ModelMeta(
|
|
|
184
184
|
|
|
185
185
|
opensearch_neural_sparse_encoding_doc_v2_distill = ModelMeta(
|
|
186
186
|
name="opensearch-project/opensearch-neural-sparse-encoding-doc-v2-distill",
|
|
187
|
-
model_type=["
|
|
187
|
+
model_type=["sparse"],
|
|
188
188
|
languages=["eng-Latn"],
|
|
189
189
|
open_weights=True,
|
|
190
190
|
revision="8921a26c78b8559d6604eb1f5c0b74c079bee38f",
|
|
@@ -208,7 +208,7 @@ opensearch_neural_sparse_encoding_doc_v2_distill = ModelMeta(
|
|
|
208
208
|
|
|
209
209
|
opensearch_neural_sparse_encoding_doc_v2_mini = ModelMeta(
|
|
210
210
|
name="opensearch-project/opensearch-neural-sparse-encoding-doc-v2-mini",
|
|
211
|
-
model_type=["
|
|
211
|
+
model_type=["sparse"],
|
|
212
212
|
languages=["eng-Latn"],
|
|
213
213
|
open_weights=True,
|
|
214
214
|
revision="4af867a426867dfdd744097531046f4289a32fdd",
|
|
@@ -231,7 +231,7 @@ opensearch_neural_sparse_encoding_doc_v2_mini = ModelMeta(
|
|
|
231
231
|
|
|
232
232
|
opensearch_neural_sparse_encoding_doc_v1 = ModelMeta(
|
|
233
233
|
name="opensearch-project/opensearch-neural-sparse-encoding-doc-v1",
|
|
234
|
-
model_type=["
|
|
234
|
+
model_type=["sparse"],
|
|
235
235
|
languages=["eng-Latn"],
|
|
236
236
|
open_weights=True,
|
|
237
237
|
revision="98cdcbd72867c547f72f2b7b7bed9cdf9f09922d",
|
mteb/models/model_meta.py
CHANGED
|
@@ -71,7 +71,7 @@ FRAMEWORKS = Literal[
|
|
|
71
71
|
"Transformers",
|
|
72
72
|
]
|
|
73
73
|
|
|
74
|
-
MODEL_TYPES = Literal["dense", "cross-encoder", "late-interaction"]
|
|
74
|
+
MODEL_TYPES = Literal["dense", "cross-encoder", "late-interaction", "sparse"]
|
|
75
75
|
|
|
76
76
|
|
|
77
77
|
class ScoringFunction(HelpfulStrEnum):
|
|
@@ -266,7 +266,7 @@ class ModelMeta(BaseModel):
|
|
|
266
266
|
@field_validator("name")
|
|
267
267
|
@classmethod
|
|
268
268
|
def _check_name(cls, v: str | None) -> str | None:
|
|
269
|
-
if v is None
|
|
269
|
+
if v is None:
|
|
270
270
|
return v
|
|
271
271
|
if "/" not in v:
|
|
272
272
|
raise ValueError(
|
|
@@ -302,26 +302,154 @@ class ModelMeta(BaseModel):
|
|
|
302
302
|
raise ValueError("Model name is not set")
|
|
303
303
|
return self.name.replace("/", "__").replace(" ", "_")
|
|
304
304
|
|
|
305
|
+
@classmethod
|
|
306
|
+
def _detect_cross_encoder_or_dense(
|
|
307
|
+
cls,
|
|
308
|
+
model_name: str,
|
|
309
|
+
revision: str | None,
|
|
310
|
+
sentence_transformers_loader: Callable[..., MTEBModels],
|
|
311
|
+
cross_encoder_loader: Callable[..., MTEBModels],
|
|
312
|
+
) -> tuple[Callable[..., MTEBModels] | None, MODEL_TYPES]:
|
|
313
|
+
"""Detect if model is CrossEncoder or default to dense."""
|
|
314
|
+
config = _get_json_from_hub(
|
|
315
|
+
model_name, "config.json", "model", revision=revision
|
|
316
|
+
)
|
|
317
|
+
|
|
318
|
+
if not config:
|
|
319
|
+
logger.warning(
|
|
320
|
+
f"Could not load config.json for {model_name}. "
|
|
321
|
+
"Defaulting to SentenceTransformer loader."
|
|
322
|
+
)
|
|
323
|
+
return sentence_transformers_loader, "dense"
|
|
324
|
+
|
|
325
|
+
architectures = config.get("architectures", [])
|
|
326
|
+
|
|
327
|
+
is_cross_encoder = any(
|
|
328
|
+
arch.endswith("ForSequenceClassification") for arch in architectures
|
|
329
|
+
)
|
|
330
|
+
if is_cross_encoder:
|
|
331
|
+
return cross_encoder_loader, "cross-encoder"
|
|
332
|
+
|
|
333
|
+
if cls._is_causal_lm_reranker(architectures, config, model_name):
|
|
334
|
+
return cross_encoder_loader, "cross-encoder"
|
|
335
|
+
|
|
336
|
+
logger.info(
|
|
337
|
+
f"Model {model_name} does not have modules.json or recognized architecture. "
|
|
338
|
+
"Defaulting to SentenceTransformer loader."
|
|
339
|
+
)
|
|
340
|
+
return sentence_transformers_loader, "dense"
|
|
341
|
+
|
|
342
|
+
@staticmethod
|
|
343
|
+
def _is_causal_lm_reranker(
|
|
344
|
+
architectures: list[str], config: dict[str, Any], model_name: str
|
|
345
|
+
) -> bool:
|
|
346
|
+
"""Check if model is a CausalLM-style reranker."""
|
|
347
|
+
is_causal_lm = any(arch.endswith("ForCausalLM") for arch in architectures)
|
|
348
|
+
|
|
349
|
+
if not is_causal_lm:
|
|
350
|
+
return False
|
|
351
|
+
|
|
352
|
+
num_labels = config.get("num_labels", 0)
|
|
353
|
+
model_name_lower = model_name.lower()
|
|
354
|
+
|
|
355
|
+
return (
|
|
356
|
+
num_labels > 0
|
|
357
|
+
or "rerank" in model_name_lower
|
|
358
|
+
or "cross-encoder" in model_name_lower
|
|
359
|
+
)
|
|
360
|
+
|
|
361
|
+
@classmethod
|
|
362
|
+
def _detect_model_type_and_loader(
|
|
363
|
+
cls,
|
|
364
|
+
model_name: str | None,
|
|
365
|
+
revision: str | None = None,
|
|
366
|
+
) -> tuple[Callable[..., MTEBModels] | None, MODEL_TYPES]:
|
|
367
|
+
"""Detect the model type and appropriate loader based on HuggingFace Hub configuration files.
|
|
368
|
+
|
|
369
|
+
This follows the Sentence Transformers architecture detection logic:
|
|
370
|
+
1. Check for modules.json - If present, model is a SentenceTransformer (dense encoder)
|
|
371
|
+
2. If no modules.json, check config.json for architecture:
|
|
372
|
+
- ForSequenceClassification → CrossEncoder
|
|
373
|
+
- CausalLM with reranking indicators → CrossEncoder
|
|
374
|
+
3. Default to dense (SentenceTransformer) if no clear indicators are found
|
|
375
|
+
|
|
376
|
+
Detection for CausalLM-style rerankers:
|
|
377
|
+
- Model has ForCausalLM architecture AND
|
|
378
|
+
- Has num_labels > 0 in config, OR
|
|
379
|
+
- Model name contains "rerank" or "cross-encoder"
|
|
380
|
+
|
|
381
|
+
Args:
|
|
382
|
+
model_name: The HuggingFace model name (can be None)
|
|
383
|
+
revision: The model revision
|
|
384
|
+
|
|
385
|
+
Returns:
|
|
386
|
+
A tuple of (loader_function, model_type) where:
|
|
387
|
+
- loader_function: A callable that returns MTEBModels, or None if model doesn't exist
|
|
388
|
+
- model_type: One of "dense", "cross-encoder", or "late-interaction"
|
|
389
|
+
"""
|
|
390
|
+
from mteb.models import CrossEncoderWrapper, sentence_transformers_loader
|
|
391
|
+
|
|
392
|
+
if not model_name or not _repo_exists(model_name):
|
|
393
|
+
return sentence_transformers_loader, "dense"
|
|
394
|
+
|
|
395
|
+
try:
|
|
396
|
+
modules_config = _get_json_from_hub(
|
|
397
|
+
model_name, "modules.json", "model", revision=revision
|
|
398
|
+
)
|
|
399
|
+
|
|
400
|
+
if (
|
|
401
|
+
modules_config
|
|
402
|
+
): # SentenceTransformer/SparseEncoder (Not support for now)
|
|
403
|
+
return sentence_transformers_loader, "dense"
|
|
404
|
+
else:
|
|
405
|
+
return cls._detect_cross_encoder_or_dense(
|
|
406
|
+
model_name,
|
|
407
|
+
revision,
|
|
408
|
+
sentence_transformers_loader,
|
|
409
|
+
cross_encoder_loader=CrossEncoderWrapper,
|
|
410
|
+
)
|
|
411
|
+
|
|
412
|
+
except Exception as e:
|
|
413
|
+
logger.warning(
|
|
414
|
+
f"Error detecting model type for {model_name}: {e}. "
|
|
415
|
+
"Defaulting to SentenceTransformer loader."
|
|
416
|
+
)
|
|
417
|
+
|
|
418
|
+
return sentence_transformers_loader, "dense"
|
|
419
|
+
|
|
305
420
|
@classmethod
|
|
306
421
|
def _from_hub(
|
|
307
422
|
cls,
|
|
308
423
|
model_name: str | None,
|
|
309
424
|
revision: str | None = None,
|
|
310
|
-
|
|
425
|
+
fill_missing: bool = True,
|
|
426
|
+
compute_metadata: bool | None = None,
|
|
311
427
|
) -> Self:
|
|
312
428
|
"""Generates a ModelMeta from a HuggingFace model name.
|
|
313
429
|
|
|
314
430
|
Args:
|
|
315
431
|
model_name: The HuggingFace model name.
|
|
316
432
|
revision: Revision of the model
|
|
317
|
-
|
|
433
|
+
fill_missing: Fill missing attributes from the metadata including number of parameters and memory usage.
|
|
434
|
+
compute_metadata: Deprecated. Use fill_missing instead.
|
|
318
435
|
|
|
319
436
|
Returns:
|
|
320
437
|
The generated ModelMeta.
|
|
321
438
|
"""
|
|
322
|
-
|
|
439
|
+
loader: Callable[..., MTEBModels] | None
|
|
440
|
+
model_type: MODEL_TYPES
|
|
441
|
+
|
|
442
|
+
if compute_metadata is not None:
|
|
443
|
+
warnings.warn(
|
|
444
|
+
"The compute_metadata parameter is deprecated and will be removed in a future version. "
|
|
445
|
+
f"Use fill_missing instead. Setting `fill_missing={compute_metadata}`.",
|
|
446
|
+
DeprecationWarning,
|
|
447
|
+
stacklevel=2,
|
|
448
|
+
)
|
|
449
|
+
fill_missing = compute_metadata
|
|
450
|
+
|
|
451
|
+
loader, model_type = cls._detect_model_type_and_loader(model_name, revision)
|
|
323
452
|
|
|
324
|
-
loader = sentence_transformers_loader
|
|
325
453
|
frameworks: list[FRAMEWORKS] = ["PyTorch"]
|
|
326
454
|
model_license = None
|
|
327
455
|
reference = None
|
|
@@ -331,7 +459,7 @@ class ModelMeta(BaseModel):
|
|
|
331
459
|
embedding_dim = None
|
|
332
460
|
max_tokens = None
|
|
333
461
|
|
|
334
|
-
if model_name and
|
|
462
|
+
if model_name and fill_missing and _repo_exists(model_name):
|
|
335
463
|
reference = "https://huggingface.co/" + model_name
|
|
336
464
|
card = ModelCard.load(model_name)
|
|
337
465
|
card_data: ModelCardData = card.data
|
|
@@ -363,6 +491,7 @@ class ModelMeta(BaseModel):
|
|
|
363
491
|
return cls(
|
|
364
492
|
loader=loader,
|
|
365
493
|
name=model_name or "no_model_name/available",
|
|
494
|
+
model_type=[model_type],
|
|
366
495
|
revision=revision or "no_revision_available",
|
|
367
496
|
reference=reference,
|
|
368
497
|
release_date=release_date,
|
|
@@ -387,14 +516,16 @@ class ModelMeta(BaseModel):
|
|
|
387
516
|
cls,
|
|
388
517
|
model: SentenceTransformer,
|
|
389
518
|
revision: str | None = None,
|
|
390
|
-
|
|
519
|
+
fill_missing: bool = False,
|
|
520
|
+
compute_metadata: bool | None = None,
|
|
391
521
|
) -> Self:
|
|
392
522
|
"""Generates a ModelMeta from a SentenceTransformer model.
|
|
393
523
|
|
|
394
524
|
Args:
|
|
395
525
|
model: SentenceTransformer model.
|
|
396
526
|
revision: Revision of the model
|
|
397
|
-
|
|
527
|
+
fill_missing: Fill missing attributes from the metadata including number of parameters and memory usage.
|
|
528
|
+
compute_metadata: Deprecated. Use fill_missing instead.
|
|
398
529
|
|
|
399
530
|
Returns:
|
|
400
531
|
The generated ModelMeta.
|
|
@@ -404,7 +535,9 @@ class ModelMeta(BaseModel):
|
|
|
404
535
|
if model.model_card_data.model_name
|
|
405
536
|
else model.model_card_data.base_model
|
|
406
537
|
)
|
|
407
|
-
meta = cls._from_hub(
|
|
538
|
+
meta = cls._from_hub(
|
|
539
|
+
name, revision, fill_missing=fill_missing, compute_metadata=compute_metadata
|
|
540
|
+
)
|
|
408
541
|
try:
|
|
409
542
|
first = model[0]
|
|
410
543
|
|
|
@@ -417,7 +550,9 @@ class ModelMeta(BaseModel):
|
|
|
417
550
|
meta.max_tokens = model.max_seq_length
|
|
418
551
|
meta.embed_dim = model.get_sentence_embedding_dimension()
|
|
419
552
|
meta.similarity_fn_name = ScoringFunction.from_str(model.similarity_fn_name)
|
|
420
|
-
meta.modalities = ["text"]
|
|
553
|
+
meta.modalities = ["text"] # best guess
|
|
554
|
+
if "Sentence Transformers" not in meta.framework:
|
|
555
|
+
meta.framework.append("Sentence Transformers")
|
|
421
556
|
return meta
|
|
422
557
|
|
|
423
558
|
@classmethod
|
|
@@ -425,22 +560,29 @@ class ModelMeta(BaseModel):
|
|
|
425
560
|
cls,
|
|
426
561
|
model: str,
|
|
427
562
|
revision: str | None = None,
|
|
428
|
-
|
|
563
|
+
fill_missing: bool = True,
|
|
564
|
+
compute_metadata: bool | None = None,
|
|
429
565
|
) -> Self:
|
|
430
566
|
"""Generates a ModelMeta for model from HuggingFace hub.
|
|
431
567
|
|
|
432
568
|
Args:
|
|
433
569
|
model: Name of the model from HuggingFace hub. For example, `intfloat/multilingual-e5-large`
|
|
434
570
|
revision: Revision of the model
|
|
435
|
-
|
|
571
|
+
fill_missing: Fill missing attributes from the metadata including number of parameters and memory usage.
|
|
572
|
+
compute_metadata: Deprecated. Use fill_missing instead.
|
|
436
573
|
|
|
437
574
|
Returns:
|
|
438
575
|
The generated ModelMeta.
|
|
439
576
|
"""
|
|
440
|
-
meta = cls._from_hub(
|
|
577
|
+
meta = cls._from_hub(
|
|
578
|
+
model,
|
|
579
|
+
revision,
|
|
580
|
+
fill_missing=fill_missing,
|
|
581
|
+
compute_metadata=compute_metadata,
|
|
582
|
+
)
|
|
441
583
|
meta.modalities = ["text"]
|
|
442
584
|
|
|
443
|
-
if model and
|
|
585
|
+
if model and fill_missing and _repo_exists(model):
|
|
444
586
|
# have max_seq_length field
|
|
445
587
|
sbert_config = _get_json_from_hub(
|
|
446
588
|
model, "sentence_bert_config.json", "model", revision=revision
|
|
@@ -469,21 +611,28 @@ class ModelMeta(BaseModel):
|
|
|
469
611
|
cls,
|
|
470
612
|
model: CrossEncoder,
|
|
471
613
|
revision: str | None = None,
|
|
472
|
-
|
|
614
|
+
fill_missing: bool = False,
|
|
615
|
+
compute_metadata: bool | None = None,
|
|
473
616
|
) -> Self:
|
|
474
617
|
"""Generates a ModelMeta from a CrossEncoder.
|
|
475
618
|
|
|
476
619
|
Args:
|
|
477
620
|
model: The CrossEncoder model
|
|
478
621
|
revision: Revision of the model
|
|
479
|
-
|
|
622
|
+
fill_missing: Fill missing attributes from the metadata including number of parameters and memory usage.
|
|
623
|
+
compute_metadata: Deprecated. Use fill_missing instead.
|
|
480
624
|
|
|
481
625
|
Returns:
|
|
482
626
|
The generated ModelMeta
|
|
483
627
|
"""
|
|
484
628
|
from mteb.models import CrossEncoderWrapper
|
|
485
629
|
|
|
486
|
-
meta = cls._from_hub(
|
|
630
|
+
meta = cls._from_hub(
|
|
631
|
+
model.model.name_or_path,
|
|
632
|
+
revision,
|
|
633
|
+
fill_missing=fill_missing,
|
|
634
|
+
compute_metadata=compute_metadata,
|
|
635
|
+
)
|
|
487
636
|
try:
|
|
488
637
|
emb = model.model.get_input_embeddings()
|
|
489
638
|
|
|
@@ -498,6 +647,8 @@ class ModelMeta(BaseModel):
|
|
|
498
647
|
meta.embed_dim = None
|
|
499
648
|
meta.modalities = ["text"]
|
|
500
649
|
meta.model_type = ["cross-encoder"]
|
|
650
|
+
if "Sentence Transformers" not in meta.framework:
|
|
651
|
+
meta.framework.append("Sentence Transformers")
|
|
501
652
|
return meta
|
|
502
653
|
|
|
503
654
|
def is_zero_shot_on(self, tasks: Sequence[AbsTask] | Sequence[str]) -> bool | None:
|
mteb/results/model_result.py
CHANGED
|
@@ -17,6 +17,7 @@ from .task_result import TaskError, TaskResult
|
|
|
17
17
|
|
|
18
18
|
if TYPE_CHECKING:
|
|
19
19
|
from collections.abc import Callable, Iterable
|
|
20
|
+
from pathlib import Path
|
|
20
21
|
|
|
21
22
|
from mteb.abstasks.abstask import AbsTask
|
|
22
23
|
from mteb.abstasks.task_metadata import (
|
|
@@ -417,3 +418,25 @@ class ModelResult(BaseModel):
|
|
|
417
418
|
if not mods:
|
|
418
419
|
mods = self.default_modalities
|
|
419
420
|
return list(set(mods))
|
|
421
|
+
|
|
422
|
+
def to_disk(self, path: Path) -> None:
|
|
423
|
+
"""Save ModelResult to disk as JSON.
|
|
424
|
+
|
|
425
|
+
Args:
|
|
426
|
+
path: The path to the file to save.
|
|
427
|
+
"""
|
|
428
|
+
with path.open("w") as f:
|
|
429
|
+
f.write(self.model_dump_json(indent=2))
|
|
430
|
+
|
|
431
|
+
@classmethod
|
|
432
|
+
def from_disk(cls, path: Path) -> ModelResult:
|
|
433
|
+
"""Load ModelResult from disk.
|
|
434
|
+
|
|
435
|
+
Args:
|
|
436
|
+
path: The path to the JSON file to load.
|
|
437
|
+
|
|
438
|
+
Returns:
|
|
439
|
+
The loaded ModelResult object.
|
|
440
|
+
"""
|
|
441
|
+
with path.open("r", encoding="utf-8") as f:
|
|
442
|
+
return cls.model_validate_json(f.read())
|
mteb/results/task_result.py
CHANGED
|
@@ -337,16 +337,16 @@ class TaskResult(BaseModel):
|
|
|
337
337
|
The loaded TaskResult object.
|
|
338
338
|
"""
|
|
339
339
|
with path.open("r", encoding="utf-8") as f:
|
|
340
|
-
|
|
340
|
+
json_str = f.read()
|
|
341
341
|
|
|
342
342
|
if not load_historic_data:
|
|
343
343
|
try:
|
|
344
|
-
return cls.
|
|
344
|
+
return cls.model_validate_json(json_str)
|
|
345
345
|
except Exception as e:
|
|
346
346
|
raise ValueError(
|
|
347
347
|
f"Error loading TaskResult from disk. You can try to load historic data by setting `load_historic_data=True`. Error: {e}"
|
|
348
348
|
)
|
|
349
|
-
|
|
349
|
+
data = json.loads(json_str)
|
|
350
350
|
pre_1_11_load = (
|
|
351
351
|
(
|
|
352
352
|
"mteb_version" in data
|
|
@@ -357,7 +357,7 @@ class TaskResult(BaseModel):
|
|
|
357
357
|
) # assume it is before 1.11.0 if the version is not present
|
|
358
358
|
|
|
359
359
|
try:
|
|
360
|
-
obj: TaskResult = cls.
|
|
360
|
+
obj: TaskResult = cls.model_validate_json(json_str)
|
|
361
361
|
except Exception as e:
|
|
362
362
|
if not pre_1_11_load:
|
|
363
363
|
raise e
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import datasets
|
|
2
|
-
|
|
3
1
|
from mteb.abstasks.pair_classification import AbsTaskPairClassification
|
|
4
2
|
from mteb.abstasks.task_metadata import TaskMetadata
|
|
5
3
|
|
|
@@ -8,8 +6,8 @@ class FarsTail(AbsTaskPairClassification):
|
|
|
8
6
|
metadata = TaskMetadata(
|
|
9
7
|
name="FarsTail",
|
|
10
8
|
dataset={
|
|
11
|
-
"path": "
|
|
12
|
-
"revision": "
|
|
9
|
+
"path": "mteb/FarsTail",
|
|
10
|
+
"revision": "0fa0863dc160869b5a2d78803b4440ea3c671ff5",
|
|
13
11
|
},
|
|
14
12
|
description="This dataset, named FarsTail, includes 10,367 samples which are provided in both the Persian language as well as the indexed format to be useful for non-Persian researchers. The samples are generated from 3,539 multiple-choice questions with the least amount of annotator interventions in a way similar to the SciTail dataset",
|
|
15
13
|
reference="https://link.springer.com/article/10.1007/s00500-023-08959-3",
|
|
@@ -37,33 +35,3 @@ class FarsTail(AbsTaskPairClassification):
|
|
|
37
35
|
}
|
|
38
36
|
""", # after removing neutral
|
|
39
37
|
)
|
|
40
|
-
|
|
41
|
-
def load_data(self, num_proc: int = 1, **kwargs) -> None:
|
|
42
|
-
if self.data_loaded:
|
|
43
|
-
return
|
|
44
|
-
path = self.metadata.dataset["path"]
|
|
45
|
-
revision = self.metadata.dataset["revision"]
|
|
46
|
-
data_files = {
|
|
47
|
-
"test": f"https://huggingface.co/datasets/{path}/resolve/{revision}/data/Test-word.csv"
|
|
48
|
-
}
|
|
49
|
-
self.dataset = datasets.load_dataset(
|
|
50
|
-
"csv", data_files=data_files, delimiter="\t"
|
|
51
|
-
)
|
|
52
|
-
self.dataset_transform()
|
|
53
|
-
self.data_loaded = True
|
|
54
|
-
|
|
55
|
-
def dataset_transform(self, num_proc: int = 1):
|
|
56
|
-
_dataset = {}
|
|
57
|
-
self.dataset = self.dataset.filter(lambda x: x["label"] != "n")
|
|
58
|
-
self.dataset = self.dataset.map(
|
|
59
|
-
lambda example: {"label": 1 if example["label"] == "e" else 0}
|
|
60
|
-
)
|
|
61
|
-
for split in self.metadata.eval_splits:
|
|
62
|
-
_dataset[split] = [
|
|
63
|
-
{
|
|
64
|
-
"sentence1": self.dataset[split]["premise"],
|
|
65
|
-
"sentence2": self.dataset[split]["hypothesis"],
|
|
66
|
-
"labels": self.dataset[split]["label"],
|
|
67
|
-
}
|
|
68
|
-
]
|
|
69
|
-
self.dataset = _dataset
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mteb
|
|
3
|
-
Version: 2.7.
|
|
3
|
+
Version: 2.7.15
|
|
4
4
|
Summary: Massive Text Embedding Benchmark
|
|
5
5
|
Author-email: MTEB Contributors <niklas@huggingface.co>, Kenneth Enevoldsen <kenneth.enevoldsen@cas.au.dk>, Nouamane Tazi <nouamane@huggingface.co>, Nils Reimers <info@nils-reimers.de>
|
|
6
6
|
Maintainer-email: Kenneth Enevoldsen <kenneth.enevoldsen@cas.au.dk>, Roman Solomatin <risolomatin@gmail.com>, Isaac Chung <chungisaac1217@gmail.com>
|
|
@@ -40,7 +40,7 @@ mteb/abstasks/clustering.py,sha256=I8vre2f2FJFagzJEYf6hKDo3Y28xU29J_O-MhfqWqSI,1
|
|
|
40
40
|
mteb/abstasks/clustering_legacy.py,sha256=sbx8K6paccvzDPnmhgNE_UJE83orAJnQm3NGr-Ktjfs,9184
|
|
41
41
|
mteb/abstasks/dataset_card_template.md,sha256=aD6l8qc3_jxwoIGJNYLzse-jpRa8hu92AxpnUtNgges,5122
|
|
42
42
|
mteb/abstasks/multilabel_classification.py,sha256=rFa_Pw2OsUzqhZS-jh2zFD7I-TNl8bVNJ-DW7EpPapU,9708
|
|
43
|
-
mteb/abstasks/pair_classification.py,sha256=
|
|
43
|
+
mteb/abstasks/pair_classification.py,sha256=RVV5WUjs18N5PbWpyxakDNEd1UlRc4ON9I0OjD26Z78,14231
|
|
44
44
|
mteb/abstasks/regression.py,sha256=ZuMZfOwU3G4hr__eHsgdagKKdrbN4-wQMLz45jr9YUc,8946
|
|
45
45
|
mteb/abstasks/retrieval.py,sha256=BPyRibStAD70JfR0Z1x-VVVfzJDRVSmbOS6uREfpmok,27743
|
|
46
46
|
mteb/abstasks/retrieval_dataset_loaders.py,sha256=p0y1nrWlUrt_aeoR4ocDLEQMLuD_SlMH0gBiUsOwrww,9983
|
|
@@ -1479,9 +1479,9 @@ mteb/leaderboard/table.py,sha256=U5mWtrVUTk_6t8T4KAp5qlbFgKh1PD0iKICqNMfhsoY,104
|
|
|
1479
1479
|
mteb/leaderboard/text_segments.py,sha256=iMIkS04QQjPbT-SkU0x6fOcS8xRbUYevryu9HydipKM,6570
|
|
1480
1480
|
mteb/models/__init__.py,sha256=ABTuoqiBjBtBWW3LYY7ItBHdylR6jWoy06HH0g6j6fU,910
|
|
1481
1481
|
mteb/models/abs_encoder.py,sha256=We9HlwWP61P4cMyZ080gywvDErA1eVsU9t46PtcNrCM,16830
|
|
1482
|
-
mteb/models/get_model_meta.py,sha256=
|
|
1482
|
+
mteb/models/get_model_meta.py,sha256=EUy3F2A57qfm046lDJQ2eaAaD_buHALD7XHJeYsx8vY,7234
|
|
1483
1483
|
mteb/models/instruct_wrapper.py,sha256=XAvvbPnXiTxKhFbmusm2uS8E9BMq8QXRSzQQI1jqKzE,9781
|
|
1484
|
-
mteb/models/model_meta.py,sha256=
|
|
1484
|
+
mteb/models/model_meta.py,sha256=B2BpzOZAxBgNwMrZ-saN0sw-Y4tjBKIbt2byDoQz3ac,38873
|
|
1485
1485
|
mteb/models/models_protocols.py,sha256=HTB4-SYa3SeJXMMSA8o05lHTiLBbq314VW60K_PfcZY,9509
|
|
1486
1486
|
mteb/models/search_wrappers.py,sha256=PXE1VVDWUd0LgTPJ-FxqIbGpIDWLRKo5CjrwIuu5nzw,21567
|
|
1487
1487
|
mteb/models/sentence_transformer_wrapper.py,sha256=RsOxj-b7qzeYcxUTVJyb-lZDY4bINl4jEAEkPvKYB10,13578
|
|
@@ -1505,7 +1505,7 @@ mteb/models/model_implementations/bge_models.py,sha256=JuO1FRWrsqlsM_jslQ96oVsD3
|
|
|
1505
1505
|
mteb/models/model_implementations/bica_model.py,sha256=Yx3iZrXF6ZMJS9SH5lbzNHoUWGNH3dypRtZ7dX5o7rA,1305
|
|
1506
1506
|
mteb/models/model_implementations/blip2_models.py,sha256=C6egwozJthHmv92I0SWID3-sQCPROPJP0TzfQVKNzlo,7898
|
|
1507
1507
|
mteb/models/model_implementations/blip_models.py,sha256=D_9e7C8GXGST8k7dMJL20x984vMeqbITu36XASi-iUU,12149
|
|
1508
|
-
mteb/models/model_implementations/bm25.py,sha256
|
|
1508
|
+
mteb/models/model_implementations/bm25.py,sha256=IAKU8syYesN7seRQLII-c1ACq6BRz5Ql6nEQEXYWLwQ,5226
|
|
1509
1509
|
mteb/models/model_implementations/bmretriever_models.py,sha256=rijCIzX6nO5kNXqxEFbZrV7bsZtmKs8RIkMqa5cPWTk,7078
|
|
1510
1510
|
mteb/models/model_implementations/cadet_models.py,sha256=gXIfW9MkGYFhOhsrq5a_tQcPuth13Dh1dO1KySwVxyo,2305
|
|
1511
1511
|
mteb/models/model_implementations/cde_models.py,sha256=l4E6h1hcsNY1GTXoCgQDoeG5dRcEl7JTOiiWmp6FYqg,9373
|
|
@@ -1537,7 +1537,7 @@ mteb/models/model_implementations/granite_vision_embedding_models.py,sha256=jxyR
|
|
|
1537
1537
|
mteb/models/model_implementations/gritlm_models.py,sha256=756vgZGADy5FhKlFuzuD6huevC_AYD5b88V1Y5yFht8,3241
|
|
1538
1538
|
mteb/models/model_implementations/gte_models.py,sha256=-ASkoAuAiVytVtsYMtuKonUf39i0U69HSEnJy_-PwXA,14574
|
|
1539
1539
|
mteb/models/model_implementations/hinvec_models.py,sha256=SYWGFr8XALmM7B9tIHEQnrqq9kZOZIBkW7m7QpzerHI,1756
|
|
1540
|
-
mteb/models/model_implementations/human.py,sha256=
|
|
1540
|
+
mteb/models/model_implementations/human.py,sha256=k7vN6WTcSWyWS9wnluzr6yCOjuMi5LupQnT-4cfzNOk,600
|
|
1541
1541
|
mteb/models/model_implementations/ibm_granite_models.py,sha256=ipLRDBerTQiL5NaoaDho410Fzy7eNFlF3jB54hGZrwI,8687
|
|
1542
1542
|
mteb/models/model_implementations/inf_models.py,sha256=q_hNNhzMjAxbnJnAT0N6KaNegX_3XZlmz-LXY5C891I,3093
|
|
1543
1543
|
mteb/models/model_implementations/jasper_models.py,sha256=ourAMx1_L6b2AxX046wQcxDqvYzY1Mx3gaHww0WaMA8,16476
|
|
@@ -1572,7 +1572,7 @@ mteb/models/model_implementations/nvidia_models.py,sha256=r-AW1dVQbteWjexjvZgFEt
|
|
|
1572
1572
|
mteb/models/model_implementations/octen_models.py,sha256=5z-t2O-iIFiOOLdZ_AK9f7GrVRg-9_vx3JNAG9dJNPE,8562
|
|
1573
1573
|
mteb/models/model_implementations/openai_models.py,sha256=y1wMknrrcu1L5CNwniG0mFThPVMON1c2Fj22jkKsw7Y,9730
|
|
1574
1574
|
mteb/models/model_implementations/openclip_models.py,sha256=z2gQum16O0QhJPyxqKor3oO-_uWfnep6wSXqOFQQ2Q8,11969
|
|
1575
|
-
mteb/models/model_implementations/opensearch_neural_sparse_models.py,sha256=
|
|
1575
|
+
mteb/models/model_implementations/opensearch_neural_sparse_models.py,sha256=J5FEvKWQUiBusL6PHcrRuRRJOQ-iMwOSu1fX0pblXhk,8941
|
|
1576
1576
|
mteb/models/model_implementations/ops_colqwen3_models.py,sha256=5vg5d1_WfVGMgtIwkh6zf2-Paum6V35XcKEvLfRyRzs,7437
|
|
1577
1577
|
mteb/models/model_implementations/ops_moa_models.py,sha256=Ah7L78mqC9pH8t6sf1OWXOLjouVUpAutt6lZ0np7eMM,2655
|
|
1578
1578
|
mteb/models/model_implementations/ordalietech_solon_embeddings_mini_beta_1_1.py,sha256=xv1ftJeMND4lpeKYC3RLQB4nhdiYy0wCxrzEjUj4gSg,1114
|
|
@@ -1629,8 +1629,8 @@ mteb/models/search_encoder_index/search_indexes/__init__.py,sha256=Wm60_oUemUpFs
|
|
|
1629
1629
|
mteb/models/search_encoder_index/search_indexes/faiss_search_index.py,sha256=jwC-3swhnILZnVHUrMR7Ts78TuYtVRxPusF02UV1g6E,5770
|
|
1630
1630
|
mteb/results/__init__.py,sha256=EXQqK4Am5eIYzD52dpcGAFSdqnC38oE6JHN302oidHc,158
|
|
1631
1631
|
mteb/results/benchmark_results.py,sha256=unBUBJ92ud0UXlkZJLn71WVcf-oUlF6XcITTccz5OBA,20318
|
|
1632
|
-
mteb/results/model_result.py,sha256=
|
|
1633
|
-
mteb/results/task_result.py,sha256=
|
|
1632
|
+
mteb/results/model_result.py,sha256=h894O5-RSCOF8XNpXMuhBCqnj43T-1K5Y1el_fyrzP4,15954
|
|
1633
|
+
mteb/results/task_result.py,sha256=Wi5MRQBkb0Qddhc4nLzrrjm1nGlCh8aq4_VCQoxGmNg,34300
|
|
1634
1634
|
mteb/tasks/__init__.py,sha256=izAxU0ip1F_YUwx0dFCuN35BaktdmePh6vlDiHC0kLo,503
|
|
1635
1635
|
mteb/tasks/aggregated_tasks/__init__.py,sha256=Ufgbh1AirxCQkojO3AUhUFWM8zQG10cfdVTkj_PeyLI,104
|
|
1636
1636
|
mteb/tasks/aggregated_tasks/eng/__init__.py,sha256=HgaSyAX8Is5CGE006RgJkLQQVxrx2FmMnm6NHQBDi-4,358
|
|
@@ -2113,7 +2113,7 @@ mteb/tasks/pair_classification/eng/twitter_sem_eval2015_pc.py,sha256=0YjKK4C47Uu
|
|
|
2113
2113
|
mteb/tasks/pair_classification/eng/twitter_url_corpus_pc.py,sha256=M9B3JCFt4L6yEnd8S-o-W-FtCSMdl0h1KST3fqApEVA,1796
|
|
2114
2114
|
mteb/tasks/pair_classification/fas/__init__.py,sha256=1Bbr5ZKSjpPuJb9zvk7OSd2Krdh1bpxJjVNLNPFT4Ck,440
|
|
2115
2115
|
mteb/tasks/pair_classification/fas/fa_mteb_pair_classification.py,sha256=1i8phewQffpIxzWtBWQFUisHu3XhBpk9Sf-IkwM8jNg,10932
|
|
2116
|
-
mteb/tasks/pair_classification/fas/fars_tail.py,sha256=
|
|
2116
|
+
mteb/tasks/pair_classification/fas/fars_tail.py,sha256=jb-6UW0Lk7YxdMMCZsMavY6CRiv3T6MFrbvlPd0vPPk,1676
|
|
2117
2117
|
mteb/tasks/pair_classification/hye/__init__.py,sha256=hU4xSf6kyKhD4o4CuNMQNE1w9FKv8tkkqvYvhpMV5Kg,93
|
|
2118
2118
|
mteb/tasks/pair_classification/hye/armenian_paraphrase_pc.py,sha256=Ezi604W-cHOLDm8O9j3yq9z-GzDt9OWI9jgyqVjY9M4,1437
|
|
2119
2119
|
mteb/tasks/pair_classification/ind/__init__.py,sha256=iXGvZ6eNgGhyD2wgbkvV-bpPPCJNxlE5eq_qvF2Y_UI,53
|
|
@@ -2646,9 +2646,9 @@ mteb/types/_metadata.py,sha256=NN-W0S6a5TDV7UkpRx1pyWtGF4TyyCyoPUfHOwdeci8,2290
|
|
|
2646
2646
|
mteb/types/_result.py,sha256=UKNokV9pu3G74MGebocU512aU_fFU9I9nPKnrG9Q0iE,1035
|
|
2647
2647
|
mteb/types/_string_validators.py,sha256=PY-dYq4E8O50VS3bLYdldPWp400fl_WzUjfVSkNWe8U,523
|
|
2648
2648
|
mteb/types/statistics.py,sha256=gElgSShKBXpfcqaZHhU_d2UHln1CyzUj8FN8KFun_UA,4087
|
|
2649
|
-
mteb-2.7.
|
|
2650
|
-
mteb-2.7.
|
|
2651
|
-
mteb-2.7.
|
|
2652
|
-
mteb-2.7.
|
|
2653
|
-
mteb-2.7.
|
|
2654
|
-
mteb-2.7.
|
|
2649
|
+
mteb-2.7.15.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
2650
|
+
mteb-2.7.15.dist-info/METADATA,sha256=EoUeroRRdre5jYbplBGCJuWs-6M7cZGpzwLqSQyJKgI,14348
|
|
2651
|
+
mteb-2.7.15.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
2652
|
+
mteb-2.7.15.dist-info/entry_points.txt,sha256=8IJoEJFKoDHmVnNev-qJ9pp4Ln7_1-ma9QsXnzVCzGU,39
|
|
2653
|
+
mteb-2.7.15.dist-info/top_level.txt,sha256=OLVIjcQAlWBz0bdmutKlWHLF42FF0hp4uVAg3ZyiG4U,5
|
|
2654
|
+
mteb-2.7.15.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|