binhdinh-embedding

This is a sentence-transformers model finetuned from bkai-foundation-models/vietnamese-bi-encoder on the json dataset. It maps sentences & paragraphs to a 768-dimensional dense vector space and can be used for semantic textual similarity, semantic search, paraphrase mining, text classification, clustering, and more.

  • 📚 Trained on a in house dataset consist of approximately 120,000 examples of question and related documents
  • 🪆 Trained with a Matryoshka loss, allowing you to truncate embeddings with minimal performance loss: smaller embeddings are faster to compare.

Model Details

Model Description

  • Model Type: Sentence Transformer
  • Base model: bkai-foundation-models/vietnamese-bi-encoder
  • Maximum Sequence Length: 256 tokens
  • Output Dimensionality: 768 dimensions
  • Similarity Function: Cosine Similarity
  • Language: VietNamese
  • License: apache-2.0

Model Sources

Full Model Architecture

SentenceTransformer(
  (0): Transformer({'max_seq_length': 256, 'do_lower_case': False, 'architecture': 'RobertaModel'})
  (1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False, 'pooling_mode_weightedmean_tokens': False, 'pooling_mode_lasttoken': False, 'include_prompt': True})
)

Usage

Direct Usage (Sentence Transformers)

First install the Sentence Transformers library:

pip install -U sentence-transformers

Then you can load this model and run inference.

from sentence_transformers import SentenceTransformer
import torch
from pyvi import ViTokenizer

# Download from the 🤗 Hub
model = SentenceTransformer("minhthuan77f1/binhdinh-embedding")

# Define query and documents
query = "Người lao động có quyền đơn phương chấm dứt hợp đồng lao động khi nào?"

docs = [
    "Người lao động có quyền đơn phương chấm dứt hợp đồng lao động nhưng phải báo trước cho người sử dụng lao động theo thời hạn luật định.",
    "Người lao động có thể nghỉ việc không cần báo trước nếu không được trả lương đầy đủ hoặc bị ngược đãi, quấy rối.",
    "Thời hạn báo trước khi đơn phương chấm dứt hợp đồng lao động thường là 30 hoặc 45 ngày tùy loại hợp đồng.",
    "Người lao động làm việc theo hợp đồng xác định thời hạn có quyền đơn phương chấm dứt trước thời hạn theo quy định pháp luật.",
    "Sau khi chấm dứt hợp đồng lao động hợp pháp, người lao động được thanh toán lương và các quyền lợi liên quan."
]

# Tokenization
segmented_query = ViTokenizer.tokenize(query)
segmented_docs = [ViTokenizer.tokenize(doc) for doc in docs]

# Encode query and documents
query_embedding = model.encode([segmented_query])
doc_embeddings = model.encode(segmented_docs)
similarities = model.similarity(query_embedding, doc_embeddings).flatten()

# Sort documents by cosine similarity
sorted_indices = torch.argsort(similarities, descending=True)
sorted_docs = [docs[idx] for idx in sorted_indices]
sorted_scores = [similarities[idx].item() for idx in sorted_indices]

# Print sorted documents with their cosine scores
for doc, score in zip(sorted_docs, sorted_scores):
    print(f"Document: {doc} - Cosine Similarity: {score:.4f}")

# Document: Người lao động có quyền đơn phương chấm dứt hợp đồng lao động nhưng phải báo trước cho người sử dụng lao động theo thời hạn luật định. - Cosine Similarity: 0.9128       
# Document: Người lao động làm việc theo hợp đồng xác định thời hạn có quyền đơn phương chấm dứt trước thời hạn theo quy định pháp luật. - Cosine Similarity: 0.7447
# Document: Sau khi chấm dứt hợp đồng lao động hợp pháp, người lao động được thanh toán lương và các quyền lợi liên quan. - Cosine Similarity: 0.6812
# Document: Thời hạn báo trước khi đơn phương chấm dứt hợp đồng lao động thường là 30 hoặc 45 ngày tùy loại hợp đồng. - Cosine Similarity: 0.6243
# Document: Người lao động có thể nghỉ việc không cần báo trước nếu không được trả lương đầy đủ hoặc bị ngược đãi, quấy rối. - Cosine Similarity: 0.3723

Evaluation

Metrics

Information Retrieval

Model Accuracy@1 Accuracy@3 Accuracy@5 Accuracy@10 Precision@1 Precision@3 Precision@5 Precision@10 Recall@1 Recall@3 Recall@5 Recall@10 NDCG@10 MRR@10 MAP@100
binhdinh-embedding 0.7425 0.8928 0.9268 0.9585 0.7425 0.2976 0.1853 0.0958 0.7425 0.8928 0.9268 0.9585 0.8559 0.8224 0.8239
AITeamVN/Vietnamese_Embedding 0.7323 0.8920 0.9248 0.9581 0.7323 0.2973 0.1849 0.0958 0.7323 0.8920 0.9248 0.9581 0.8525 0.8178 0.8193
bkai-foundation-models/vietnamese-bi-encoder 0.6874 0.8513 0.8896 0.9307 0.6874 0.2837 0.1779 0.0930 0.6874 0.8513 0.8896 0.9307 0.8138 0.7758 0.7783
halong_embedding 0.5586 0.7331 0.7969 0.8591 0.5586 0.2443 0.1593 0.0859 0.5586 0.7331 0.7969 0.8591 0.7080 0.6596 0.6646
sup-SimCSE-VietNamese-phobert-base 0.4405 0.6240 0.6987 0.7715 0.4405 0.2080 0.1397 0.0771 0.4405 0.6240 0.6987 0.7715 0.6021 0.5482 0.5547

Citation

You can cite our work as below:

@misc{BinhDinhEmbedding,
  title={BinhDinhEmbedding: A Vietnamese Text Embedding},
  author={Minh Thuan},
  year={2026},
  publisher={Huggingface},
}

BibTeX

Sentence Transformers

@inproceedings{reimers-2019-sentence-bert,
    title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
    author = "Reimers, Nils and Gurevych, Iryna",
    booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
    month = "11",
    year = "2019",
    publisher = "Association for Computational Linguistics",
    url = "https://arxiv.org/abs/1908.10084",
}

MatryoshkaLoss

@misc{kusupati2024matryoshka,
    title={Matryoshka Representation Learning},
    author={Aditya Kusupati and Gantavya Bhatt and Aniket Rege and Matthew Wallingford and Aditya Sinha and Vivek Ramanujan and William Howard-Snyder and Kaifeng Chen and Sham Kakade and Prateek Jain and Ali Farhadi},
    year={2024},
    eprint={2205.13147},
    archivePrefix={arXiv},
    primaryClass={cs.LG}
}

MultipleNegativesRankingLoss

@misc{henderson2017efficient,
    title={Efficient Natural Language Response Suggestion for Smart Reply},
    author={Matthew Henderson and Rami Al-Rfou and Brian Strope and Yun-hsuan Sung and Laszlo Lukacs and Ruiqi Guo and Sanjiv Kumar and Balint Miklos and Ray Kurzweil},
    year={2017},
    eprint={1705.00652},
    archivePrefix={arXiv},
    primaryClass={cs.CL}
}
Downloads last month
98
Safetensors
Model size
0.1B params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for minhthuan77f1/binhdinh-embedding

Finetuned
(50)
this model

Papers for minhthuan77f1/binhdinh-embedding

Evaluation results