πŸ’» 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:
    1. SimCSE Unsupervised Contrastive Learning (uniformity on hypersphere).
    2. Supervised Fine-Tuning (MNRL with BM25 lexical hard negatives).
    3. 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
Downloads last month
17
Safetensors
Model size
0.1B params
Tensor type
F32
Β·
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Space using divakantpandey/code-embed 1

Collection including divakantpandey/code-embed

Evaluation results