Support for older sentence-transformers?

#9
by thecodder123 - opened

My project currently uses sentence transformers 2.2.2, due to compatibility issues with instructor models. Is there a way to get this model to work with 2.2.2? I am running into this error:

No such file or directory: '.../.cache/torch/sentence_transformers/Snowflake_snowflake-arctic-embed-l-v2.0/sentence_xlnet_config.json'

../../.PythonRuntime/conda_envs/.../lib/python3.10/site-packages/sentence_transformers/models/Transformer.py:135: FileNotFoundError

Upon manually adding the sentence_bert_config.json, i am getting E TypeError: Pooling.init() got an unexpected keyword argument 'pooling_mode_weightedmean_tokens'

Hello!

Definitely, it should be able to get it working. On your local clone/your cloned repository, you already added the sentence_bert_config.json - good!

The next step is to remove the last few keys from the 1_Pooling/config.json. For example, you'll get:

{
  "word_embedding_dimension": 1024,
  "pooling_mode_cls_token": true,
  "pooling_mode_mean_tokens": false,
  "pooling_mode_max_tokens": false
}

For the inference, you can't use prompt or prompt_name in model.encode, so you'll have to pretend the query prompt manually for all queries, just like how it's done in the Transformers snippet.

Beyond that, my recommendation is to compare the embeddings of a specific text from your modified model to the model loaded in e.g. Google Colab where you have a higher version installed automatically. The embeddings should match.

  • Tom Aarsen

Hello!

Definitely, it should be able to get it working. On your local clone/your cloned repository, you already added the sentence_bert_config.json - good!

The next step is to remove the last few keys from the 1_Pooling/config.json. For example, you'll get:

{
  "word_embedding_dimension": 1024,
  "pooling_mode_cls_token": true,
  "pooling_mode_mean_tokens": false,
  "pooling_mode_max_tokens": false
}

For the inference, you can't use prompt or prompt_name in model.encode, so you'll have to pretend the query prompt manually for all queries, just like how it's done in the Transformers snippet.

Beyond that, my recommendation is to compare the embeddings of a specific text from your modified model to the model loaded in e.g. Google Colab where you have a higher version installed automatically. The embeddings should match.

  • Tom Aarsen

Hey Tom! Thanks for the quick reply! That worked. 1 last question. The older version of sentence transformer does not support the truncate_dim parameter which is used for MRL. Will taking the output of the encoding and then slicing the vector to the required dimension be equivalent?

Yes, that's exactly equivalent. You might have to renormalize the final vector, but that's it :)

Your need to confirm your account before you can post a new comment.

Sign up or log in to comment