Instructions to use sentence-transformers/all-MiniLM-L12-v2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use sentence-transformers/all-MiniLM-L12-v2 with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("sentence-transformers/all-MiniLM-L12-v2") sentences = [ "That is a happy person", "That is a happy dog", "That is a very happy person", "Today is a sunny day" ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [4, 4] - Transformers
How to use sentence-transformers/all-MiniLM-L12-v2 with Transformers:
# Load model directly from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("sentence-transformers/all-MiniLM-L12-v2") model = AutoModel.from_pretrained("sentence-transformers/all-MiniLM-L12-v2") - Inference
- Notebooks
- Google Colab
- Kaggle
Different Input Lengths
Can anyone describe the difference between max_pos_embeddings=512(config.json) , max_seq_length=128(sentence_bert_config.json), model_max_length=512(tokenizer_config.json).
Also how can I set these values by using langchain.
Hello!
The 512 values are defined by the MiniLM base model, whereas 128 is the maximum sequence length that was used when finetuning the model to be an embedding model. As a result, 128 is the recommended maximum sequence length (after which you'll get much worse embeddings), and 512 is the maximum sequence length after which the model will simply crash.
I'm not sure how to set these values in LangChain.
- Tom Aarsen