🚀 multi-qa_v1-MiniLM-L6-cls_dot
SentenceTransformers is a set of models and frameworks for training and generating sentence embeddings, which can be used for tasks like Clustering and Semantic Search.
🚀 Quick Start
This model can be used as a sentence encoder for search engines. Given an input sentence, it outputs a vector capturing the sentence's semantic information, which can be used for semantic search, clustering, or sentence similarity tasks.
✨ Features
- Sentence Embedding Generation: Capable of generating sentence embeddings from given data.
- Robust to Q&A Similarity: Trained with question and answer pairs from StackExchange to be robust to Question / Answer embedding similarity.
- Specific Output and Similarity Calculation: Uses cls output as sentence embeddings and dot product to calculate similarity for the learning objective.
📦 Installation
To use this model, you need to install the SentenceTransformers library. You can install it using the following command:
pip install sentence-transformers
💻 Usage Examples
Basic Usage
from sentence_transformers import SentenceTransformer
model = SentenceTransformer('flax-sentence-embeddings/multi-qa_v1-MiniLM-L6-cls_dot')
text = "Replace me by any question / answer you'd like."
text_embbedding = model.encode(text)
📚 Documentation
Model Description
SentenceTransformers is a set of models and frameworks that enable training and generating sentence embeddings from given data. The generated sentence embeddings can be utilized for Clustering, Semantic Search and other tasks. We used a pretrained nreimers/MiniLM-L6-H384-uncased model and trained it using Siamese Network setup and contrastive learning objective. Question and answer pairs from StackExchange was used as training data to make the model robust to Question / Answer embedding similarity. For this model, cls output was used instead of mean pooling as sentence embeddings. Dot product was used to calculate similarity for learning objective.
We developed this model during the
Community week using JAX/Flax for NLP & CV,
organized by Hugging Face. We developed this model as part of the project:
Train the Best Sentence Embedding Model Ever with 1B Training Pairs. We benefited from efficient hardware infrastructure to run the project: 7 TPUs v3-8, as well
as assistance from Google’s Flax, JAX, and Cloud team members about efficient deep learning frameworks.
Intended uses
Our model is intended to be used as a sentence encoder for a search engine. Given an input sentence, it outputs a vector which captures
the sentence semantic information. The sentence vector may be used for semantic-search, clustering or sentence similarity tasks.
🔧 Technical Details
Training procedure
Pre-training
We use the pretrained nreimers/MiniLM-L6-H384-uncased. Please refer to the model
card for more detailed information about the pre-training procedure.
Fine-tuning
We fine-tune the model using a contrastive objective. Formally, we compute the cosine similarity from each possible sentence pairs from the batch.
We then apply the cross entropy loss by comparing with true pairs.
Hyper parameters
We trained on model on a TPU v3-8. We train the model during 80k steps using a batch size of 1024 (128 per TPU core).
We use a learning rate warm up of 500. The sequence length was limited to 128 tokens. We used the AdamW optimizer with
a 2e-5 learning rate. The full training script is accessible in this current repository.
Training data
We used the concatenation from multiple Stackexchange Question-Answer datasets to fine-tune our model. MSMARCO, NQ & other question-answer datasets were also used.
Property |
Details |
Model Type |
Sentence encoder for search engines |
Training Data |
Concatenation of multiple Stackexchange Question-Answer datasets, MSMARCO, NQ, and other question-answer datasets |
Dataset |
Paper |
Number of training tuples |
Stack Exchange QA - Title & Answer |
- |
4,750,619 |
Stack Exchange |
- |
364,001 |
TriviaqQA |
- |
73,346 |
SQuAD2.0 |
paper |
87,599 |
Quora Question Pairs |
- |
103,663 |
Eli5 |
paper |
325,475 |
PAQ |
paper |
64,371,441 |
WikiAnswers |
paper |
77,427,422 |
MS MARCO |
paper |
9,144,553 |
GOOAQ: Open Question Answering with Diverse Answer Types |
paper |
3,012,496 |
Yahoo Answers Question/Answer |
paper |
681,164 |
SearchQA |
- |
582,261 |
Natural Questions (NQ) |
paper |
100,231 |