-
Notifications
You must be signed in to change notification settings - Fork 786
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
[Question] distiluse-base-multilingual-cased-v2 - wrong vector dimension (768 vs 512) in onnx version? #230
Comments
Here's the model architecture according to their README:
It would appear as though they store the final "dense" layer in a separate folder (https://huggingface.co/sentence-transformers/distiluse-base-multilingual-cased-v2/tree/main/2_Dense) and the ONNX model you're loading was only converted from the pytorch_model.bin in the root directory. If you try using the HF transformers python library (not sbert), you should also get 768 dimensions, simply because it doesn't know of the existence of the final dense layer. Regarding a way to fix it, you could perhaps convert the dense layer to ONNX, then use another |
Thanks for your answer! You're right with from transformers import AutoModel, AutoTokenizer
import torch
model_name = "sentence-transformers/distiluse-base-multilingual-cased-v2"
model = AutoModel.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
inputs = tokenizer("Hello, my dog is cute", return_tensors="pt")
outputs = model(**inputs)
sentence_embedding = outputs[0][0][0]
len(sentence_embedding)
#768 or simply from transformers import pipeline
pipe = pipeline('feature-extraction', model= "sentence-transformers/distiluse-base-multilingual-cased-v2")
out = pipe('I love transformers!')
len(out[0][0])
#768 where the first tensor ([CLS]) should be the sentence embedding (afaik) according to the BERT paper (right?). I suppose the dense layer in the sentence transformer models serves only for shortening the tensors and saving memory. It's certainly a nice banana skin to slip over. :D Are you aware of any way to add the dense layer to the Also (for anyone reading this in the future), I am not aware of any parameter to ignore the dense layer in sentence transformer models. |
Maybe @fxmarty or @michaelbenayoun can help with this? It most likely will require some custom config. |
I was just playing around with the model distiluse-base-multilingual-cased-v2 and noticed that your onnx versions both (quantized and normal) produce embeddings with 768-dimensional vectors instead of 512.
Example:
index.html
main.js
That gives me
However, the model page states
Also, I used the Python package
which gives me a correct 512-dimensional embedding.
Am I missing some option here or overseeing the obvious?
The text was updated successfully, but these errors were encountered: