mteb 2.5.2__py3-none-any.whl → 2.7.2__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/__init__.py +2 -0
- mteb/_create_dataloaders.py +17 -18
- mteb/_evaluators/any_sts_evaluator.py +3 -3
- mteb/_evaluators/clustering_evaluator.py +2 -2
- mteb/_evaluators/evaluator.py +4 -2
- mteb/_evaluators/image/imagetext_pairclassification_evaluator.py +10 -8
- mteb/_evaluators/pair_classification_evaluator.py +5 -3
- mteb/_evaluators/retrieval_evaluator.py +2 -2
- mteb/_evaluators/retrieval_metrics.py +18 -17
- mteb/_evaluators/sklearn_evaluator.py +11 -10
- mteb/_evaluators/text/bitext_mining_evaluator.py +27 -18
- mteb/_evaluators/text/summarization_evaluator.py +23 -18
- mteb/_evaluators/zeroshot_classification_evaluator.py +5 -3
- mteb/abstasks/_data_filter/filters.py +1 -1
- mteb/abstasks/_data_filter/task_pipelines.py +3 -0
- mteb/abstasks/_statistics_calculation.py +18 -10
- mteb/abstasks/_stratification.py +18 -18
- mteb/abstasks/abstask.py +35 -28
- mteb/abstasks/aggregate_task_metadata.py +1 -9
- mteb/abstasks/aggregated_task.py +10 -29
- mteb/abstasks/classification.py +15 -10
- mteb/abstasks/clustering.py +19 -15
- mteb/abstasks/clustering_legacy.py +10 -10
- mteb/abstasks/image/image_text_pair_classification.py +7 -4
- mteb/abstasks/multilabel_classification.py +23 -19
- mteb/abstasks/pair_classification.py +20 -11
- mteb/abstasks/regression.py +4 -4
- mteb/abstasks/retrieval.py +28 -24
- mteb/abstasks/retrieval_dataset_loaders.py +2 -2
- mteb/abstasks/sts.py +8 -5
- mteb/abstasks/task_metadata.py +31 -33
- mteb/abstasks/text/bitext_mining.py +39 -28
- mteb/abstasks/text/reranking.py +8 -6
- mteb/abstasks/text/summarization.py +10 -5
- mteb/abstasks/zeroshot_classification.py +8 -4
- mteb/benchmarks/benchmark.py +4 -2
- mteb/benchmarks/benchmarks/__init__.py +4 -0
- mteb/benchmarks/benchmarks/benchmarks.py +112 -11
- mteb/benchmarks/get_benchmark.py +14 -55
- mteb/cache.py +182 -29
- mteb/cli/_display_tasks.py +2 -2
- mteb/cli/build_cli.py +110 -14
- mteb/cli/generate_model_card.py +43 -23
- mteb/deprecated_evaluator.py +63 -49
- mteb/descriptive_stats/Image/DocumentUnderstanding/KoVidore2CybersecurityRetrieval.json +32 -0
- mteb/descriptive_stats/Image/DocumentUnderstanding/KoVidore2EconomicRetrieval.json +32 -0
- mteb/descriptive_stats/Image/DocumentUnderstanding/KoVidore2EnergyRetrieval.json +32 -0
- mteb/descriptive_stats/Image/DocumentUnderstanding/KoVidore2HrRetrieval.json +32 -0
- mteb/descriptive_stats/Retrieval/ChemRxivRetrieval.json +30 -0
- mteb/descriptive_stats/Retrieval/EuroPIRQRetrieval.json +116 -0
- mteb/descriptive_stats/Retrieval/NanoClimateFEVER-VN.json +30 -0
- mteb/descriptive_stats/Retrieval/NanoDBPedia-VN.json +30 -0
- mteb/descriptive_stats/Retrieval/NanoFEVER-VN.json +30 -0
- mteb/descriptive_stats/Retrieval/NanoHotpotQA-VN.json +30 -0
- mteb/descriptive_stats/Retrieval/NanoMSMARCO-VN.json +30 -0
- mteb/descriptive_stats/Retrieval/NanoNQ-VN.json +30 -0
- mteb/descriptive_stats/Retrieval/TVPLRetrieval.json +30 -0
- mteb/evaluate.py +44 -33
- mteb/filter_tasks.py +25 -26
- mteb/get_tasks.py +29 -30
- mteb/languages/language_scripts.py +5 -3
- mteb/leaderboard/app.py +162 -34
- mteb/load_results.py +12 -12
- mteb/models/abs_encoder.py +10 -6
- mteb/models/cache_wrappers/cache_backend_protocol.py +3 -5
- mteb/models/cache_wrappers/cache_backends/_hash_utils.py +5 -4
- mteb/models/cache_wrappers/cache_backends/faiss_cache.py +6 -2
- mteb/models/cache_wrappers/cache_backends/numpy_cache.py +43 -25
- mteb/models/cache_wrappers/cache_wrapper.py +2 -2
- mteb/models/get_model_meta.py +21 -3
- mteb/models/instruct_wrapper.py +28 -8
- mteb/models/model_implementations/align_models.py +1 -1
- mteb/models/model_implementations/andersborges.py +4 -4
- mteb/models/model_implementations/ara_models.py +1 -1
- mteb/models/model_implementations/arctic_models.py +8 -8
- mteb/models/model_implementations/b1ade_models.py +1 -1
- mteb/models/model_implementations/bge_models.py +45 -21
- mteb/models/model_implementations/bica_model.py +3 -3
- mteb/models/model_implementations/blip2_models.py +2 -2
- mteb/models/model_implementations/blip_models.py +16 -16
- mteb/models/model_implementations/bm25.py +4 -4
- mteb/models/model_implementations/bmretriever_models.py +6 -4
- mteb/models/model_implementations/cadet_models.py +1 -1
- mteb/models/model_implementations/cde_models.py +11 -4
- mteb/models/model_implementations/clip_models.py +6 -6
- mteb/models/model_implementations/clips_models.py +3 -3
- mteb/models/model_implementations/codefuse_models.py +5 -5
- mteb/models/model_implementations/codesage_models.py +3 -3
- mteb/models/model_implementations/cohere_models.py +5 -5
- mteb/models/model_implementations/cohere_v.py +2 -2
- mteb/models/model_implementations/colpali_models.py +3 -3
- mteb/models/model_implementations/colqwen_models.py +8 -8
- mteb/models/model_implementations/colsmol_models.py +2 -2
- mteb/models/model_implementations/conan_models.py +1 -1
- mteb/models/model_implementations/dino_models.py +42 -42
- mteb/models/model_implementations/e5_instruct.py +23 -4
- mteb/models/model_implementations/e5_models.py +9 -9
- mteb/models/model_implementations/e5_v.py +6 -6
- mteb/models/model_implementations/eagerworks_models.py +1 -1
- mteb/models/model_implementations/emillykkejensen_models.py +6 -6
- mteb/models/model_implementations/en_code_retriever.py +1 -1
- mteb/models/model_implementations/euler_models.py +2 -2
- mteb/models/model_implementations/fa_models.py +9 -9
- mteb/models/model_implementations/facebookai.py +14 -2
- mteb/models/model_implementations/geogpt_models.py +1 -1
- mteb/models/model_implementations/gme_v_models.py +6 -5
- mteb/models/model_implementations/google_models.py +1 -1
- mteb/models/model_implementations/granite_vision_embedding_models.py +1 -1
- mteb/models/model_implementations/gritlm_models.py +2 -2
- mteb/models/model_implementations/gte_models.py +25 -13
- mteb/models/model_implementations/hinvec_models.py +1 -1
- mteb/models/model_implementations/ibm_granite_models.py +30 -6
- mteb/models/model_implementations/inf_models.py +2 -2
- mteb/models/model_implementations/jasper_models.py +2 -2
- mteb/models/model_implementations/jina_clip.py +48 -10
- mteb/models/model_implementations/jina_models.py +18 -11
- mteb/models/model_implementations/kblab.py +12 -6
- mteb/models/model_implementations/kennethenevoldsen_models.py +4 -4
- mteb/models/model_implementations/kfst.py +1 -1
- mteb/models/model_implementations/kowshik24_models.py +1 -1
- mteb/models/model_implementations/lgai_embedding_models.py +1 -1
- mteb/models/model_implementations/linq_models.py +1 -1
- mteb/models/model_implementations/listconranker.py +1 -1
- mteb/models/model_implementations/llm2clip_models.py +6 -6
- mteb/models/model_implementations/llm2vec_models.py +8 -8
- mteb/models/model_implementations/mcinext_models.py +4 -1
- mteb/models/model_implementations/mdbr_models.py +17 -3
- mteb/models/model_implementations/misc_models.py +68 -68
- mteb/models/model_implementations/mixedbread_ai_models.py +332 -0
- mteb/models/model_implementations/mme5_models.py +1 -1
- mteb/models/model_implementations/moco_models.py +4 -4
- mteb/models/model_implementations/mod_models.py +1 -1
- mteb/models/model_implementations/model2vec_models.py +14 -14
- mteb/models/model_implementations/moka_models.py +1 -1
- mteb/models/model_implementations/nbailab.py +3 -3
- mteb/models/model_implementations/no_instruct_sentence_models.py +2 -2
- mteb/models/model_implementations/nomic_models.py +30 -15
- mteb/models/model_implementations/nomic_models_vision.py +1 -1
- mteb/models/model_implementations/nvidia_llama_nemoretriever_colemb.py +15 -9
- mteb/models/model_implementations/nvidia_models.py +151 -19
- mteb/models/model_implementations/octen_models.py +61 -2
- mteb/models/model_implementations/openclip_models.py +13 -13
- mteb/models/model_implementations/opensearch_neural_sparse_models.py +5 -5
- mteb/models/model_implementations/ops_moa_models.py +1 -1
- mteb/models/model_implementations/ordalietech_solon_embeddings_mini_beta_1_1.py +1 -1
- mteb/models/model_implementations/pawan_models.py +1 -1
- mteb/models/model_implementations/piccolo_models.py +1 -1
- mteb/models/model_implementations/pixie_models.py +56 -0
- mteb/models/model_implementations/promptriever_models.py +4 -4
- mteb/models/model_implementations/pylate_models.py +10 -9
- mteb/models/model_implementations/qodo_models.py +2 -2
- mteb/models/model_implementations/qtack_models.py +1 -1
- mteb/models/model_implementations/qwen3_models.py +3 -3
- mteb/models/model_implementations/qzhou_models.py +2 -2
- mteb/models/model_implementations/random_baseline.py +3 -3
- mteb/models/model_implementations/rasgaard_models.py +2 -2
- mteb/models/model_implementations/reasonir_model.py +1 -1
- mteb/models/model_implementations/repllama_models.py +3 -3
- mteb/models/model_implementations/rerankers_custom.py +12 -6
- mteb/models/model_implementations/rerankers_monot5_based.py +17 -17
- mteb/models/model_implementations/richinfoai_models.py +1 -1
- mteb/models/model_implementations/ru_sentence_models.py +20 -20
- mteb/models/model_implementations/ruri_models.py +10 -10
- mteb/models/model_implementations/salesforce_models.py +3 -3
- mteb/models/model_implementations/samilpwc_models.py +1 -1
- mteb/models/model_implementations/sarashina_embedding_models.py +2 -2
- mteb/models/model_implementations/searchmap_models.py +1 -1
- mteb/models/model_implementations/seed_1_6_embedding_models_1215.py +113 -146
- mteb/models/model_implementations/sentence_transformers_models.py +124 -22
- mteb/models/model_implementations/shuu_model.py +1 -1
- mteb/models/model_implementations/siglip_models.py +20 -20
- mteb/models/model_implementations/slm_models.py +416 -0
- mteb/models/model_implementations/spartan8806_atles_champion.py +1 -1
- mteb/models/model_implementations/stella_models.py +17 -4
- mteb/models/model_implementations/tarka_models.py +2 -2
- mteb/models/model_implementations/text2vec_models.py +9 -3
- mteb/models/model_implementations/ua_sentence_models.py +1 -1
- mteb/models/model_implementations/uae_models.py +7 -1
- mteb/models/model_implementations/vdr_models.py +1 -1
- mteb/models/model_implementations/vi_vn_models.py +6 -6
- mteb/models/model_implementations/vlm2vec_models.py +3 -3
- mteb/models/model_implementations/voyage_models.py +84 -0
- mteb/models/model_implementations/voyage_v.py +9 -7
- mteb/models/model_implementations/youtu_models.py +1 -1
- mteb/models/model_implementations/yuan_models.py +1 -1
- mteb/models/model_implementations/yuan_models_en.py +1 -1
- mteb/models/model_meta.py +80 -31
- mteb/models/models_protocols.py +22 -6
- mteb/models/search_encoder_index/search_indexes/faiss_search_index.py +9 -6
- mteb/models/search_wrappers.py +33 -18
- mteb/models/sentence_transformer_wrapper.py +50 -25
- mteb/models/vllm_wrapper.py +327 -0
- mteb/py.typed +0 -0
- mteb/results/benchmark_results.py +29 -21
- mteb/results/model_result.py +52 -22
- mteb/results/task_result.py +80 -58
- mteb/similarity_functions.py +11 -7
- mteb/tasks/classification/dan/dk_hate_classification.py +1 -1
- mteb/tasks/classification/est/estonian_valence.py +1 -1
- mteb/tasks/classification/kur/kurdish_sentiment_classification.py +2 -2
- mteb/tasks/classification/multilingual/scala_classification.py +1 -1
- mteb/tasks/clustering/eng/hume_wiki_cities_clustering.py +1 -1
- mteb/tasks/clustering/eng/wiki_cities_clustering.py +1 -1
- mteb/tasks/clustering/zho/cmteb_clustering.py +2 -2
- mteb/tasks/image_text_pair_classification/eng/sugar_crepe.py +1 -1
- mteb/tasks/reranking/multilingual/wikipedia_reranking_multilingual.py +1 -1
- mteb/tasks/retrieval/code/code_rag.py +12 -12
- mteb/tasks/retrieval/dan/dan_fever_retrieval.py +1 -1
- mteb/tasks/retrieval/dan/tv2_nordretrieval.py +2 -2
- mteb/tasks/retrieval/dan/twitter_hjerne_retrieval.py +2 -2
- mteb/tasks/retrieval/eng/__init__.py +2 -0
- mteb/tasks/retrieval/eng/chemrxiv.py +33 -0
- mteb/tasks/retrieval/eng/cub200_i2i_retrieval.py +1 -1
- mteb/tasks/retrieval/kor/__init__.py +15 -1
- mteb/tasks/retrieval/kor/kovidore2_bench_retrieval.py +142 -0
- mteb/tasks/retrieval/multilingual/__init__.py +2 -0
- mteb/tasks/retrieval/multilingual/euro_pirq_retrieval.py +43 -0
- mteb/tasks/retrieval/multilingual/vidore3_bench_retrieval.py +90 -100
- mteb/tasks/retrieval/nob/norquad.py +2 -2
- mteb/tasks/retrieval/nob/snl_retrieval.py +2 -2
- mteb/tasks/retrieval/tur/tur_hist_quad.py +1 -1
- mteb/tasks/retrieval/vie/__init__.py +14 -6
- mteb/tasks/retrieval/vie/climate_fevervn_retrieval.py +39 -0
- mteb/tasks/retrieval/vie/db_pedia_vn_retrieval.py +39 -0
- mteb/tasks/retrieval/vie/fevervn_retrieval.py +39 -0
- mteb/tasks/retrieval/vie/hotpot_qavn_retrieval.py +39 -0
- mteb/tasks/retrieval/vie/msmarcovn_retrieval.py +48 -0
- mteb/tasks/retrieval/vie/nqvn_retrieval.py +39 -0
- mteb/tasks/retrieval/vie/tvpl_retrieval.py +42 -0
- mteb/tasks/retrieval/vie/zac_legal_text_retrieval.py +15 -1
- mteb/types/__init__.py +2 -0
- mteb/types/_encoder_io.py +12 -0
- mteb/types/_result.py +2 -1
- mteb/types/statistics.py +9 -3
- {mteb-2.5.2.dist-info → mteb-2.7.2.dist-info}/METADATA +15 -4
- {mteb-2.5.2.dist-info → mteb-2.7.2.dist-info}/RECORD +240 -219
- mteb/models/model_implementations/mxbai_models.py +0 -111
- {mteb-2.5.2.dist-info → mteb-2.7.2.dist-info}/WHEEL +0 -0
- {mteb-2.5.2.dist-info → mteb-2.7.2.dist-info}/entry_points.txt +0 -0
- {mteb-2.5.2.dist-info → mteb-2.7.2.dist-info}/licenses/LICENSE +0 -0
- {mteb-2.5.2.dist-info → mteb-2.7.2.dist-info}/top_level.txt +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import json
|
|
2
2
|
import logging
|
|
3
|
+
import warnings
|
|
3
4
|
from pathlib import Path
|
|
5
|
+
from typing import Any
|
|
4
6
|
|
|
5
7
|
import numpy as np
|
|
6
8
|
|
|
7
|
-
from mteb.types import BatchedInput
|
|
8
|
-
|
|
9
9
|
from ._hash_utils import _hash_item
|
|
10
10
|
|
|
11
11
|
logger = logging.getLogger(__name__)
|
|
@@ -14,7 +14,7 @@ logger = logging.getLogger(__name__)
|
|
|
14
14
|
class NumpyCache:
|
|
15
15
|
"""Generic vector cache for both text and images."""
|
|
16
16
|
|
|
17
|
-
def __init__(self, directory: str | Path, initial_vectors: int =
|
|
17
|
+
def __init__(self, directory: str | Path, initial_vectors: int = 100_000):
|
|
18
18
|
self.directory = Path(directory)
|
|
19
19
|
self.directory.mkdir(parents=True, exist_ok=True)
|
|
20
20
|
self.vectors_file = self.directory / "vectors.npy"
|
|
@@ -27,7 +27,7 @@ class NumpyCache:
|
|
|
27
27
|
logger.info(f"Initialized VectorCacheMap in directory: {self.directory}")
|
|
28
28
|
self._initialize_vectors_file()
|
|
29
29
|
|
|
30
|
-
def add(self,
|
|
30
|
+
def add(self, items: list[dict[str, Any]], vectors: np.ndarray) -> None:
|
|
31
31
|
"""Add a vector to the cache."""
|
|
32
32
|
try:
|
|
33
33
|
if self.vector_dim is None:
|
|
@@ -38,12 +38,17 @@ class NumpyCache:
|
|
|
38
38
|
self._save_dimension()
|
|
39
39
|
logger.info(f"Initialized vector dimension to {self.vector_dim}")
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
if self.vectors is None:
|
|
42
|
+
raise RuntimeError(
|
|
43
|
+
"Vectors file not initialized. Call _initialize_vectors_file() first."
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
for item, vec in zip(items, vectors):
|
|
42
47
|
item_hash = _hash_item(item)
|
|
43
48
|
if item_hash in self.hash_to_index:
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
)
|
|
49
|
+
msg = f"Hash collision or duplicate item for hash {item_hash}. Overwriting existing vector."
|
|
50
|
+
logger.warning(msg)
|
|
51
|
+
warnings.warn(msg)
|
|
47
52
|
index = self.hash_to_index[item_hash]
|
|
48
53
|
else:
|
|
49
54
|
index = len(self.hash_to_index)
|
|
@@ -74,18 +79,26 @@ class NumpyCache:
|
|
|
74
79
|
shape=(self.initial_vectors, self.vector_dim),
|
|
75
80
|
)
|
|
76
81
|
else:
|
|
77
|
-
self.vectors = np.memmap(
|
|
78
|
-
|
|
82
|
+
self.vectors = np.memmap(
|
|
83
|
+
self.vectors_file,
|
|
84
|
+
dtype="float32",
|
|
85
|
+
mode="r+",
|
|
86
|
+
shape=(-1, self.vector_dim),
|
|
87
|
+
)
|
|
79
88
|
logger.info(f"Vectors file initialized with shape: {self.vectors.shape}")
|
|
80
89
|
|
|
81
90
|
def _double_vectors_file(self) -> None:
|
|
91
|
+
if self.vectors is None or self.vector_dim is None:
|
|
92
|
+
raise RuntimeError(
|
|
93
|
+
"Vectors file not initialized. Call _initialize_vectors_file() first."
|
|
94
|
+
)
|
|
82
95
|
current_size = len(self.vectors)
|
|
83
96
|
new_size = current_size * 2
|
|
84
97
|
logger.info(f"Doubling vectors file from {current_size} to {new_size} vectors")
|
|
85
98
|
self.vectors.flush()
|
|
86
99
|
new_vectors = np.memmap(
|
|
87
|
-
self.vectors_file,
|
|
88
|
-
dtype=
|
|
100
|
+
str(self.vectors_file),
|
|
101
|
+
dtype=np.float32,
|
|
89
102
|
mode="r+",
|
|
90
103
|
shape=(new_size, self.vector_dim),
|
|
91
104
|
)
|
|
@@ -107,9 +120,9 @@ class NumpyCache:
|
|
|
107
120
|
f"Loaded vector dimension {self.vector_dim} from {self.dimension_file}"
|
|
108
121
|
)
|
|
109
122
|
else:
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
)
|
|
123
|
+
msg = "Dimension file not found. Vector dimension remains uninitialized."
|
|
124
|
+
logger.warning(msg)
|
|
125
|
+
warnings.warn(msg)
|
|
113
126
|
|
|
114
127
|
def save(self) -> None:
|
|
115
128
|
"""Persist VectorCacheMap to disk."""
|
|
@@ -146,25 +159,30 @@ class NumpyCache:
|
|
|
146
159
|
|
|
147
160
|
if self.vector_dim is not None:
|
|
148
161
|
self.vectors = np.memmap(
|
|
149
|
-
self.vectors_file,
|
|
162
|
+
self.vectors_file,
|
|
163
|
+
dtype="float32",
|
|
164
|
+
mode="r+",
|
|
165
|
+
shape=(-1, self.vector_dim),
|
|
150
166
|
)
|
|
151
|
-
self.vectors = self.vectors.reshape(-1, self.vector_dim)
|
|
152
167
|
logger.info(f"Loaded vectors file with shape: {self.vectors.shape}")
|
|
153
168
|
else:
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
)
|
|
169
|
+
msg = "Vector dimension not set. Unable to load vectors file."
|
|
170
|
+
logger.warning(msg)
|
|
171
|
+
warnings.warn(msg)
|
|
157
172
|
logger.info(f"Loaded VectorCacheMap from {self.directory}")
|
|
158
173
|
else:
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
)
|
|
174
|
+
msg = "No existing files found. Initialized empty VectorCacheMap."
|
|
175
|
+
logger.warning(msg)
|
|
176
|
+
warnings.warn(msg)
|
|
162
177
|
except Exception as e:
|
|
163
178
|
logger.error(f"Error loading VectorCacheMap: {str(e)}")
|
|
164
179
|
raise
|
|
165
180
|
|
|
166
|
-
def get_vector(self, item:
|
|
181
|
+
def get_vector(self, item: dict[str, Any]) -> np.ndarray | None:
|
|
167
182
|
"""Retrieve vector from index by hash."""
|
|
183
|
+
if self.vectors is None:
|
|
184
|
+
return None
|
|
185
|
+
|
|
168
186
|
try:
|
|
169
187
|
item_hash = _hash_item(item)
|
|
170
188
|
if item_hash not in self.hash_to_index:
|
|
@@ -176,7 +194,7 @@ class NumpyCache:
|
|
|
176
194
|
logger.error(f"Error retrieving vector for item: {str(e)}")
|
|
177
195
|
raise
|
|
178
196
|
|
|
179
|
-
def __contains__(self, item:
|
|
197
|
+
def __contains__(self, item: dict[str, Any]) -> bool:
|
|
180
198
|
return _hash_item(item) in self.hash_to_index
|
|
181
199
|
|
|
182
200
|
def __del__(self):
|
|
@@ -90,9 +90,9 @@ class CachedEmbeddingWrapper:
|
|
|
90
90
|
try:
|
|
91
91
|
cache = self._get_or_create_cache(task_name)
|
|
92
92
|
|
|
93
|
-
uncached_items: list[
|
|
93
|
+
uncached_items: list[dict[str, Any]] = []
|
|
94
94
|
uncached_indices: list[int] = []
|
|
95
|
-
all_items = inputs.dataset
|
|
95
|
+
all_items: Dataset = inputs.dataset
|
|
96
96
|
cached_vectors: dict[int, np.ndarray] = {}
|
|
97
97
|
|
|
98
98
|
for i, item in enumerate(all_items):
|
mteb/models/get_model_meta.py
CHANGED
|
@@ -21,6 +21,7 @@ def get_model_metas(
|
|
|
21
21
|
n_parameters_range: tuple[int | None, int | None] = (None, None),
|
|
22
22
|
use_instructions: bool | None = None,
|
|
23
23
|
zero_shot_on: list[AbsTask] | None = None,
|
|
24
|
+
model_types: Iterable[str] | None = None,
|
|
24
25
|
) -> list[ModelMeta]:
|
|
25
26
|
"""Load all models' metadata that fit the specified criteria.
|
|
26
27
|
|
|
@@ -33,6 +34,7 @@ def get_model_metas(
|
|
|
33
34
|
If (None, None), this filter is ignored.
|
|
34
35
|
use_instructions: Whether to filter by models that use instructions. If None, all models are included.
|
|
35
36
|
zero_shot_on: A list of tasks on which the model is zero-shot. If None this filter is ignored.
|
|
37
|
+
model_types: A list of model types to filter by. If None, all model types are included.
|
|
36
38
|
|
|
37
39
|
Returns:
|
|
38
40
|
A list of model metadata objects that fit the specified criteria.
|
|
@@ -41,6 +43,7 @@ def get_model_metas(
|
|
|
41
43
|
model_names = set(model_names) if model_names is not None else None
|
|
42
44
|
languages = set(languages) if languages is not None else None
|
|
43
45
|
frameworks = set(frameworks) if frameworks is not None else None
|
|
46
|
+
model_types_set = set(model_types) if model_types is not None else None
|
|
44
47
|
for model_meta in MODEL_REGISTRY.values():
|
|
45
48
|
if (model_names is not None) and (model_meta.name not in model_names):
|
|
46
49
|
continue
|
|
@@ -57,6 +60,10 @@ def get_model_metas(
|
|
|
57
60
|
model_meta.use_instructions != use_instructions
|
|
58
61
|
):
|
|
59
62
|
continue
|
|
63
|
+
if model_types_set is not None and not model_types_set.intersection(
|
|
64
|
+
model_meta.model_type
|
|
65
|
+
):
|
|
66
|
+
continue
|
|
60
67
|
|
|
61
68
|
lower, upper = n_parameters_range
|
|
62
69
|
n_parameters = model_meta.n_parameters
|
|
@@ -75,7 +82,10 @@ def get_model_metas(
|
|
|
75
82
|
|
|
76
83
|
|
|
77
84
|
def get_model(
|
|
78
|
-
model_name: str,
|
|
85
|
+
model_name: str,
|
|
86
|
+
revision: str | None = None,
|
|
87
|
+
device: str | None = None,
|
|
88
|
+
**kwargs: Any,
|
|
79
89
|
) -> MTEBModels:
|
|
80
90
|
"""A function to fetch and load model object by name.
|
|
81
91
|
|
|
@@ -85,15 +95,23 @@ def get_model(
|
|
|
85
95
|
Args:
|
|
86
96
|
model_name: Name of the model to fetch
|
|
87
97
|
revision: Revision of the model to fetch
|
|
98
|
+
device: Device used to load the model
|
|
88
99
|
**kwargs: Additional keyword arguments to pass to the model loader
|
|
89
100
|
|
|
90
101
|
Returns:
|
|
91
102
|
A model object
|
|
92
103
|
"""
|
|
93
104
|
meta = get_model_meta(model_name, revision)
|
|
94
|
-
model = meta.load_model(**kwargs)
|
|
105
|
+
model = meta.load_model(device=device, **kwargs)
|
|
106
|
+
|
|
107
|
+
if kwargs:
|
|
108
|
+
logger.info(
|
|
109
|
+
f"Model '{model_name}' loaded with additional arguments: {list(kwargs.keys())}"
|
|
110
|
+
)
|
|
111
|
+
meta = meta.model_copy(deep=True)
|
|
112
|
+
meta.loader_kwargs |= kwargs
|
|
95
113
|
|
|
96
|
-
model.mteb_model_meta = meta # type: ignore
|
|
114
|
+
model.mteb_model_meta = meta # type: ignore[misc]
|
|
97
115
|
return model
|
|
98
116
|
|
|
99
117
|
|
mteb/models/instruct_wrapper.py
CHANGED
|
@@ -17,7 +17,8 @@ logger = logging.getLogger(__name__)
|
|
|
17
17
|
def instruct_wrapper(
|
|
18
18
|
model_name_or_path: str,
|
|
19
19
|
mode: str,
|
|
20
|
-
instruction_template: str | Callable[[str], str] | None = None,
|
|
20
|
+
instruction_template: str | Callable[[str, PromptType | None], str] | None = None,
|
|
21
|
+
device: str | None = None,
|
|
21
22
|
**kwargs,
|
|
22
23
|
):
|
|
23
24
|
"""Instruct wrapper for models. Uses GritLM to pass instructions to the model.
|
|
@@ -28,6 +29,7 @@ def instruct_wrapper(
|
|
|
28
29
|
model_name_or_path: Model name or path.
|
|
29
30
|
mode: Mode of the model. Either 'query' or 'passage'.
|
|
30
31
|
instruction_template: Instruction template. Should contain the string '{instruction}'.
|
|
32
|
+
device: Device used to load the model.
|
|
31
33
|
**kwargs: Additional arguments to pass to the model.
|
|
32
34
|
"""
|
|
33
35
|
requires_package(
|
|
@@ -40,7 +42,10 @@ def instruct_wrapper(
|
|
|
40
42
|
self,
|
|
41
43
|
model_name_or_path: str,
|
|
42
44
|
mode: str,
|
|
43
|
-
|
|
45
|
+
device: str | None = None,
|
|
46
|
+
instruction_template: str
|
|
47
|
+
| Callable[[str, PromptType | None], str]
|
|
48
|
+
| None = None,
|
|
44
49
|
**kwargs,
|
|
45
50
|
):
|
|
46
51
|
if (
|
|
@@ -61,7 +66,12 @@ def instruct_wrapper(
|
|
|
61
66
|
)
|
|
62
67
|
|
|
63
68
|
self.instruction_template = instruction_template
|
|
64
|
-
super().__init__(
|
|
69
|
+
super().__init__(
|
|
70
|
+
model_name_or_path=model_name_or_path,
|
|
71
|
+
mode=mode,
|
|
72
|
+
device=device,
|
|
73
|
+
**kwargs,
|
|
74
|
+
)
|
|
65
75
|
|
|
66
76
|
def encode(
|
|
67
77
|
self,
|
|
@@ -82,15 +92,20 @@ def instruct_wrapper(
|
|
|
82
92
|
logger.info(
|
|
83
93
|
f"Using instruction: '{instruction}' for task: '{task_metadata.name}'"
|
|
84
94
|
)
|
|
85
|
-
embeddings = super().encode(
|
|
86
|
-
_inputs,
|
|
95
|
+
embeddings = super().encode( # type: ignore[safe-super,call-arg]
|
|
96
|
+
_inputs, # type: ignore[arg-type]
|
|
97
|
+
instruction=instruction,
|
|
98
|
+
*args,
|
|
99
|
+
**kwargs,
|
|
87
100
|
)
|
|
88
101
|
if isinstance(embeddings, torch.Tensor):
|
|
89
102
|
# sometimes in kwargs can be return_tensors=True
|
|
90
103
|
embeddings = embeddings.cpu().detach().float().numpy()
|
|
91
104
|
return embeddings
|
|
92
105
|
|
|
93
|
-
return InstructGritLMModel(
|
|
106
|
+
return InstructGritLMModel(
|
|
107
|
+
model_name_or_path, mode, instruction_template=instruction_template, **kwargs
|
|
108
|
+
)
|
|
94
109
|
|
|
95
110
|
|
|
96
111
|
class InstructSentenceTransformerModel(AbsEncoder):
|
|
@@ -100,6 +115,7 @@ class InstructSentenceTransformerModel(AbsEncoder):
|
|
|
100
115
|
self,
|
|
101
116
|
model_name: str,
|
|
102
117
|
revision: str,
|
|
118
|
+
device: str | None = None,
|
|
103
119
|
instruction_template: str
|
|
104
120
|
| Callable[[str, PromptType | None], str]
|
|
105
121
|
| None = None,
|
|
@@ -117,6 +133,7 @@ class InstructSentenceTransformerModel(AbsEncoder):
|
|
|
117
133
|
Arguments:
|
|
118
134
|
model_name: Model name of the sentence transformers model.
|
|
119
135
|
revision: Revision of the sentence transformers model.
|
|
136
|
+
device: Device used to load the model.
|
|
120
137
|
instruction_template: Model template. Should contain the string '{instruction}'.
|
|
121
138
|
max_seq_length: Maximum sequence length. If None, the maximum sequence length will be read from the model config.
|
|
122
139
|
apply_instruction_to_passages: Whether to apply the instruction template to the passages.
|
|
@@ -141,7 +158,7 @@ class InstructSentenceTransformerModel(AbsEncoder):
|
|
|
141
158
|
)
|
|
142
159
|
|
|
143
160
|
self.instruction_template = instruction_template
|
|
144
|
-
tokenizer_params = {}
|
|
161
|
+
tokenizer_params: dict[str, Any] = {}
|
|
145
162
|
if add_eos_token:
|
|
146
163
|
tokenizer_params["add_eos_token"] = add_eos_token
|
|
147
164
|
if max_seq_length is not None:
|
|
@@ -153,7 +170,9 @@ class InstructSentenceTransformerModel(AbsEncoder):
|
|
|
153
170
|
kwargs.setdefault("tokenizer_kwargs", {}).update(tokenizer_params)
|
|
154
171
|
|
|
155
172
|
self.model_name = model_name
|
|
156
|
-
self.model = SentenceTransformer(
|
|
173
|
+
self.model = SentenceTransformer(
|
|
174
|
+
model_name, revision=revision, device=device, **kwargs
|
|
175
|
+
)
|
|
157
176
|
if max_seq_length:
|
|
158
177
|
# https://github.com/huggingface/sentence-transformers/issues/3575
|
|
159
178
|
self.model.max_seq_length = max_seq_length
|
|
@@ -193,6 +212,7 @@ class InstructSentenceTransformerModel(AbsEncoder):
|
|
|
193
212
|
The encoded input in a numpy array or torch tensor of the shape (Number of sentences) x (Embedding dimension).
|
|
194
213
|
"""
|
|
195
214
|
sentences = [text for batch in inputs for text in batch["text"]]
|
|
215
|
+
instruction: str | None
|
|
196
216
|
instruction = self.get_task_instruction(task_metadata, prompt_type)
|
|
197
217
|
|
|
198
218
|
# to passage prompts won't be applied to passages
|
|
@@ -118,7 +118,7 @@ align_base = ModelMeta(
|
|
|
118
118
|
open_weights=True,
|
|
119
119
|
public_training_code="https://github.com/kakaobrain/coyo-align",
|
|
120
120
|
public_training_data=True,
|
|
121
|
-
framework=["PyTorch"],
|
|
121
|
+
framework=["PyTorch", "Transformers"],
|
|
122
122
|
reference="https://huggingface.co/kakaobrain/align-base",
|
|
123
123
|
similarity_fn_name=ScoringFunction.COSINE,
|
|
124
124
|
use_instructions=False,
|
|
@@ -4,7 +4,7 @@ from mteb.models.model_implementations.model2vec_models import Model2VecModel
|
|
|
4
4
|
from mteb.models.model_meta import ModelMeta, ScoringFunction
|
|
5
5
|
|
|
6
6
|
model2vecdk = ModelMeta(
|
|
7
|
-
loader=Model2VecModel,
|
|
7
|
+
loader=Model2VecModel,
|
|
8
8
|
name="andersborges/model2vecdk",
|
|
9
9
|
model_type=["dense"],
|
|
10
10
|
languages=["dan-Latn"],
|
|
@@ -17,7 +17,7 @@ model2vecdk = ModelMeta(
|
|
|
17
17
|
embed_dim=256,
|
|
18
18
|
license="mit",
|
|
19
19
|
similarity_fn_name=ScoringFunction.COSINE,
|
|
20
|
-
framework=["NumPy", "Sentence Transformers"],
|
|
20
|
+
framework=["NumPy", "Sentence Transformers", "safetensors"],
|
|
21
21
|
reference="https://huggingface.co/andersborges/model2vecdk",
|
|
22
22
|
use_instructions=False,
|
|
23
23
|
adapted_from="https://huggingface.co/jealk/TTC-L2V-supervised-2",
|
|
@@ -35,7 +35,7 @@ model2vecdk = ModelMeta(
|
|
|
35
35
|
|
|
36
36
|
|
|
37
37
|
model2vecdk_stem = ModelMeta(
|
|
38
|
-
loader=Model2VecModel,
|
|
38
|
+
loader=Model2VecModel,
|
|
39
39
|
name="andersborges/model2vecdk-stem",
|
|
40
40
|
model_type=["dense"],
|
|
41
41
|
languages=["dan-Latn"],
|
|
@@ -48,7 +48,7 @@ model2vecdk_stem = ModelMeta(
|
|
|
48
48
|
embed_dim=256,
|
|
49
49
|
license="mit",
|
|
50
50
|
similarity_fn_name=ScoringFunction.COSINE,
|
|
51
|
-
framework=["NumPy", "Sentence Transformers"],
|
|
51
|
+
framework=["NumPy", "Sentence Transformers", "safetensors"],
|
|
52
52
|
reference="https://huggingface.co/andersborges/model2vecdk",
|
|
53
53
|
use_instructions=False,
|
|
54
54
|
adapted_from="https://huggingface.co/jealk/TTC-L2V-supervised-2",
|
|
@@ -16,7 +16,7 @@ arabic_triplet_matryoshka = ModelMeta(
|
|
|
16
16
|
max_tokens=768,
|
|
17
17
|
reference="https://huggingface.co/Omartificial-Intelligence-Space/Arabic-Triplet-Matryoshka-V2",
|
|
18
18
|
similarity_fn_name=ScoringFunction.COSINE,
|
|
19
|
-
framework=["Sentence Transformers", "PyTorch"],
|
|
19
|
+
framework=["Sentence Transformers", "PyTorch", "safetensors", "Transformers"],
|
|
20
20
|
use_instructions=False,
|
|
21
21
|
public_training_code=None,
|
|
22
22
|
adapted_from="aubmindlab/bert-base-arabertv02",
|
|
@@ -145,7 +145,7 @@ arctic_embed_xs = ModelMeta(
|
|
|
145
145
|
release_date="2024-07-08", # initial commit of hf model.
|
|
146
146
|
languages=["eng-Latn"],
|
|
147
147
|
open_weights=True,
|
|
148
|
-
framework=["Sentence Transformers", "PyTorch"],
|
|
148
|
+
framework=["Sentence Transformers", "PyTorch", "ONNX", "safetensors"],
|
|
149
149
|
n_parameters=22_600_000,
|
|
150
150
|
memory_usage_mb=86,
|
|
151
151
|
max_tokens=512,
|
|
@@ -171,7 +171,7 @@ arctic_embed_s = ModelMeta(
|
|
|
171
171
|
release_date="2024-04-12", # initial commit of hf model.
|
|
172
172
|
languages=["eng-Latn"],
|
|
173
173
|
open_weights=True,
|
|
174
|
-
framework=["Sentence Transformers", "PyTorch"],
|
|
174
|
+
framework=["Sentence Transformers", "PyTorch", "ONNX", "safetensors"],
|
|
175
175
|
n_parameters=32_200_000,
|
|
176
176
|
memory_usage_mb=127,
|
|
177
177
|
max_tokens=512,
|
|
@@ -197,7 +197,7 @@ arctic_embed_m = ModelMeta(
|
|
|
197
197
|
release_date="2024-04-12", # initial commit of hf model.
|
|
198
198
|
languages=["eng-Latn"],
|
|
199
199
|
open_weights=True,
|
|
200
|
-
framework=["Sentence Transformers", "PyTorch"],
|
|
200
|
+
framework=["Sentence Transformers", "PyTorch", "ONNX", "safetensors"],
|
|
201
201
|
n_parameters=109_000_000,
|
|
202
202
|
memory_usage_mb=415,
|
|
203
203
|
max_tokens=512,
|
|
@@ -223,7 +223,7 @@ arctic_embed_m_long = ModelMeta(
|
|
|
223
223
|
release_date="2024-04-12", # initial commit of hf model.
|
|
224
224
|
languages=["eng-Latn"],
|
|
225
225
|
open_weights=True,
|
|
226
|
-
framework=["Sentence Transformers", "PyTorch"],
|
|
226
|
+
framework=["Sentence Transformers", "PyTorch", "ONNX", "safetensors"],
|
|
227
227
|
n_parameters=137_000_000,
|
|
228
228
|
memory_usage_mb=522,
|
|
229
229
|
max_tokens=2048,
|
|
@@ -248,7 +248,7 @@ arctic_embed_l = ModelMeta(
|
|
|
248
248
|
release_date="2024-04-12", # initial commit of hf model.
|
|
249
249
|
languages=["eng-Latn"],
|
|
250
250
|
open_weights=True,
|
|
251
|
-
framework=["Sentence Transformers", "PyTorch"],
|
|
251
|
+
framework=["Sentence Transformers", "PyTorch", "ONNX", "safetensors"],
|
|
252
252
|
n_parameters=335_000_000,
|
|
253
253
|
memory_usage_mb=1274,
|
|
254
254
|
max_tokens=512,
|
|
@@ -278,7 +278,7 @@ arctic_embed_m_v1_5 = ModelMeta(
|
|
|
278
278
|
release_date="2024-07-08", # initial commit of hf model.
|
|
279
279
|
languages=["eng-Latn"],
|
|
280
280
|
open_weights=True,
|
|
281
|
-
framework=["Sentence Transformers", "PyTorch"],
|
|
281
|
+
framework=["Sentence Transformers", "PyTorch", "ONNX", "safetensors", "GGUF"],
|
|
282
282
|
n_parameters=109_000_000,
|
|
283
283
|
memory_usage_mb=415,
|
|
284
284
|
max_tokens=512,
|
|
@@ -304,7 +304,7 @@ arctic_embed_m_v2_0 = ModelMeta(
|
|
|
304
304
|
release_date="2024-12-04", # initial commit of hf model.
|
|
305
305
|
languages=LANGUAGES_V2_0,
|
|
306
306
|
open_weights=True,
|
|
307
|
-
framework=["Sentence Transformers", "PyTorch"],
|
|
307
|
+
framework=["Sentence Transformers", "PyTorch", "ONNX", "safetensors"],
|
|
308
308
|
n_parameters=305_000_000,
|
|
309
309
|
memory_usage_mb=1165,
|
|
310
310
|
max_tokens=8192,
|
|
@@ -329,7 +329,7 @@ arctic_embed_l_v2_0 = ModelMeta(
|
|
|
329
329
|
release_date="2024-12-04", # initial commit of hf model.
|
|
330
330
|
languages=LANGUAGES_V2_0,
|
|
331
331
|
open_weights=True,
|
|
332
|
-
framework=["Sentence Transformers", "PyTorch"],
|
|
332
|
+
framework=["Sentence Transformers", "PyTorch", "ONNX", "safetensors"],
|
|
333
333
|
n_parameters=568_000_000,
|
|
334
334
|
memory_usage_mb=2166,
|
|
335
335
|
max_tokens=8192,
|
|
@@ -22,7 +22,7 @@ b1ade_embed = ModelMeta(
|
|
|
22
22
|
max_tokens=4096,
|
|
23
23
|
reference="https://huggingface.co/w601sxs/b1ade-embed",
|
|
24
24
|
similarity_fn_name=ScoringFunction.COSINE,
|
|
25
|
-
framework=["Sentence Transformers", "PyTorch"],
|
|
25
|
+
framework=["Sentence Transformers", "PyTorch", "Transformers", "safetensors"],
|
|
26
26
|
use_instructions=False,
|
|
27
27
|
public_training_code=None,
|
|
28
28
|
public_training_data=None,
|