Feature Extraction
Safetensors
Model2Vec
sentence-transformers
code
distiller
code-search
code-embeddings
distillation
static-embeddings
tokenlearn
Run this model with HF Jobs
Run sarthak1/codemalt on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/sarthak1/codemalt. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/sarthak1/codemalt on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use sarthak1/codemalt with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Model2Vec
How to use sarthak1/codemalt with Model2Vec:
from model2vec import StaticModel model = StaticModel.from_pretrained("sarthak1/codemalt") embeddings = model.encode(["It's dangerous to go alone!", "It's a secret to everybody."]) print(embeddings.shape) - sentence-transformers
How to use sarthak1/codemalt with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("sarthak1/codemalt") sentences = [ "The weather is lovely today.", "It's so sunny outside!", "He drove to the stadium." ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [3, 3] - Notebooks
- Google Colab
- Kaggle
Sarthak commited on
Commit ·
4a1942c
1
Parent(s): ecfceb8
docs: Enhance README.md with detailed project information for gte-Qwen2-7B-instruct-M2V-Distilled, including model optimization benefits, installation instructions, usage examples, and performance results.
Browse files123---license: apache-2.0---123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146---base_model: Alibaba-NLP/gte-Qwen2-7B-instructlibrary_name: model2veclicense: apache-2.0license_name: apache-2.0license_link: LICENSEmodel_name: gte-Qwen2-7B-instruct-M2V-Distilledtags:- sentence-transformers- sentence-similarity- feature-extraction- transformers- Qwen2---# gte-Qwen2-7B-instruct-M2V-DistilledThis project optimizes the gte-Qwen2-7B-instruct model using Model2Vec, reducing its size and dramatically improving inference speed while maintaining most of its performance capabilities.## Overview[gte-Qwen2-7B-instruct](https://huggingface.co/Alibaba-NLP/gte-Qwen2-7B-instruct) is a state-of-the-art embedding model designed for retrieval tasks. While powerful, it can be resource-intensive for production use cases.[Model2Vec](https://github.com/MinishLab/model2vec) is a technique to distill large sentence transformer models into small, fast static embedding models. This project applies Model2Vec to create an optimized version of gte-Qwen2-7B-instruct with the following benefits:- **Smaller Size**: Reduces model size by a factor of 180x- **Faster Inference**: Up to 15,021x faster inference- **Low Resource Requirements**: Minimal memory footprint and dependencies- **Maintains Performance**: Retains 86.56% of the original model's embedding similarity## Model Information- **Model Name**: gte-Qwen2-7B-instruct-M2V-Distilled- **Original Model**: [gte-Qwen2-7B-instruct](https://huggingface.co/Alibaba-NLP/gte-Qwen2-7B-instruct)- **Distillation Method**: [Model2Vec](https://github.com/MinishLab/model2vec)- **Original Dimensions**: 3584- **Distilled Dimensions**: 256- **Embedding Similarity**: 86.56% maintained with original model- **Size Reduction**: 180x (from 28.7GB to 158.98MB)- **Speed Improvement**: 15,021x faster (0.50 → 7,549 texts/second)## InstallationFirst, ensure you have the required dependencies:```bash# Install the base packageuv sync```## Usage### DistillationTo create a distilled version of Alibaba-NLP/gte-Qwen2-7B-instruct:```bashuv run python distill.py```### EvaluationTo evaluate the distilled model against the original:```bashuv run python evaluate.py```### Training Code ClassificationTo train a programming language classifier using the distilled model on the CodeSearchNet dataset:```bashuv run python train_code_classification.py```This script:- Uses the [CodeSearchNet dataset](https://github.com/github/CodeSearchNet) for training- Trains a classifier to distinguish between 6 programming languages: Python, Java, JavaScript, Go, PHP, and Ruby- Creates a `StaticModelForClassification` using the distilled model- Evaluates the classifier and saves the trained model.**Dataset Details:**- **Source**: `code-search-net/code_search_net` from HuggingFace- **Task**: Programming language classification- **Languages**: Python, Java, JavaScript, Go, PHP, Ruby- **Max samples per language**: 5,000 (for balanced training)- **Code length range**: 50-2,000 characters- **Features**: Function code strings with language labels**Training Configuration:**- **Max epochs**: 30 with early stopping (patience: 5)- **Batch size**: 32- **Learning rate**: 1e-3- **Output**: Scikit-learn compatible pipeline saved to the root dir## ResultsThe distilled model achieves remarkable performance improvements:- **180x reduction in model size** (from 28.7GB to 158.98MB)- **15,021x increase in inference speed** (0.50 → 7,549 texts/second)- **86.56% embedding similarity** maintained with the original model- **14x dimensional reduction** (3584 → 256 dimensions)- **Significant memory efficiency** with minimal resource requirements### Performance Visualizations#### Model Size Comparison*Dramatic reduction in model size from 28.7GB to 158.98MB*#### Inference Speed Comparison*15,021x faster inference speed: from 0.50 to 7,549 texts per second*#### Memory Usage Comparison*Significant reduction in memory footprint during inference*#### Embedding Similarity Analysis*High correlation (86.56%) between original and distilled model embeddings*Detailed evaluation results, including similarity plots and performance metrics, are saved to the evaluation output directory.## Project Structure- `distill.py` - Script to create the distilled model- `evaluate.py` - Script to compare performance with the original model- `train_code_classification.py` - Script to train programming language classifier- `MTEB_evaluate.py` - Script to evaluate model on MTEB benchmark tasks- `evaluation/` - Directory containing evaluation results and visualizations- `trained_code_classifier/` - Directory containing trained classification model- `mteb_results/` - Directory containing MTEB evaluation results## AcknowledgmentsThis project is built upon the following technologies:- [gte-Qwen2-7B-instruct](https://huggingface.co/Alibaba-NLP/gte-Qwen2-7B-instruct) - The original embedding model developed by Alibaba-NLP- [Model2Vec](https://github.com/MinishLab/model2vec) - The distillation technique used to optimize the model## LicenseThis model is licensed under the [Apache 2.0](LICENSE) license, the same as the original gte-Qwen2-7B-instruct model.
README.md+143