Feature Extraction
sentence-transformers
ONNX
Safetensors
English
code
roberta
python
code-search
code-embeddings
unixcoder
matryoshka
mteb
Eval Results (legacy)
text-embeddings-inference
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
|
Download README.md from divakantpandey/code-embed: direct link, hf CLI and curl.
- Browser
- Download file 4.03 kB
-
https://huggingface.co/divakantpandey/code-embed/resolve/main/README.md
- Command line
-
hf download hf://divakantpandey/code-embed/README.md
-
curl -L -o README.md https://huggingface.co/divakantpandey/code-embed/resolve/main/README.md
4.03 kB
metadata
language:
- en
- code
tags:
- python
- code-search
- code-embeddings
- sentence-transformers
- unixcoder
- matryoshka
- onnx
- mteb
license: cc-by-nc-4.0
pipeline_tag: feature-extraction
library_name: sentence-transformers
metrics:
- mrr
- ndcg
- recall
model-index:
- name: Code-Embed
results:
- task:
type: feature-extraction
name: Code Search
dataset:
name: CodeSearchNet (Python)
type: code_search_net
config: python
split: test
metrics:
- type: mrr@10
value: 0.7514
name: MRR@10 (100-pool)
- type: mrr@10
value: 0.8241
name: MRR@10 (15k-corpus)
- type: recall@10
value: 0.923
name: Recall@10 (15k-corpus)
- task:
type: feature-extraction
name: Code Question Answering
dataset:
name: CoSQA
type: cosqa
split: validation
metrics:
- type: mrr@10
value: 0.7509
name: MRR@10
- type: recall@10
value: 0.86
name: Recall@10
π» code-embed
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:
divakant01@gmail.com - GitHub: @divakantpandey