Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: align readme with current mteb #1493

Merged
merged 4 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ from sentence_transformers import SentenceTransformer

# Define the sentence-transformers model name
model_name = "average_word_embeddings_komninos"
# or directly from huggingface:
# model_name = "sentence-transformers/all-MiniLM-L6-v2"

model = SentenceTransformer(model_name)
model = mteb.get_model(model_name) # if the model is not implemented in MTEB it will be eq. to SentenceTransformer(model_name)
tasks = mteb.get_tasks(tasks=["Banking77Classification"])
evaluation = mteb.MTEB(tasks=tasks)
results = evaluation.run(model, output_folder=f"results/{model_name}")
Expand Down Expand Up @@ -220,7 +218,10 @@ Note that the public leaderboard uses the test splits for all datasets except MS
Models should implement the following interface, implementing an `encode` function taking as inputs a list of sentences, and returning a list of embeddings (embeddings can be `np.array`, `torch.tensor`, etc.). For inspiration, you can look at the [mteb/mtebscripts repo](https://github.com/embeddings-benchmark/mtebscripts) used for running diverse models via SLURM scripts for the paper.

```python
import mteb
from mteb.encoder_interface import PromptType
import numpy as np


class CustomModel:
def encode(
Expand All @@ -244,7 +245,7 @@ class CustomModel:
pass

model = CustomModel()
tasks = mteb.get_task("Banking77Classification")
tasks = mteb.get_tasks(tasks=["Banking77Classification"])
evaluation = MTEB(tasks=tasks)
evaluation.run(model)
```
Expand Down
5 changes: 2 additions & 3 deletions mteb/evaluation/MTEB.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from typing import Any

import datasets
from sentence_transformers import SentenceTransformer
from sentence_transformers import CrossEncoder, SentenceTransformer

from mteb.encoder_interface import Encoder
from mteb.model_meta import ModelMeta
Expand All @@ -23,7 +23,6 @@
from ..abstasks import AbsTask
from ..load_results.task_results import TaskResult
from ..models.sentence_transformer_wrapper import SentenceTransformerWrapper
from ..models.wrapper import Wrapper
from ..tasks import *
from . import LangMapping

Expand Down Expand Up @@ -363,7 +362,7 @@ def run(

meta = self.create_model_meta(model)
output_path = self.create_output_folder(meta, output_folder)
if not isinstance(model, Wrapper):
if isinstance(model, (SentenceTransformer, CrossEncoder)):
model = SentenceTransformerWrapper(model)

if output_path:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_benchmark/mock_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def encode(self, sentences, prompt_name: str | None = None, **kwargs):
return torch.randn(len(sentences), 10).numpy()


class MockTorchbf16Encoder(mteb.Encoder):
class MockTorchbf16Encoder(SentenceTransformer):
def __init__(self):
pass

Expand Down