Halong Embedding is a Vietnamese text embedding focused on RAG and production efficiency:
📚 Trained on a in house dataset consist of approximately 100,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.
This is a
sentence-transformers
model finetuned from
intfloat/multilingual-e5-base
. 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.
You can find eval, fine-tune scripts
here
as well as my
seminar
from sentence_transformers import SentenceTransformer
import torch
# Download from the 🤗 Hub
model = SentenceTransformer("hiieu/halong_embedding")
# Define query and documents
query = "Bóng đá có lợi ích gì cho sức khỏe?"
docs = [
"Bóng đá giúp cải thiện sức khỏe tim mạch và tăng cường sức bền.",
"Bóng đá là môn thể thao phổ biến nhất thế giới.",
"Chơi bóng đá giúp giảm căng thẳng và cải thiện tâm lý.",
"Bóng đá có thể giúp bạn kết nối với nhiều người hơn.",
"Bóng đá không chỉ là môn thể thao mà còn là cách để giải trí."
]
# Encode query and documents
query_embedding = model.encode([query])
doc_embeddings = model.encode(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 scoresfor doc, score inzip(sorted_docs, sorted_scores):
print(f"Document: {doc} - Cosine Similarity: {score:.4f}")
# Document: Bóng đá giúp cải thiện sức khỏe tim mạch và tăng cường sức bền. - Cosine Similarity: 0.7318# Document: Chơi bóng đá giúp giảm căng thẳng và cải thiện tâm lý. - Cosine Similarity: 0.6623# Document: Bóng đá không chỉ là môn thể thao mà còn là cách để giải trí. - Cosine Similarity: 0.6102# Document: Bóng đá có thể giúp bạn kết nối với nhiều người hơn. - Cosine Similarity: 0.4988# Document: Bóng đá là môn thể thao phổ biến nhất thế giới. - Cosine Similarity: 0.4828
Matryoshka Embeddings Inference
from sentence_transformers import SentenceTransformer
import torch.nn.functional as F
import torch
matryoshka_dim = 64
model = SentenceTransformer(
"hiieu/halong_embedding",
truncate_dim=matryoshka_dim,
)
# Define query and documents
query = "Bóng đá có lợi ích gì cho sức khỏe?"
docs = [
"Bóng đá giúp cải thiện sức khỏe tim mạch và tăng cường sức bền.",
"Bóng đá là môn thể thao phổ biến nhất thế giới.",
"Chơi bóng đá giúp giảm căng thẳng và cải thiện tâm lý.",
"Bóng đá có thể giúp bạn kết nối với nhiều người hơn.",
"Bóng đá không chỉ là môn thể thao mà còn là cách để giải trí."
]
# Encode query and documents
query_embedding = model.encode([query])
doc_embeddings = model.encode(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 scoresfor doc, score inzip(sorted_docs, sorted_scores):
print(f"Document: {doc} - Cosine Similarity: {score:.4f}")
# Document: Bóng đá giúp cải thiện sức khỏe tim mạch và tăng cường sức bền. - Cosine Similarity: 0.8045# Document: Chơi bóng đá giúp giảm căng thẳng và cải thiện tâm lý. - Cosine Similarity: 0.7676# Document: Bóng đá không chỉ là môn thể thao mà còn là cách để giải trí. - Cosine Similarity: 0.6758# Document: Bóng đá có thể giúp bạn kết nối với nhiều người hơn. - Cosine Similarity: 0.5931# Document: Bóng đá là môn thể thao phổ biến nhất thế giới. - Cosine Similarity: 0.5105
@misc{HalongEmbedding,
title={HalongEmbedding: A Vietnamese Text Embedding},
author={Ngo Hieu},
year={2024},
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}
}
Runs of contextboxai halong_embedding on huggingface.co
1.7K
Total runs
0
24-hour runs
16
3-day runs
-782
7-day runs
-1.9K
30-day runs
More Information About halong_embedding huggingface.co Model
halong_embedding huggingface.co is an AI model on huggingface.co that provides halong_embedding's model effect (), which can be used instantly with this contextboxai halong_embedding model. huggingface.co supports a free trial of the halong_embedding model, and also provides paid use of the halong_embedding. Support call halong_embedding model through api, including Node.js, Python, http.
halong_embedding huggingface.co is an online trial and call api platform, which integrates halong_embedding's modeling effects, including api services, and provides a free online trial of halong_embedding, you can try halong_embedding online for free by clicking the link below.
contextboxai halong_embedding online free url in huggingface.co:
halong_embedding is an open source model from GitHub that offers a free installation service, and any user can find halong_embedding on GitHub to install. At the same time, huggingface.co provides the effect of halong_embedding install, users can directly use halong_embedding installed effect in huggingface.co for debugging and trial. It also supports api for free installation.