Sentence Embedding difference between DJL Java code and equivalent Python code for Bert model #2895
Replies: 8 comments 8 replies
-
In short I would expect embedding float[] to be 768 for bert base model and 1024 for bert large model. Why is it returning 30522 embedding array. |
Beta Was this translation helpful? Give feedback.
-
Can you share your model_id?
|
Beta Was this translation helpful? Give feedback.
-
This djl://ai.djl.huggingface.pytorch/bert-base-uncased model is NOT an sentence transformers model. This is a fill musk model. The output is logits, a probability for each vocab. |
Beta Was this translation helpful? Give feedback.
-
When we import bert-base-uncased to our model zoo, we use If you want to use base bert model. You can trace the model with |
Beta Was this translation helpful? Give feedback.
-
See this document: https://docs.djl.ai/master/docs/pytorch/how_to_convert_your_model_to_torchscript.html |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
The default implementation in DJL TextEmbeddingTranslatorFactory did an You can disable normalize in DJL to get the same output:
|
Beta Was this translation helpful? Give feedback.
-
DJL and python use the same underly PyTorch native library, the model output should be identical. If the result are different, it can only be we are using different posting processing in the translator. You can always implement your own translator to match the python code. |
Beta Was this translation helpful? Give feedback.
-
I have a following code in python which accepts sentence and computes embedding for the sentence..
This prints torch.size([1,1024])
I'm trying to replicate the same with Java code to get the embedding output with following code..
I see the length printed as Embedding length: 30522 <- which is length of vocab instead of what I see in Python code output.
What am I missing, how do I get average vector of 1024 for the same in Java ?
Im pretty sure there is something simple Im missing.
Beta Was this translation helpful? Give feedback.
All reactions