Downloads · 30 days
135
11% of all-time downloads
carlesoctav/multi-qa-en-id-mMiniLMv2-L6-H384
multi-qa-en-id-mMiniLMv2-L6-H384 is a feature extraction model from carlesoctav. Use it when you need embeddings to search or compare text. It is set up for transformers. The card lists the license as apache-2.0.
This model is a fine-tuned version of nreimers/mMiniLMv2-L6-H384-distilled-from-XLMR-Large on the carlesoctav/en-id-parallel-sentences dataset using the following procedure: Making Monolingual Sentence Embeddings Mult…
Downloads · 30 days
135
11% of all-time downloads
All-time downloads
1.3K
Public
Parameters
107M
1.3 GB on disk
Likes
0
Public
Click a slice to open those files.
.h5428 MB · 33%
How the weights are stored.
F32107M · 100%
From the Hugging Face model README
This model is a fine-tuned version of nreimers/mMiniLMv2-L6-H384-distilled-from-XLMR-Large on the carlesoctav/en-id-parallel-sentences dataset using the following procedure: Making Monolingual Sentence Embeddings Multilingual using Knowledge Distillation. It achieves 92% accuracy on the validation split of the dataset for the English-Indonesian language pair in the bitext mining task.
Since we followed the approach outlined in Making Monolingual Sentence Embeddings Multilingual using Knowledge Distillation, we used sentence-transformers/multi-qa-MiniLM-L6-dot-v1 as the teacher model and nreimers/mMiniLMv2-L6-H384-distilled-from-XLMR-Large as the student model (multilingual).
Example of usage:
from transformers import AutoTokenizer, AutoModel
import torch
#CLS Pooling - Take output from first token
def cls_pooling(model_output):
return model_output.last_hidden_state[:,0]
#Encode text
def encode(texts):
# Tokenize sentences
encoded_input = tokenizer(texts, padding=True, truncation=True, return_tensors='pt')
# Compute token embeddings
with torch.no_grad():
model_output = model(**encoded_input, return_dict=True)
# Perform pooling
embeddings = cls_pooling(model_output)
return embeddings
# Sentences we want sentence embeddings for
query = "How many people live in London?"
docs = ["Around 9 Million people live in London", "London is known for its financial district", "sekitar 9 juta orang tinggal di london", " London terkenal sebagai distrik finansial"]
# Load model from HuggingFace Hub
tokenizer = AutoTokenizer.from_pretrained("carlesoctav/multi-qa-en-id-mMiniLMv2-L6-H384")
model = AutoModel.from_pretrained("carlesoctav/multi-qa-en-id-mMiniLMv2-L6-H384", from_tf = True)
#Encode query and docs
query_emb = encode(query)
doc_emb = encode(docs)
#Compute dot score between query and all document embeddings
scores = torch.mm(query_emb, doc_emb.transpose(0, 1))[0].cpu().tolist()
#Combine docs & scores
doc_score_pairs = list(zip(docs, scores))
#Sort by decreasing score
doc_score_pairs = sorted(doc_score_pairs, key=lambda x: x[1], reverse=True)
#Output passages & scores
for doc, score in doc_score_pairs:
print(score, doc)
Take a look at the demo on Google Colab here.
Our model is intended to be used for semantic search. It encodes queries/questions and text paragraphs into dense vectors, allowing it to find relevant documents based on the given passages.
The model is designed to create sentence embeddings specifically for semantic search and information retrieval tasks. As the student model, it inherits this capability from the fine-tuned teacher model. It supports both English and Indonesian languages, making it suitable for cross-lingual information retrieval tasks.
Please note that there is a limit of 256 word pieces, and any text longer than that will be truncated. Additionally, the model was trained using input text up to 80 word pieces, so it may not perform optimally on longer text.
In the following some technical details how this model must be used:
| Setting | Value |
|---|---|
| Dimensions | 384 |
| Produces normalized embeddings | No |
| Pooling-Method | CLS pooling |
| Suitable score functions | dot-product (e.g. util.dot_score) |
We utilized the carlesoctav/en-id-parallel-sentences dataset for training and evaluation purposes. The data was dynamically split into 95% for training and 5% for validation.
The complete training script can be found in the current repository under the name train.py.
The following framework versions were used: