Run this model with HF Jobs
Run divakantpandey/code-embed 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/divakantpandey/code-embed. 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/divakantpandey/code-embed 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 divakantpandey/code-embed with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use divakantpandey/code-embed with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("divakantpandey/code-embed") 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
π» code-embed
π CodeEmbed v2 is now live! Check out for 6-language multilingual code search and official MTEB leaderboard rankings:
- Rank #3 Worldwide on Code-to-Code Reranking ()
- Rank #3 Worldwide on (β€150M category)
- Rank #8 Worldwide on (β€150M category)
- Rank #9 Worldwide on (β€150M category)
CodeEmbed is a lightweight, high-performance code embedding model (β€130M parameters) developed by Divakant Pandey. Specialized for semantic code search, code retrieval, and repository navigation with 8,192 token context and Matryoshka representation learning.
π Key Features
- Author / Maintainer: Divakant Pandey
- Backbone: UniXcoder bi-encoder architecture with a 2-layer MLP projection head and unit-sphere L2 normalization.
- 3-Stage Curriculum:
- SimCSE Unsupervised Contrastive Learning (uniformity on hypersphere).
- Supervised Fine-Tuning (MNRL with BM25 lexical hard negatives).
- Matryoshka Representation Learning (MRL) (nested dimensions: 64, 128, 256, 384, 768, 1536).
- Fast CPU Inference: ~20.8 ms per code snippet on standard laptop CPU.
- Production-Ready: Exportable to ONNX with dynamic axes and dynamic INT8 quantization.
π Benchmark Results
| Benchmark | Metric | Value | Gate Status |
|---|---|---|---|
| CodeSearchNet (Python) | MRR@10 | 0.7514 | PASS (β₯ 0.65) |
| CoSQA (Code Search QA) | MRR@10 | 0.7509 | PASS (β₯ 0.50) |
| Hypersphere Uniformity | Uniformity | -1.9758 | PASS (β€ -1.0) |
| Single-Snippet Latency | CPU Latency | 20.8 ms | PASS (< 100 ms) |
π» Quickstart Usage
With Sentence-Transformers:
from sentence_transformers import SentenceTransformer
# Automatically downloads from Hugging Face Hub
model = SentenceTransformer("divakantpandey/code-embed")
queries = ["binary search in sorted list", "read json file"]
snippets = [
"def binary_search(arr, target): ...",
"import json\ndef load_json(path): return json.load(open(path))"
]
query_embeddings = model.encode(queries, normalize_embeddings=True)
code_embeddings = model.encode(snippets, normalize_embeddings=True)
# Compute cosine similarity
similarities = query_embeddings @ code_embeddings.T
print(similarities)
π License & Commercial Inquiries
This model and its weights are released under the Creative Commons Attribution-NonCommercial 4.0 International (CC-BY-NC 4.0) license.
- Non-Commercial Use: Free for academic research, education, benchmarking, and non-commercial projects with attribution.
- Attribution: Please cite Divakant Pandey and link to https://github.com/divakantpandey/code-embed.
- Commercial Licensing: To use this model in commercial applications, proprietary software, enterprise APIs, or SaaS products, please contact:
- Maintainer: Divakant Pandey
- Email:
[email protected] - GitHub: @divakantpandey
- Downloads last month
- 58
Spaces using divakantpandey/code-embed 2
Collection including divakantpandey/code-embed
Evaluation results
- MRR@10 (100-pool) on CodeSearchNet (Python)test set self-reported0.751
- MRR@10 (15k-corpus) on CodeSearchNet (Python)test set self-reported0.824
- Recall@10 (15k-corpus) on CodeSearchNet (Python)test set self-reported0.923
- MRR@10 on CoSQAvalidation set self-reported0.751
- Recall@10 on CoSQAvalidation set self-reported0.860