-
Notifications
You must be signed in to change notification settings - Fork 298
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
[v2] add similarity_fn in ModelMeta #1759
base: v2.0.0
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, I really appreciate your suggestions, but I’m not sure if we should rely on the ModelMeta
object for anything during evaluation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added 2 comments as I see that this is meant to be partially complete at this time.
Co-authored-by: Isaac Chung <[email protected]>
6d04547
to
e4a692f
Compare
I made some additional changes, so the PR ended up being a bit larger than originally planned. Please take a look at what I’ve done and share your feedback—I’m looking forward to hearing your thoughts! @Samoed @isaac-chung Just a heads-up, there’s one failing test: #1777. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This currently doesn’t fix the issues with the similarity function, as it focuses only on the retrieval model wrapper. I think the changes should be made in get_model
. The model name and revision can be used there, and the type of similarity function can be passed to the loader.
Lines 156 to 157 in c3b46b7
meta = get_model_meta(model_name, revision) | |
model = meta.load_model(**kwargs) |
Also ModelMeta
can be changed to separate loader
and additional loader_kwargs
Yes, you're correct about the changes. Did you notice these changes? I’m using the st similarity function names and map them to the Enum. |
No, I missed, thanks! But still I think this should be changed to not duplicate |
I am note quite sure of the context of this PR. It would great with a short explanation of what the PR is trying to solve. Below are some questions to help getting that process started.
Can't see where this happens? Why do we want this?
We generally havenøt used enum's anywhere else in the repo. Any strong reason to introduce it over the literal?
Hmm, but why do we need a get_similarity function in the first place? The interface specified that the model should specify the similarity function. Is there anything that I am missing here?
What issue?
I agree. I don't like this as well. However that is quite a large overhaul. We could consider reformatting models similar to tasks (so that we have a model where we can call |
Ok, I'll create separate PR for updating work with |
Currently, when passing a model, the old way MTEB creates two folders with missing model name and revision. This happens because a type check in
This might be a subjective preference, but using an Enum reduces the code size and, in my opinion, makes it easier to work with when implementing a new model, as it provides type suggestions from the IDE. I also believe it makes development in other parts of the project much easier, as the available types are clearly defined and suggested by the IDE.
The
The BM25 function call does not match the defined |
Maybe good to outline it in an issue first before you spend a lot of time on the refactor |
Not sure what you mean here. What is model in this case? When I run: import mteb
task = mteb.get_task("BornholmBitextMining")
model = mteb.get_model("sentence-transformers/all-MiniLM-L6-v2")
bench = mteb.MTEB(tasks=[task])
bench.run(model) # only created one folder I do not get two folders.
I understand where you are coming from. I think this is a more general change across the repo and not one that should happen just here. I would suggest that we stick with Literals as this will be a breaking change so no reason to add it unless we have a strong reason to. However do open an issue on Literals vs. Enums (most IDEs, e.g. vscode also allow suggestions when using literals).
But why not use the mteb/mteb/encoder_interface.py Line 71 in 0c5c3a5
This is modelled after sentence-transformers and freely allow the model to implement their own similarity function. Why is there a reason to fetch it? |
Thanks for the clarification. For future PRs it would make it easier for the reviewer if what it intends to solve is specified in the first comment (it seems like this was discussed elsewhere, in which case do link to it). Besides the Enums (which is being discussed in #1784) I believe this is ready to merge as soon as tests pass. |
This PR originally had a completely different scope, so you're absolutely correct—it ended up getting quite tangled with multiple different PRs and issues addressing the same topic. My apologies for the confusion. Only #1777 is failing, but that's expected |
That's fixed in the latest commit in main. Feel free to copy that small commit over. |
* skip AfriSentiLID for now * skip relevant test case instead --------- Co-authored-by: Isaac Chung <[email protected]>
There seems to be a conflict. @sam-hey if you resolve this remove the Enum part we can merge this in. This is not at all a hard decision on Enums, but I think with two major merges coming up, this will cause a lot of conflicts (cc. @Samoed, @gowitheflow-1998). We can still do the transition after the merge (outlined in #1784). |
@KennethEnevoldsen, what do you think about merging it in its current state? I’ve kept the Enum but reverted the changes in all the models. Personally, I think this is a good compromise. Backward compatibility is fully maintained. |
Model loading test has been fixed here in main as well: #1775 |
@isaac-chung I've merged your updates to |
All |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, last changes! Maybe apply here pytest.importskip
instead of pytest.mark.skip
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm totally here to improve my coding, so I really appreciate a thorough review, even if it means I have to redo parts! @Samoed, thanks for the feedback!
And you're absolutely right it is not so nice —pytest.importskip
doesn't exist, as far as I can tell. However, pytest.importorskip
is a similar function, but it’s not a marker.
We could go with something like this, or even write a custom decorator:
try:
import pylate # noqa
except ImportError:
pylate_installed = False
@pytest.mark.skipif(not pylate_installed, reason="PyLate not installed")
https://docs.pytest.org/en/7.1.x/reference/reference.html#pytest-importorskip
pytest-dev/pytest#9548
https://stackoverflow.com/questions/73750328/make-pytest-ignore-gathering-a-file-if-a-module-is-not-installed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I meaned importorskip
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you reviewed the documentation and the related issue? You can find it here: pytest-dev/pytest#9548.
https://docs.pytest.org/en/7.1.x/reference/reference.html#pytest-importorskip
Using importorskip
will work, but only if we split each component into its own file, which isn't very practical.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use it inside test function
Checklist
Run tests locally to make sure nothing is broken using
make test
.Run the formatter to format the code using
make lint
.fix: Retrieve
name
andrevision
from SentenceTransformers metadata.mv: Move the
get_similarity_function
method toModelMeta
.fix: Resolve issues with
bm25s
.feat: Add a
max_similarity
function toutils.py
.feat: Map and load SentenceTransformers similarity functions to MTEB similarity functions.
ref: Changed
max_sim
toMaxSim
to align with thepylate
implementation ofsimilarity_fn_name
Update similarity_fn_name = 'cosine' to MaxSim lightonai/pylate#77