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
Upload CodeEmbed model weights and configuration
Browse files- README.md +78 -0
- backbone/config.json +31 -0
- backbone/model.safetensors +3 -0
- code_embed_config.json +9 -0
- onnx/model.onnx +3 -0
- onnx/model_int8.onnx +3 -0
- projection_head.pt +3 -0
- pycode_embed_config.json +9 -0
- tokenizer.json +0 -0
- tokenizer_config.json +17 -0
README.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
- code
|
| 5 |
+
tags:
|
| 6 |
+
- python
|
| 7 |
+
- code-search
|
| 8 |
+
- code-embeddings
|
| 9 |
+
- sentence-transformers
|
| 10 |
+
- unixcoder
|
| 11 |
+
- matryoshka
|
| 12 |
+
- onnx
|
| 13 |
+
license: cc-by-nc-4.0
|
| 14 |
+
pipeline_tag: feature-extraction
|
| 15 |
+
library_name: sentence-transformers
|
| 16 |
+
metrics:
|
| 17 |
+
- mrr
|
| 18 |
+
- ndcg
|
| 19 |
+
- recall
|
| 20 |
+
---
|
| 21 |
+
|
| 22 |
+
# 💻 code-embed
|
| 23 |
+
|
| 24 |
+
CodeEmbed is a lightweight, high-performance code embedding model (≤130M parameters) developed by **[Divakant Pandey](https://github.com/divakantpandey)**. Specialized for semantic code search, code retrieval, and repository navigation with **8,192 token context** and **Matryoshka representation learning**.
|
| 25 |
+
|
| 26 |
+
## 🚀 Key Features
|
| 27 |
+
|
| 28 |
+
- **Author / Maintainer**: [Divakant Pandey](https://github.com/divakantpandey)
|
| 29 |
+
- **Backbone**: UniXcoder bi-encoder architecture with a 2-layer MLP projection head and unit-sphere L2 normalization.
|
| 30 |
+
- **3-Stage Curriculum**:
|
| 31 |
+
1. *SimCSE Unsupervised Contrastive Learning* (uniformity on hypersphere).
|
| 32 |
+
2. *Supervised Fine-Tuning* (MNRL with BM25 lexical hard negatives).
|
| 33 |
+
3. *Matryoshka Representation Learning (MRL)* (nested dimensions: 64, 128, 256, 384, 768, 1536).
|
| 34 |
+
- **Fast CPU Inference**: ~20.8 ms per code snippet on standard laptop CPU.
|
| 35 |
+
- **Production-Ready**: Exportable to ONNX with dynamic axes and dynamic INT8 quantization.
|
| 36 |
+
|
| 37 |
+
## 📊 Benchmark Results
|
| 38 |
+
|
| 39 |
+
| Benchmark | Metric | Value | Gate Status |
|
| 40 |
+
| :--- | :--- | :---: | :---: |
|
| 41 |
+
| **CodeSearchNet (Python)** | **MRR@10** | **0.7514** | **PASS** (≥ 0.65) |
|
| 42 |
+
| **CoSQA (Code Search QA)** | **MRR@10** | **0.7509** | **PASS** (≥ 0.50) |
|
| 43 |
+
| **Hypersphere Uniformity** | **Uniformity** | **-1.9758** | **PASS** (≤ -1.0) |
|
| 44 |
+
| **Single-Snippet Latency** | **CPU Latency** | **20.8 ms** | **PASS** (< 100 ms) |
|
| 45 |
+
|
| 46 |
+
## 💻 Quickstart Usage
|
| 47 |
+
|
| 48 |
+
### With Sentence-Transformers:
|
| 49 |
+
```python
|
| 50 |
+
from sentence_transformers import SentenceTransformer
|
| 51 |
+
|
| 52 |
+
# Automatically downloads from Hugging Face Hub
|
| 53 |
+
model = SentenceTransformer("divakantpandey/code-embed")
|
| 54 |
+
|
| 55 |
+
queries = ["binary search in sorted list", "read json file"]
|
| 56 |
+
snippets = [
|
| 57 |
+
"def binary_search(arr, target): ...",
|
| 58 |
+
"import json\ndef load_json(path): return json.load(open(path))"
|
| 59 |
+
]
|
| 60 |
+
|
| 61 |
+
query_embeddings = model.encode(queries, normalize_embeddings=True)
|
| 62 |
+
code_embeddings = model.encode(snippets, normalize_embeddings=True)
|
| 63 |
+
|
| 64 |
+
# Compute cosine similarity
|
| 65 |
+
similarities = query_embeddings @ code_embeddings.T
|
| 66 |
+
print(similarities)
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
## 📜 License & Commercial Inquiries
|
| 70 |
+
|
| 71 |
+
This model and its weights are released under the **Creative Commons Attribution-NonCommercial 4.0 International (CC-BY-NC 4.0)** license.
|
| 72 |
+
|
| 73 |
+
- **Non-Commercial Use:** Free for academic research, education, benchmarking, and non-commercial projects with attribution.
|
| 74 |
+
- **Attribution:** Please cite **Divakant Pandey** and link to [https://github.com/divakantpandey/code-embed](https://github.com/divakantpandey/code-embed).
|
| 75 |
+
- **Commercial Licensing:** To use this model in commercial applications, proprietary software, enterprise APIs, or SaaS products, please contact:
|
| 76 |
+
- **Maintainer:** Divakant Pandey
|
| 77 |
+
- **Email:** `divakant01@gmail.com`
|
| 78 |
+
- **GitHub:** [@divakantpandey](https://github.com/divakantpandey)
|
backbone/config.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_cross_attention": false,
|
| 3 |
+
"architectures": [
|
| 4 |
+
"RobertaModel"
|
| 5 |
+
],
|
| 6 |
+
"attention_probs_dropout_prob": 0.1,
|
| 7 |
+
"bos_token_id": 0,
|
| 8 |
+
"classifier_dropout": null,
|
| 9 |
+
"dtype": "float32",
|
| 10 |
+
"eos_token_id": 2,
|
| 11 |
+
"gradient_checkpointing": false,
|
| 12 |
+
"hidden_act": "gelu",
|
| 13 |
+
"hidden_dropout_prob": 0.1,
|
| 14 |
+
"hidden_size": 768,
|
| 15 |
+
"initializer_range": 0.02,
|
| 16 |
+
"intermediate_size": 3072,
|
| 17 |
+
"is_decoder": false,
|
| 18 |
+
"layer_norm_eps": 1e-05,
|
| 19 |
+
"max_position_embeddings": 8194,
|
| 20 |
+
"model_type": "roberta",
|
| 21 |
+
"num_attention_heads": 12,
|
| 22 |
+
"num_hidden_layers": 12,
|
| 23 |
+
"output_past": true,
|
| 24 |
+
"pad_token_id": 1,
|
| 25 |
+
"position_embedding_type": "absolute",
|
| 26 |
+
"tie_word_embeddings": true,
|
| 27 |
+
"transformers_version": "5.20.1",
|
| 28 |
+
"type_vocab_size": 10,
|
| 29 |
+
"use_cache": true,
|
| 30 |
+
"vocab_size": 51416
|
| 31 |
+
}
|
backbone/model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d013b306ee92fa36c45c0ced65e3b41742c9c14855ee2c1d9cae08bf0c3029e5
|
| 3 |
+
size 525761392
|
code_embed_config.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"base_model_name_or_path": "microsoft/unixcoder-base",
|
| 3 |
+
"backbone_hidden_size": 768,
|
| 4 |
+
"embedding_dim": 1536,
|
| 5 |
+
"projection_hidden_dim": 1536,
|
| 6 |
+
"pooling": "cls",
|
| 7 |
+
"max_seq_length": 8192,
|
| 8 |
+
"dropout": 0.1
|
| 9 |
+
}
|
onnx/model.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0d5b573befb66459c36aa5fdb109dcb46cc92b605be87607f9011195d4a54ea8
|
| 3 |
+
size 537853608
|
onnx/model_int8.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b9d0f987502073dc232cb0d5aa8c5e08e923fc4703d9d6b582cfc087f96e9d13
|
| 3 |
+
size 135275097
|
projection_head.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cbf1e13bb707299ddc99b72622c9807e48d44a58c72cbd399e61e081abfca2e4
|
| 3 |
+
size 14170669
|
pycode_embed_config.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"base_model_name_or_path": "microsoft/unixcoder-base",
|
| 3 |
+
"backbone_hidden_size": 768,
|
| 4 |
+
"embedding_dim": 1536,
|
| 5 |
+
"projection_hidden_dim": 1536,
|
| 6 |
+
"pooling": "cls",
|
| 7 |
+
"max_seq_length": 8192,
|
| 8 |
+
"dropout": 0.1
|
| 9 |
+
}
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": false,
|
| 3 |
+
"backend": "tokenizers",
|
| 4 |
+
"bos_token": "<s>",
|
| 5 |
+
"cls_token": "<s>",
|
| 6 |
+
"eos_token": "</s>",
|
| 7 |
+
"errors": "replace",
|
| 8 |
+
"is_local": false,
|
| 9 |
+
"local_files_only": false,
|
| 10 |
+
"mask_token": "<mask>",
|
| 11 |
+
"model_max_length": 1000000000000000019884624838656,
|
| 12 |
+
"pad_token": "<pad>",
|
| 13 |
+
"sep_token": "</s>",
|
| 14 |
+
"tokenizer_class": "RobertaTokenizer",
|
| 15 |
+
"trim_offsets": true,
|
| 16 |
+
"unk_token": "<unk>"
|
| 17 |
+
}
|