Model2Vec क्या है?
Model2Vec किसी भी sentence transformer को छोटे, तेज़ static embedding model में डिस्टिल करें. यह Retrieval & Knowledge (RAG) टूल्स की Embedding Models & Inference श्रेणी में आता है; ओपन सोर्स है और Python में लिखा गया है। शुरू करने के लिए: base package इंस्टॉल करें.
सारांश
Model2Vec एक Python library है जो किसी नियमित sentence transformer को छोटे, स्टैटिक embedding model में बदलती है। हर input के लिए neural network चलाने के बजाय, static model पहले से गणना किए गए token embeddings देखता है, जिससे वह कहीं छोटा और तेज़ हो जाता है और ज़्यादातर quality बनी रहती है। मेंटेनर्स के अनुसार आकार में 50x तक कमी और गति में 500x तक तेज़ी आती है, और performance में थोड़ी गिरावट होती है।
यह उन developers के लिए है जिन्हें text embeddings चाहिए, लेकिन जो उन्हें पूरे transformer के overhead के बिना CPU पर चलाना चाहते हैं। आप Hugging Face hub के तैयार Potion models इस्तेमाल कर सकते हैं, या किसी sentence transformer से अपना static model CPU पर लगभग 30 सेकंड में distill कर सकते हैं।
एक embedding model tool के रूप में यह text classification, retrieval, clustering और RAG systems बनाने जैसे कामों में फिट बैठता है। इससे बने embeddings standard vectors हैं, जिन्हें आप इनमें से किसी भी pipeline में डाल सकते हैं।
यह क्या करता है
- Hugging Face hub से सीधे पहले से प्रशिक्षित Potion static models लोड करता है, जो तुरंत इस्तेमाल के लिए तैयार हैं
- किसी भी sentence transformer से अपना static model CPU पर लगभग 30 सेकंड में distill करता है
- Inference के समय neural network के बिना CPU पर चलता है, इसलिए embeddings छोटे और तेज़ होते हैं
- encode और encode_as_sequence के ज़रिए pooled embeddings और per-token embedding sequences, दोनों बनाता है
- वैकल्पिक training extra से आप distill किए गए या पहले से प्रशिक्षित model पर classification models को fine-tune कर सकते हैं
- BPE और Unigram tokenizer backends सपोर्ट करता है, साथ ही models को और छोटा करने के लिए quantization और dimensionality reduction भी
शुरू करें
पहले base package इंस्टॉल करें, फिर एक Potion model लोड करके embeddings बनाएं। अगर आप अपना static model बनाना चाहते हैं, तो distillation extra इंस्टॉल करें।
Base package इंस्टॉल करें
pip से हल्का base package इंस्टॉल करें।
pip install model2vecModel लोड करें और embeddings बनाएं
Hugging Face hub से एक पहले से प्रशिक्षित Potion model लोड करें और कुछ text को encode करें।
from model2vec import StaticModel
# Load a model from the HuggingFace hub (in this case the potion-base-32M model)
model = StaticModel.from_pretrained("minishlab/potion-base-32M")
# Make embeddings
embeddings = model.encode(["It's dangerous to go alone!", "It's a secret to everybody."])
# Make sequences of token embeddings
token_embeddings = model.encode_as_sequence(["It's dangerous to go alone!", "It's a secret to everybody."])अपना model distill करें (वैकल्पिक)
Distillation extra इंस्टॉल करें, फिर किसी sentence transformer से CPU पर लगभग 30 सेकंड में एक static model distill करें।
pip install model2vec[distill]Distillation चलाएं
एक sentence transformer को distill करें और परिणामी static model को सेव करें।
from model2vec.distill import distill
# Distill a Sentence Transformer model, in this case the BAAI/bge-base-en-v1.5 model
m2v_model = distill(model_name="BAAI/bge-base-en-v1.5")
# Save the model
m2v_model.save_pretrained("m2v_model")कमांड और कोड प्रोजेक्ट के अपने दस्तावेज़ों से लिए गए हैं — हमेशा जांचें आधिकारिक repo ताज़ा जानकारी के लिए।
कब इस्तेमाल करें
- Full transformer होस्ट किए बिना retrieval या RAG pipeline में तेज़, केवल-CPU text embeddings जोड़ें
- मौजूदा sentence transformer को resource-constrained या edge deployments के लिए छोटे static model में बदलें
- उच्च throughput पर text classification और clustering के लिए vectors बनाएं
- पहले से प्रशिक्षित potion-multilingual-128M model से multilingual text को embed करें
How Model2Vec compares
Model2Vec alongside other open-source embedding models & inference tools AI/TLDR tracks, ranked by GitHub stars.
| टूल | स्टार | यह क्या करता है |
|---|---|---|
| Sentence Transformers | ★ 19.3k | Python में टेक्स्ट embeddings की गणना करें, उन्हें प्रशिक्षित करें और rerank करें |
| OpenCLIP | ★ 14.3k | image-text embeddings को ट्रेन और चलाने के लिए CLIP का ओपन इम्प्लीमेंटेशन |
| PyTorch Metric Learning | ★ 6.3k | PyTorch में embedding मॉडल ट्रेनिंग के लिए losses, miners और testers |
| EmbeddingGemma (Gemma) | ★ 5.9k | 308M मल्टीलिंगुअल एम्बेडिंग मॉडल, जो on-device चलने जितना छोटा है |
| Text Embeddings Inference (TEI) | ★ 5.2k | तेज़ HTTP API के ज़रिए ओपन सोर्स embedding और reranking मॉडल सर्व करें |
| text2vec | ★ 5k | चीनी या बहुभाषी टेक्स्ट को sentence embeddings में बदलें, ट्रेनिंग कोड के साथ |
| Infinity (Embeddings) | ★ 3k | एम्बेडिंग, रीरैंकर, CLIP और ColPali मॉडल चलाने के लिए हाई-थ्रूपुट REST API |
| Model2Vec | ★ 2.3k | किसी भी sentence transformer को छोटे, तेज़ static embedding model में डिस्टिल करें |

