mteb 2.5.3__py3-none-any.whl → 2.5.4__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.
Files changed (102) hide show
  1. mteb/_create_dataloaders.py +10 -15
  2. mteb/_evaluators/any_sts_evaluator.py +1 -4
  3. mteb/_evaluators/evaluator.py +2 -1
  4. mteb/_evaluators/image/imagetext_pairclassification_evaluator.py +5 -6
  5. mteb/_evaluators/pair_classification_evaluator.py +3 -1
  6. mteb/_evaluators/retrieval_metrics.py +17 -16
  7. mteb/_evaluators/sklearn_evaluator.py +9 -8
  8. mteb/_evaluators/text/bitext_mining_evaluator.py +23 -16
  9. mteb/_evaluators/text/summarization_evaluator.py +20 -16
  10. mteb/abstasks/_data_filter/filters.py +1 -1
  11. mteb/abstasks/_data_filter/task_pipelines.py +3 -0
  12. mteb/abstasks/_statistics_calculation.py +18 -10
  13. mteb/abstasks/_stratification.py +18 -18
  14. mteb/abstasks/abstask.py +27 -21
  15. mteb/abstasks/aggregate_task_metadata.py +1 -9
  16. mteb/abstasks/aggregated_task.py +3 -16
  17. mteb/abstasks/classification.py +10 -4
  18. mteb/abstasks/clustering.py +18 -14
  19. mteb/abstasks/clustering_legacy.py +8 -8
  20. mteb/abstasks/image/image_text_pair_classification.py +5 -3
  21. mteb/abstasks/multilabel_classification.py +20 -16
  22. mteb/abstasks/pair_classification.py +18 -9
  23. mteb/abstasks/regression.py +3 -3
  24. mteb/abstasks/retrieval.py +12 -9
  25. mteb/abstasks/sts.py +6 -3
  26. mteb/abstasks/task_metadata.py +20 -16
  27. mteb/abstasks/text/bitext_mining.py +36 -25
  28. mteb/abstasks/text/reranking.py +7 -5
  29. mteb/abstasks/text/summarization.py +8 -3
  30. mteb/abstasks/zeroshot_classification.py +5 -2
  31. mteb/benchmarks/benchmark.py +2 -2
  32. mteb/cache.py +20 -18
  33. mteb/cli/_display_tasks.py +2 -2
  34. mteb/cli/build_cli.py +5 -5
  35. mteb/cli/generate_model_card.py +6 -4
  36. mteb/deprecated_evaluator.py +56 -43
  37. mteb/evaluate.py +35 -29
  38. mteb/filter_tasks.py +25 -26
  39. mteb/get_tasks.py +25 -27
  40. mteb/languages/language_scripts.py +5 -3
  41. mteb/leaderboard/app.py +1 -1
  42. mteb/load_results.py +12 -12
  43. mteb/models/abs_encoder.py +2 -2
  44. mteb/models/cache_wrappers/cache_backend_protocol.py +3 -5
  45. mteb/models/cache_wrappers/cache_backends/_hash_utils.py +5 -4
  46. mteb/models/cache_wrappers/cache_backends/faiss_cache.py +2 -1
  47. mteb/models/cache_wrappers/cache_backends/numpy_cache.py +30 -13
  48. mteb/models/cache_wrappers/cache_wrapper.py +2 -2
  49. mteb/models/get_model_meta.py +8 -1
  50. mteb/models/instruct_wrapper.py +11 -5
  51. mteb/models/model_implementations/andersborges.py +2 -2
  52. mteb/models/model_implementations/blip_models.py +8 -8
  53. mteb/models/model_implementations/bm25.py +1 -1
  54. mteb/models/model_implementations/clip_models.py +3 -3
  55. mteb/models/model_implementations/cohere_models.py +1 -1
  56. mteb/models/model_implementations/cohere_v.py +2 -2
  57. mteb/models/model_implementations/dino_models.py +23 -23
  58. mteb/models/model_implementations/emillykkejensen_models.py +3 -3
  59. mteb/models/model_implementations/jina_clip.py +1 -1
  60. mteb/models/model_implementations/jina_models.py +1 -1
  61. mteb/models/model_implementations/kennethenevoldsen_models.py +2 -2
  62. mteb/models/model_implementations/llm2clip_models.py +3 -3
  63. mteb/models/model_implementations/moco_models.py +2 -2
  64. mteb/models/model_implementations/model2vec_models.py +1 -1
  65. mteb/models/model_implementations/nomic_models.py +8 -8
  66. mteb/models/model_implementations/openclip_models.py +7 -7
  67. mteb/models/model_implementations/random_baseline.py +3 -3
  68. mteb/models/model_implementations/rasgaard_models.py +1 -1
  69. mteb/models/model_implementations/repllama_models.py +2 -2
  70. mteb/models/model_implementations/rerankers_custom.py +3 -3
  71. mteb/models/model_implementations/rerankers_monot5_based.py +3 -3
  72. mteb/models/model_implementations/siglip_models.py +10 -10
  73. mteb/models/model_implementations/vlm2vec_models.py +1 -1
  74. mteb/models/model_implementations/voyage_v.py +4 -4
  75. mteb/models/model_meta.py +11 -12
  76. mteb/models/search_encoder_index/search_indexes/faiss_search_index.py +5 -5
  77. mteb/models/search_wrappers.py +22 -10
  78. mteb/models/sentence_transformer_wrapper.py +9 -4
  79. mteb/py.typed +0 -0
  80. mteb/results/benchmark_results.py +25 -19
  81. mteb/results/model_result.py +49 -21
  82. mteb/results/task_result.py +45 -51
  83. mteb/similarity_functions.py +11 -7
  84. mteb/tasks/classification/dan/dk_hate_classification.py +1 -1
  85. mteb/tasks/classification/est/estonian_valence.py +1 -1
  86. mteb/tasks/classification/multilingual/scala_classification.py +1 -1
  87. mteb/tasks/image_text_pair_classification/eng/sugar_crepe.py +1 -1
  88. mteb/tasks/retrieval/code/code_rag.py +12 -12
  89. mteb/tasks/retrieval/dan/dan_fever_retrieval.py +1 -1
  90. mteb/tasks/retrieval/dan/tv2_nordretrieval.py +2 -2
  91. mteb/tasks/retrieval/dan/twitter_hjerne_retrieval.py +2 -2
  92. mteb/tasks/retrieval/nob/norquad.py +2 -2
  93. mteb/tasks/retrieval/nob/snl_retrieval.py +2 -2
  94. mteb/tasks/retrieval/tur/tur_hist_quad.py +1 -1
  95. mteb/types/_result.py +2 -1
  96. mteb/types/statistics.py +9 -3
  97. {mteb-2.5.3.dist-info → mteb-2.5.4.dist-info}/METADATA +1 -1
  98. {mteb-2.5.3.dist-info → mteb-2.5.4.dist-info}/RECORD +102 -101
  99. {mteb-2.5.3.dist-info → mteb-2.5.4.dist-info}/WHEEL +0 -0
  100. {mteb-2.5.3.dist-info → mteb-2.5.4.dist-info}/entry_points.txt +0 -0
  101. {mteb-2.5.3.dist-info → mteb-2.5.4.dist-info}/licenses/LICENSE +0 -0
  102. {mteb-2.5.3.dist-info → mteb-2.5.4.dist-info}/top_level.txt +0 -0
mteb/get_tasks.py CHANGED
@@ -4,7 +4,7 @@ import difflib
4
4
  import logging
5
5
  import warnings
6
6
  from collections import Counter, defaultdict
7
- from collections.abc import Sequence
7
+ from collections.abc import Iterable, Sequence
8
8
  from typing import Any
9
9
 
10
10
  import pandas as pd
@@ -23,12 +23,11 @@ logger = logging.getLogger(__name__)
23
23
  def _gather_tasks() -> tuple[type[AbsTask], ...]:
24
24
  import mteb.tasks as tasks
25
25
 
26
- tasks = [
26
+ return tuple(
27
27
  t
28
28
  for t in tasks.__dict__.values()
29
29
  if isinstance(t, type) and issubclass(t, AbsTask)
30
- ]
31
- return tuple(tasks)
30
+ )
32
31
 
33
32
 
34
33
  def _create_name_to_task_mapping(
@@ -44,7 +43,7 @@ def _create_name_to_task_mapping(
44
43
  return metadata_names
45
44
 
46
45
 
47
- def _create_similar_tasks(tasks: Sequence[type[AbsTask]]) -> dict[str, list[str]]:
46
+ def _create_similar_tasks(tasks: Iterable[type[AbsTask]]) -> dict[str, list[str]]:
48
47
  """Create a dictionary of similar tasks.
49
48
 
50
49
  Returns:
@@ -195,9 +194,8 @@ class MTEBTasks(tuple[AbsTask]):
195
194
  string with a LaTeX table.
196
195
  """
197
196
  if include_citation_in_name and "name" in properties:
198
- properties += ["intext_citation"]
199
- df = self.to_dataframe(properties)
200
- df["name"] = df["name"] + " " + df["intext_citation"]
197
+ df = self.to_dataframe(tuple(properties) + ("intext_citation",))
198
+ df["name"] = df["name"] + " " + df["intext_citation"] # type: ignore[operator]
201
199
  df = df.drop(columns=["intext_citation"])
202
200
  else:
203
201
  df = self.to_dataframe(properties)
@@ -222,17 +220,17 @@ class MTEBTasks(tuple[AbsTask]):
222
220
 
223
221
 
224
222
  def get_tasks(
225
- tasks: list[str] | None = None,
223
+ tasks: Sequence[str] | None = None,
226
224
  *,
227
- languages: list[str] | None = None,
228
- script: list[str] | None = None,
229
- domains: list[TaskDomain] | None = None,
230
- task_types: list[TaskType] | None = None, # type: ignore
231
- categories: list[TaskCategory] | None = None,
225
+ languages: Sequence[str] | None = None,
226
+ script: Sequence[str] | None = None,
227
+ domains: Sequence[TaskDomain] | None = None,
228
+ task_types: Sequence[TaskType] | None = None,
229
+ categories: Sequence[TaskCategory] | None = None,
232
230
  exclude_superseded: bool = True,
233
- eval_splits: list[str] | None = None,
231
+ eval_splits: Sequence[str] | None = None,
234
232
  exclusive_language_filter: bool = False,
235
- modalities: list[Modalities] | None = None,
233
+ modalities: Sequence[Modalities] | None = None,
236
234
  exclusive_modality_filter: bool = False,
237
235
  exclude_aggregate: bool = False,
238
236
  exclude_private: bool = True,
@@ -288,7 +286,7 @@ def get_tasks(
288
286
  ]
289
287
  return MTEBTasks(_tasks)
290
288
 
291
- _tasks = filter_tasks(
289
+ tasks_: Sequence[type[AbsTask]] = filter_tasks(
292
290
  TASK_LIST,
293
291
  languages=languages,
294
292
  script=script,
@@ -301,12 +299,12 @@ def get_tasks(
301
299
  exclude_aggregate=exclude_aggregate,
302
300
  exclude_private=exclude_private,
303
301
  )
304
- _tasks = [
305
- cls().filter_languages(languages, script).filter_eval_splits(eval_splits)
306
- for cls in _tasks
307
- ]
308
-
309
- return MTEBTasks(_tasks)
302
+ return MTEBTasks(
303
+ [
304
+ cls().filter_languages(languages, script).filter_eval_splits(eval_splits)
305
+ for cls in tasks_
306
+ ]
307
+ )
310
308
 
311
309
 
312
310
  _TASK_RENAMES = {"PersianTextTone": "SynPerTextToneClassification"}
@@ -314,10 +312,10 @@ _TASK_RENAMES = {"PersianTextTone": "SynPerTextToneClassification"}
314
312
 
315
313
  def get_task(
316
314
  task_name: str,
317
- languages: list[str] | None = None,
318
- script: list[str] | None = None,
319
- eval_splits: list[str] | None = None,
320
- hf_subsets: list[str] | None = None,
315
+ languages: Sequence[str] | None = None,
316
+ script: Sequence[str] | None = None,
317
+ eval_splits: Sequence[str] | None = None,
318
+ hf_subsets: Sequence[str] | None = None,
321
319
  exclusive_language_filter: bool = False,
322
320
  ) -> AbsTask:
323
321
  """Get a task by name.
@@ -1,9 +1,9 @@
1
- from collections.abc import Iterable
1
+ from collections.abc import Iterable, Sequence
2
2
  from dataclasses import dataclass
3
3
 
4
4
  from typing_extensions import Self
5
5
 
6
- from mteb.languages import check_language_code
6
+ from mteb.languages.check_language_code import check_language_code
7
7
 
8
8
 
9
9
  @dataclass
@@ -25,7 +25,9 @@ class LanguageScripts:
25
25
 
26
26
  @classmethod
27
27
  def from_languages_and_scripts(
28
- cls, languages: list[str] | None = None, scripts: list[str] | None = None
28
+ cls,
29
+ languages: Sequence[str] | None = None,
30
+ scripts: Sequence[str] | None = None,
29
31
  ) -> Self:
30
32
  """Create a LanguageScripts object from lists of languages and scripts.
31
33
 
mteb/leaderboard/app.py CHANGED
@@ -169,7 +169,7 @@ def _update_task_info(task_names: str) -> gr.DataFrame:
169
169
  df = df.drop(columns="reference")
170
170
  return gr.DataFrame(
171
171
  df,
172
- datatype=["markdown"] + ["str"] * (len(df.columns) - 1), # type: ignore
172
+ datatype=["markdown"] + ["str"] * (len(df.columns) - 1),
173
173
  buttons=["copy", "fullscreen"],
174
174
  show_search="filter",
175
175
  )
mteb/load_results.py CHANGED
@@ -1,7 +1,7 @@
1
1
  import json
2
2
  import logging
3
3
  import sys
4
- from collections.abc import Sequence
4
+ from collections.abc import Iterable, Sequence
5
5
  from pathlib import Path
6
6
 
7
7
  from mteb.abstasks.abstask import AbsTask
@@ -45,8 +45,8 @@ def _model_name_and_revision(
45
45
  def load_results(
46
46
  results_repo: str = "https://github.com/embeddings-benchmark/results",
47
47
  download_latest: bool = True,
48
- models: Sequence[ModelMeta] | Sequence[str] | None = None,
49
- tasks: Sequence[AbsTask] | Sequence[str] | None = None,
48
+ models: Iterable[ModelMeta] | Sequence[str] | None = None,
49
+ tasks: Iterable[AbsTask] | Sequence[str] | None = None,
50
50
  validate_and_filter: bool = True,
51
51
  require_model_meta: bool = True,
52
52
  only_main_score: bool = False,
@@ -83,21 +83,21 @@ def load_results(
83
83
 
84
84
  if models is not None:
85
85
  models_to_keep = {}
86
- for model_path in models:
87
- if isinstance(model_path, ModelMeta):
88
- models_to_keep[model_path.name] = model_path.revision
86
+ for model in models:
87
+ if isinstance(model, ModelMeta):
88
+ models_to_keep[model.name] = model.revision
89
89
  else:
90
- models_to_keep[model_path] = None
90
+ models_to_keep[model] = None
91
91
  else:
92
92
  models_to_keep = None
93
93
 
94
- task_names = {}
94
+ task_names: dict[str, AbsTask | None] = {}
95
95
  if tasks is not None:
96
- for task in tasks:
97
- if isinstance(task, AbsTask):
98
- task_names[task.metadata.name] = task
96
+ for task_ in tasks:
97
+ if isinstance(task_, AbsTask):
98
+ task_names[task_.metadata.name] = task_
99
99
  else:
100
- task_names[task] = None
100
+ task_names[task_] = None
101
101
 
102
102
  model_results = []
103
103
  for model_path in model_paths:
@@ -44,7 +44,7 @@ class AbsEncoder(ABC):
44
44
  model: Any
45
45
  mteb_model_meta: ModelMeta | None = None
46
46
  model_prompts: dict[str, str] | None = None
47
- instruction_template: str | Callable[[str, PromptType], str] | None = None
47
+ instruction_template: str | Callable[[str, PromptType | None], str] | None = None
48
48
  prompts_dict: dict[str, str] | None = None
49
49
 
50
50
  def get_prompt_name(
@@ -111,7 +111,7 @@ class AbsEncoder(ABC):
111
111
  if not self.model_prompts:
112
112
  return None
113
113
  prompt_name = self.get_prompt_name(task_metadata, prompt_type)
114
- return self.model_prompts.get(prompt_name)
114
+ return self.model_prompts.get(prompt_name) if prompt_name else None
115
115
 
116
116
  @staticmethod
117
117
  @overload
@@ -5,8 +5,6 @@ from typing import Any, Protocol, runtime_checkable
5
5
 
6
6
  import numpy as np
7
7
 
8
- from mteb.types import BatchedInput
9
-
10
8
 
11
9
  @runtime_checkable
12
10
  class CacheBackendProtocol(Protocol):
@@ -26,7 +24,7 @@ class CacheBackendProtocol(Protocol):
26
24
  **kwargs: Additional backend-specific arguments.
27
25
  """
28
26
 
29
- def add(self, item: list[BatchedInput], vectors: np.ndarray) -> None:
27
+ def add(self, item: list[dict[str, Any]], vectors: np.ndarray) -> None:
30
28
  """Add a vector to the cache.
31
29
 
32
30
  Args:
@@ -34,7 +32,7 @@ class CacheBackendProtocol(Protocol):
34
32
  vectors: Embedding vector of shape (dim,) or (1, dim).
35
33
  """
36
34
 
37
- def get_vector(self, item: BatchedInput) -> np.ndarray | None:
35
+ def get_vector(self, item: dict[str, Any]) -> np.ndarray | None:
38
36
  """Retrieve the cached vector for the given item.
39
37
 
40
38
  Args:
@@ -53,5 +51,5 @@ class CacheBackendProtocol(Protocol):
53
51
  def close(self) -> None:
54
52
  """Release resources or flush data."""
55
53
 
56
- def __contains__(self, item: BatchedInput) -> bool:
54
+ def __contains__(self, item: dict[str, Any]) -> bool:
57
55
  """Check whether the cache contains an item."""
@@ -1,12 +1,13 @@
1
1
  import hashlib
2
+ from collections.abc import Mapping
3
+ from typing import Any
2
4
 
3
- from mteb.types import BatchedInput
4
5
 
5
-
6
- def _hash_item(item: BatchedInput) -> str:
6
+ def _hash_item(item: Mapping[str, Any]) -> str:
7
7
  item_hash = ""
8
8
  if "text" in item:
9
- item_hash = hashlib.sha256(item["text"].encode()).hexdigest()
9
+ item_text: str = item["text"]
10
+ item_hash = hashlib.sha256(item_text.encode()).hexdigest()
10
11
 
11
12
  if "image" in item:
12
13
  from PIL import Image
@@ -2,6 +2,7 @@ import json
2
2
  import logging
3
3
  import warnings
4
4
  from pathlib import Path
5
+ from typing import Any
5
6
 
6
7
  import numpy as np
7
8
 
@@ -37,7 +38,7 @@ class FaissCache:
37
38
  logger.info(f"Initialized FAISS VectorCacheMap in {self.directory}")
38
39
  self.load()
39
40
 
40
- def add(self, items: list[BatchedInput], vectors: np.ndarray) -> None:
41
+ def add(self, items: list[dict[str, Any]], vectors: np.ndarray) -> None:
41
42
  """Add vector to FAISS index."""
42
43
  import faiss
43
44
 
@@ -2,11 +2,10 @@ import json
2
2
  import logging
3
3
  import warnings
4
4
  from pathlib import Path
5
+ from typing import Any
5
6
 
6
7
  import numpy as np
7
8
 
8
- from mteb.types import BatchedInput
9
-
10
9
  from ._hash_utils import _hash_item
11
10
 
12
11
  logger = logging.getLogger(__name__)
@@ -15,7 +14,7 @@ logger = logging.getLogger(__name__)
15
14
  class NumpyCache:
16
15
  """Generic vector cache for both text and images."""
17
16
 
18
- def __init__(self, directory: str | Path, initial_vectors: int = 100000):
17
+ def __init__(self, directory: str | Path, initial_vectors: int = 100_000):
19
18
  self.directory = Path(directory)
20
19
  self.directory.mkdir(parents=True, exist_ok=True)
21
20
  self.vectors_file = self.directory / "vectors.npy"
@@ -28,7 +27,7 @@ class NumpyCache:
28
27
  logger.info(f"Initialized VectorCacheMap in directory: {self.directory}")
29
28
  self._initialize_vectors_file()
30
29
 
31
- def add(self, item: list[BatchedInput], vectors: np.ndarray) -> None:
30
+ def add(self, items: list[dict[str, Any]], vectors: np.ndarray) -> None:
32
31
  """Add a vector to the cache."""
33
32
  try:
34
33
  if self.vector_dim is None:
@@ -39,7 +38,12 @@ class NumpyCache:
39
38
  self._save_dimension()
40
39
  logger.info(f"Initialized vector dimension to {self.vector_dim}")
41
40
 
42
- for item, vec in zip(item, vectors):
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):
43
47
  item_hash = _hash_item(item)
44
48
  if item_hash in self.hash_to_index:
45
49
  msg = f"Hash collision or duplicate item for hash {item_hash}. Overwriting existing vector."
@@ -75,18 +79,26 @@ class NumpyCache:
75
79
  shape=(self.initial_vectors, self.vector_dim),
76
80
  )
77
81
  else:
78
- self.vectors = np.memmap(self.vectors_file, dtype="float32", mode="r+")
79
- self.vectors = self.vectors.reshape(-1, self.vector_dim)
82
+ self.vectors = np.memmap(
83
+ self.vectors_file,
84
+ dtype="float32",
85
+ mode="r+",
86
+ shape=(-1, self.vector_dim),
87
+ )
80
88
  logger.info(f"Vectors file initialized with shape: {self.vectors.shape}")
81
89
 
82
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
+ )
83
95
  current_size = len(self.vectors)
84
96
  new_size = current_size * 2
85
97
  logger.info(f"Doubling vectors file from {current_size} to {new_size} vectors")
86
98
  self.vectors.flush()
87
99
  new_vectors = np.memmap(
88
- self.vectors_file,
89
- dtype="float32",
100
+ str(self.vectors_file),
101
+ dtype=np.float32,
90
102
  mode="r+",
91
103
  shape=(new_size, self.vector_dim),
92
104
  )
@@ -147,9 +159,11 @@ class NumpyCache:
147
159
 
148
160
  if self.vector_dim is not None:
149
161
  self.vectors = np.memmap(
150
- self.vectors_file, dtype="float32", mode="r+"
162
+ self.vectors_file,
163
+ dtype="float32",
164
+ mode="r+",
165
+ shape=(-1, self.vector_dim),
151
166
  )
152
- self.vectors = self.vectors.reshape(-1, self.vector_dim)
153
167
  logger.info(f"Loaded vectors file with shape: {self.vectors.shape}")
154
168
  else:
155
169
  msg = "Vector dimension not set. Unable to load vectors file."
@@ -164,8 +178,11 @@ class NumpyCache:
164
178
  logger.error(f"Error loading VectorCacheMap: {str(e)}")
165
179
  raise
166
180
 
167
- def get_vector(self, item: BatchedInput) -> np.ndarray | None:
181
+ def get_vector(self, item: dict[str, Any]) -> np.ndarray | None:
168
182
  """Retrieve vector from index by hash."""
183
+ if self.vectors is None:
184
+ return None
185
+
169
186
  try:
170
187
  item_hash = _hash_item(item)
171
188
  if item_hash not in self.hash_to_index:
@@ -177,7 +194,7 @@ class NumpyCache:
177
194
  logger.error(f"Error retrieving vector for item: {str(e)}")
178
195
  raise
179
196
 
180
- def __contains__(self, item: BatchedInput) -> bool:
197
+ def __contains__(self, item: dict[str, Any]) -> bool:
181
198
  return _hash_item(item) in self.hash_to_index
182
199
 
183
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[BatchedInput] = []
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):
@@ -93,7 +93,14 @@ def get_model(
93
93
  meta = get_model_meta(model_name, revision)
94
94
  model = meta.load_model(**kwargs)
95
95
 
96
- model.mteb_model_meta = meta # type: ignore
96
+ if kwargs:
97
+ logger.info(
98
+ f"Model '{model_name}' loaded with additional arguments: {list(kwargs.keys())}"
99
+ )
100
+ meta = meta.model_copy(deep=True)
101
+ meta.loader_kwargs |= kwargs
102
+
103
+ model.mteb_model_meta = meta # type: ignore[misc]
97
104
  return model
98
105
 
99
106
 
@@ -17,7 +17,7 @@ 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
21
  **kwargs,
22
22
  ):
23
23
  """Instruct wrapper for models. Uses GritLM to pass instructions to the model.
@@ -40,7 +40,9 @@ def instruct_wrapper(
40
40
  self,
41
41
  model_name_or_path: str,
42
42
  mode: str,
43
- instruction_template: str | Callable[[str, PromptType], str] | None = None,
43
+ instruction_template: str
44
+ | Callable[[str, PromptType | None], str]
45
+ | None = None,
44
46
  **kwargs,
45
47
  ):
46
48
  if (
@@ -82,8 +84,11 @@ def instruct_wrapper(
82
84
  logger.info(
83
85
  f"Using instruction: '{instruction}' for task: '{task_metadata.name}'"
84
86
  )
85
- embeddings = super().encode(
86
- _inputs, instruction=instruction, *args, **kwargs
87
+ embeddings = super().encode( # type: ignore[safe-super]
88
+ _inputs, # type: ignore[arg-type]
89
+ instruction=instruction,
90
+ *args,
91
+ **kwargs,
87
92
  )
88
93
  if isinstance(embeddings, torch.Tensor):
89
94
  # sometimes in kwargs can be return_tensors=True
@@ -141,7 +146,7 @@ class InstructSentenceTransformerModel(AbsEncoder):
141
146
  )
142
147
 
143
148
  self.instruction_template = instruction_template
144
- tokenizer_params = {}
149
+ tokenizer_params: dict[str, Any] = {}
145
150
  if add_eos_token:
146
151
  tokenizer_params["add_eos_token"] = add_eos_token
147
152
  if max_seq_length is not None:
@@ -193,6 +198,7 @@ class InstructSentenceTransformerModel(AbsEncoder):
193
198
  The encoded input in a numpy array or torch tensor of the shape (Number of sentences) x (Embedding dimension).
194
199
  """
195
200
  sentences = [text for batch in inputs for text in batch["text"]]
201
+ instruction: str | None
196
202
  instruction = self.get_task_instruction(task_metadata, prompt_type)
197
203
 
198
204
  # to passage prompts won't be applied to passages
@@ -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, # type: ignore
7
+ loader=Model2VecModel,
8
8
  name="andersborges/model2vecdk",
9
9
  model_type=["dense"],
10
10
  languages=["dan-Latn"],
@@ -35,7 +35,7 @@ model2vecdk = ModelMeta(
35
35
 
36
36
 
37
37
  model2vecdk_stem = ModelMeta(
38
- loader=Model2VecModel, # type: ignore
38
+ loader=Model2VecModel,
39
39
  name="andersborges/model2vecdk-stem",
40
40
  model_type=["dense"],
41
41
  languages=["dan-Latn"],
@@ -128,7 +128,7 @@ class BLIPModel(AbsEncoder):
128
128
 
129
129
  # in descending order of usage (downloads from huggingface)
130
130
  blip_image_captioning_large = ModelMeta(
131
- loader=BLIPModel, # type: ignore
131
+ loader=BLIPModel,
132
132
  name="Salesforce/blip-image-captioning-large",
133
133
  model_type=["dense"],
134
134
  languages=["eng-Latn"],
@@ -156,7 +156,7 @@ blip_image_captioning_large = ModelMeta(
156
156
  )
157
157
 
158
158
  blip_image_captioning_base = ModelMeta(
159
- loader=BLIPModel, # type: ignore
159
+ loader=BLIPModel,
160
160
  name="Salesforce/blip-image-captioning-base",
161
161
  model_type=["dense"],
162
162
  languages=["eng-Latn"],
@@ -185,7 +185,7 @@ blip_image_captioning_base = ModelMeta(
185
185
 
186
186
 
187
187
  blip_vqa_base = ModelMeta(
188
- loader=BLIPModel, # type: ignore
188
+ loader=BLIPModel,
189
189
  name="Salesforce/blip-vqa-base",
190
190
  model_type=["dense"],
191
191
  languages=["eng-Latn"],
@@ -212,7 +212,7 @@ blip_vqa_base = ModelMeta(
212
212
  )
213
213
 
214
214
  blip_vqa_capfilt_large = ModelMeta(
215
- loader=BLIPModel, # type: ignore
215
+ loader=BLIPModel,
216
216
  name="Salesforce/blip-vqa-capfilt-large",
217
217
  model_type=["dense"],
218
218
  languages=["eng-Latn"],
@@ -239,7 +239,7 @@ blip_vqa_capfilt_large = ModelMeta(
239
239
  )
240
240
 
241
241
  blip_itm_base_coco = ModelMeta(
242
- loader=BLIPModel, # type: ignore
242
+ loader=BLIPModel,
243
243
  name="Salesforce/blip-itm-base-coco",
244
244
  model_type=["dense"],
245
245
  languages=["eng-Latn"],
@@ -266,7 +266,7 @@ blip_itm_base_coco = ModelMeta(
266
266
  )
267
267
 
268
268
  blip_itm_large_coco = ModelMeta(
269
- loader=BLIPModel, # type: ignore
269
+ loader=BLIPModel,
270
270
  name="Salesforce/blip-itm-large-coco",
271
271
  model_type=["dense"],
272
272
  languages=["eng-Latn"],
@@ -294,7 +294,7 @@ blip_itm_large_coco = ModelMeta(
294
294
  )
295
295
 
296
296
  blip_itm_base_flickr = ModelMeta(
297
- loader=BLIPModel, # type: ignore
297
+ loader=BLIPModel,
298
298
  name="Salesforce/blip-itm-base-flickr",
299
299
  model_type=["dense"],
300
300
  languages=["eng-Latn"],
@@ -322,7 +322,7 @@ blip_itm_base_flickr = ModelMeta(
322
322
  )
323
323
 
324
324
  blip_itm_large_flickr = ModelMeta(
325
- loader=BLIPModel, # type: ignore
325
+ loader=BLIPModel,
326
326
  name="Salesforce/blip-itm-large-flickr",
327
327
  model_type=["dense"],
328
328
  languages=["eng-Latn"],
@@ -113,7 +113,7 @@ def bm25_loader(model_name, **kwargs) -> SearchProtocol:
113
113
 
114
114
  def encode(self, texts: list[str]):
115
115
  """Encode input text as term vectors"""
116
- return bm25s.tokenize(texts, stopwords=self.stopwords, stemmer=self.stemmer) # type: ignore
116
+ return bm25s.tokenize(texts, stopwords=self.stopwords, stemmer=self.stemmer)
117
117
 
118
118
  return BM25Search(**kwargs)
119
119
 
@@ -115,7 +115,7 @@ CLIP_CITATION = """
115
115
 
116
116
 
117
117
  clip_vit_large_patch14 = ModelMeta(
118
- loader=CLIPModel, # type: ignore
118
+ loader=CLIPModel,
119
119
  name="openai/clip-vit-large-patch14",
120
120
  model_type=["dense"],
121
121
  languages=["eng-Latn"],
@@ -139,7 +139,7 @@ clip_vit_large_patch14 = ModelMeta(
139
139
  )
140
140
 
141
141
  clip_vit_base_patch32 = ModelMeta(
142
- loader=CLIPModel, # type: ignore
142
+ loader=CLIPModel,
143
143
  name="openai/clip-vit-base-patch32",
144
144
  model_type=["dense"],
145
145
  languages=["eng-Latn"],
@@ -163,7 +163,7 @@ clip_vit_base_patch32 = ModelMeta(
163
163
  )
164
164
 
165
165
  clip_vit_base_patch16 = ModelMeta(
166
- loader=CLIPModel, # type: ignore
166
+ loader=CLIPModel,
167
167
  name="openai/clip-vit-base-patch16",
168
168
  model_type=["dense"],
169
169
  languages=["eng-Latn"],
@@ -222,7 +222,7 @@ class CohereTextEmbeddingModel(AbsEncoder):
222
222
  ) -> None:
223
223
  requires_package(self, "cohere", model_name, "pip install 'mteb[cohere]'")
224
224
 
225
- import cohere # type: ignore
225
+ import cohere
226
226
 
227
227
  self.model_name = model_name.removeprefix("Cohere/Cohere-")
228
228
  self.sep = sep
@@ -378,7 +378,7 @@ def cohere_v_loader(model_name, **kwargs):
378
378
 
379
379
 
380
380
  cohere_mult_3 = ModelMeta(
381
- loader=cohere_v_loader, # type: ignore
381
+ loader=cohere_v_loader,
382
382
  loader_kwargs={"model_name": "embed-multilingual-v3.0"},
383
383
  name="cohere/embed-multilingual-v3.0",
384
384
  model_type=["dense"],
@@ -402,7 +402,7 @@ cohere_mult_3 = ModelMeta(
402
402
  )
403
403
 
404
404
  cohere_eng_3 = ModelMeta(
405
- loader=cohere_v_loader, # type: ignore
405
+ loader=cohere_v_loader,
406
406
  loader_kwargs={"model_name": "embed-english-v3.0"},
407
407
  name="cohere/embed-english-v3.0",
408
408
  model_type=["dense"],