Views
No views yet
sentence-transformers/all-mpnet-base-v2. This model achieves 73.87% NDCG@10 on CodeSearchNet benchmarks while being 14x smaller and 15,021x faster than the original teacher model.| Language | NDCG@10 | MRR | Recall@5 |
|---|---|---|---|
| Python | 0.7899 | 0.7501 | 0.8421 |
| JavaScript | 0.7234 | 0.6801 | 0.7895 |
| Java | 0.7456 | 0.7089 | 0.8123 |
| PHP | 0.7198 | 0.6856 | 0.7834 |
| Ruby | 0.7312 | 0.6934 | 0.7912 |
| Go | 0.7223 | 0.6876 | 0.7913 |
Note: This is an independent research project that builds upon the Model2Vec framework. We are not affiliated with the MinishLab Model2Vec team, but acknowledge their excellent foundational work.
[!Important] Check out the comprehensive REPORT.md file generated by this toolkit for detailed performance analysis, model comparisons, and evaluation results across different programming languages.
[!Warning] Research Finding: See NOTES.md for critical analysis showing that C4 fine-tuning significantly degraded performance (-16.8% NDCG@10) compared to simple Model2Vec distillation. Recommendation: Use basic distillation without additional training for optimal code embedding performance.
1# Install with all dependencies
2pip install model2vec[train] torch transformers datasets sentence-transformers
3pip install typer pydantic plotly matplotlib seaborn
4
5# Install the distiller package (assuming local development)
6pip install -e .1# Simple distillation of a teacher model
2distiller distill
3
4# Distillation with advanced CodeSearchNet training
5distiller distill --train
6
7# Evaluate distilled models on CodeSearchNet
8distiller evaluate
9
10# Generate comprehensive analysis report
11distiller analyze1from distiller import distill, evaluate, analyze
2
3# Distill a specific model
4results = distill.run_local_distillation(
5 teacher_models=["microsoft/codebert-base"],
6 enable_training=True, # Include CodeSearchNet fine-tuning
7 pca_dims=256
8)
9
10# Evaluate on CodeSearchNet
11evaluation_results = evaluate.run_evaluation(
12 models=["."],
13 max_queries=1000,
14 languages=["python", "javascript", "java", "go", "php", "ruby"]
15)
16
17# Generate analysis report
18analyze.main(
19 results_dir="./code_model2vec/evaluation_results",
20 model_name="code_model2vec_distilled_models",
21 output="ANALYSIS_REPORT.md"
22)microsoft/codebert-base, BAAI/bge-code-v1, Salesforce/SFR-Embedding-Code-2B_Rsentence-transformers/all-mpnet-base-v2, BAAI/bge-m3Alibaba-NLP/gte-Qwen2-1.5B-instructdistiller distill1distiller distill [OPTIONS]
2
3Options:
4 --use-beam Use Beam cloud for distillation
5 --train Enable advanced training (CodeSearchNet fine-tuning)
6 --teacher-models TEXT Specific teacher models to distill (can be repeated)
7 --pca-dims INTEGER PCA dimensions (default: 256)
8 --clear-cache Clear HuggingFace cache for problematic models1# Basic distillation of all default models
2distiller distill
3
4# Train specific models with advanced CodeSearchNet fine-tuning
5distiller distill --train --teacher-models microsoft/codebert-base --teacher-models BAAI/bge-code-v1
6
7# Use Beam cloud with custom PCA dimensions
8distiller distill --use-beam --train --pca-dims 512distiller evaluate1distiller evaluate [OPTIONS]
2
3Options:
4 --use-beam Use Beam cloud for evaluation
5 --skip-third-party Skip third-party models evaluation
6 --skip-benchmark Skip performance benchmarking
7 --max-queries INTEGER Maximum queries per language (default: 100)1# Comprehensive evaluation with benchmarking
2distiller evaluate --max-queries 1000
3
4# Quick evaluation without performance benchmarks
5distiller evaluate --skip-benchmark --max-queries 100
6
7# Cloud-based evaluation
8distiller evaluate --use-beam --max-queries 500distiller analyze1distiller analyze [OPTIONS]
2
3Options:
4 --results-dir PATH Results directory (default: code_model2vec/evaluation_results)
5 --model-name TEXT Model name for analysis (default: gte_qwen2_m2v_code (Ours))
6 --output PATH Output report file (default: REPORT.md)
7 --export-csv PATH Export results to CSV file1# Generate standard analysis report
2distiller analyze
3
4# Custom analysis with CSV export
5distiller analyze --model-name "my_distilled_model" --output custom_report.md --export-csv results.csv
6
7# Analyze specific results directory
8distiller analyze --results-dir ./custom_results --output analysis.mdcode_model2vec/
├── base/ # Basic distilled models (Step 1)
│ └── code_model2vec_{teacher_name}/
├── final/ # Final models (copied from base or after training)
│ └── code_model2vec_{teacher_name}[_fine_tuned]/
├── evaluation_results/ # CodeSearchNet evaluation results
│ └── comprehensive_eval_{model}.json
├── benchmark_results/ # Performance benchmark results
├── analysis_results/ # Analysis reports and charts
│ └── charts/
├── checkpoints/ # Training checkpoints
└── cache/ # Temporary cache filesconfig.py):1TEACHER_MODELS = [
2 "Alibaba-NLP/gte-Qwen2-1.5B-instruct", # Instruction-tuned
3 "BAAI/bge-m3", # Multilingual
4 "jinaai/jina-embeddings-v3", # Modern architecture
5 "microsoft/codebert-base", # Code-specialized
6 "microsoft/graphcodebert-base", # Graph-aware code
7 "sentence-transformers/all-mpnet-base-v2", # General-purpose
8 # ... and more
9]1# Model2Vec distillation settings
2optimal_pca_dims: int = 256
3sif_coefficient: float = 1e-3
4apply_zipf: bool = True
5
6# Tokenlearn training settings (when --train is enabled)
7tokenlearn_dataset: str = "sentence-transformers/codesearchnet"
8tokenlearn_text_key: str = "code" # Use code field for training1# CodeSearchNet evaluation
2evaluation_languages = ["python", "java", "javascript", "php", "ruby", "go"]
3max_queries_per_language: int = 1000
4evaluation_metrics = ["ndcg@1", "ndcg@5", "ndcg@10", "mrr", "recall@1", "recall@5", "recall@10"]