Sentence Similarity
sentence-transformers
Safetensors
English
modernbert
feature-extraction
code
code-search
code-retrieval
embeddings
mteb
text-embeddings-inference
Run this model with HF Jobs
Run f4roukb/denserepr-code-48M-EN-v1 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/f4roukb/denserepr-code-48M-EN-v1. 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/f4roukb/denserepr-code-48M-EN-v1 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 f4roukb/denserepr-code-48M-EN-v1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use f4roukb/denserepr-code-48M-EN-v1 with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("f4roukb/denserepr-code-48M-EN-v1") sentences = [ "That is a happy person", "That is a happy dog", "That is a very happy person", "Today is a sunny day" ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [4, 4] - Notebooks
- Google Colab
- Kaggle
Release denserepr-code-48M-EN-v1
Browse filesFiles changed (9)
- 1_Pooling/config.jsonAdded+10
- README.mdAdded+156
- config.jsonAdded+71
- config_sentence_transformers.jsonAdded+14
- model.safetensorsAdded+3
- modules.jsonAdded+14
- sentence_bert_config.jsonAdded+4
- tokenizer.jsonAdded
- tokenizer_config.jsonAdded+23
12345678910{ "word_embedding_dimension": 384, "pooling_mode_cls_token": true, "pooling_mode_mean_tokens": false, "pooling_mode_max_tokens": false, "pooling_mode_mean_sqrt_len_tokens": false, "pooling_mode_weightedmean_tokens": false, "pooling_mode_lasttoken": false, "include_prompt": true}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156---license: apache-2.0language:- enlibrary_name: sentence-transformerspipeline_tag: sentence-similaritybase_model: f4roukb/denserepr-code-48M-pretrain-EN-v1tags:- sentence-transformers- feature-extraction- sentence-similarity- code- code-search- code-retrieval- embeddings- mtebdatasets:- lightonai/cornstack- codefuse-ai/F2LLM-v2- CoIR-Retrieval/apps- CoIR-Retrieval/codefeedback-mt- CoIR-Retrieval/codefeedback-st- CoIR-Retrieval/CodeSearchNet- CoIR-Retrieval/CodeSearchNet-ccr- CoIR-Retrieval/codetrans-contest- CoIR-Retrieval/codetrans-dl- CoIR-Retrieval/cosqa- CoIR-Retrieval/synthetic-text2sql- mteb/StackOverflowQA- seeklhy/SynSQL-2.5M- microsoft/rStar-Coder- thinkerhui/CoSQA_Plus- deepmind/code_contests- BAAI/TACO- open-r1/codeforces---
# denserepr-code-48M-EN-v1
A small dense embedding model for **code retrieval**: 48M parameters, one 384-d vector per text, cosine similarity,8,192-token context. It scores **68.86 mean nDCG@10 on CoIR** (10 tasks): +4.0 over[denserepr-code-48M-pretrain-EN-v1](https://huggingface.co/f4roukb/denserepr-code-48M-pretrain-EN-v1), the model itwas trained from, and +15.4 over[ibm-granite/granite-embedding-small-english-r2](https://huggingface.co/ibm-granite/granite-embedding-small-english-r2),the original base.
It is denserepr-code-48M-pretrain-EN-v1 fine-tuned on 4.4M code retrieval samples, with**mined hard negatives** and **listwise distillation** from[google/embeddinggemma-2](https://huggingface.co/google/embeddinggemma-2).
**At the time of publication (2026-11-23), it is on the Pareto frontier of MTEB CoIR** (mean nDCG@10 vs.parameters), across all model types: dense, multi-vector and sparse. It scores higher than every model on theleaderboard with fewer than 149M parameters (3× its size), including F2LLM-v2-80M (80.1M, 68.38, dense) andLateOn-Code-edge (17M, 64.96, multi-vector). The smallest models that score higher are gte-modernbert-base andLateOn-Code, at 149M. The comparison uses the reported results of the models with all 10 tasks, from the MTEB resultsrepository as of 2026-11-22. This model's own scores are measured locally; it is not on the leaderboard yet.
## Usage
```pythonfrom sentence_transformers import SentenceTransformer
model = SentenceTransformer("f4roukb/denserepr-code-48M-EN-v1")
queries = ["read a csv file into a list of dicts"]docs = [ "def load(path):\n import csv\n with open(path) as f:\n return list(csv.DictReader(f))", "def save(rows, path):\n import json\n with open(path, 'w') as f:\n json.dump(rows, f)",]q = model.encode(queries)d = model.encode(docs)print(model.similarity(q, d)) # the first document scores higher```
No prompts or instructions: queries and documents are encoded the same way.
| | ||---|---|| parameters | 47,662,464 || embedding | 384-d, CLS pooling, cosine similarity || max sequence length | 8,192 tokens || architecture | ModernBERT (from granite-embedding-small-english-r2) || weights | fp32 safetensors || precision | mixed bf16 / fp32: fp32 weights, run with bf16 autocast |
## Results: CoIR (MTEB)
nDCG@10 ×100 at 8,192 tokens, measured with `mteb`. All three models are measured the same way.
| task | granite-small-r2 (base) | pretrain-EN-v1 | **this model** ||---|---|---|---|| AppsRetrieval | 13.48 | 30.75 | **48.69** || CodeFeedbackMT | 52.20 | 81.19 | **87.71** || CodeFeedbackST | 76.84 | 81.26 | **83.40** || CodeSearchNetCCRetrieval | 48.42 | 75.97 | **84.17** || CodeTransOceanContest | 77.63 | 80.00 | **81.30** || CodeTransOceanDL | 33.63 | 34.84 | **35.19** || CosQA | **35.40** | 33.84 | 31.87 || COIRCodeSearchNetRetrieval | 60.42 | 79.90 | **81.06** || StackOverflowQA | 90.04 | 90.97 | **92.14** || SyntheticText2SQL | 46.44 | 59.69 | **63.04** || **mean** | 53.45 | 64.84 | **68.86** |
## Training
Two stages:
1. **Pretraining** ([denserepr-code-48M-pretrain-EN-v1](https://huggingface.co/f4roukb/denserepr-code-48M-pretrain-EN-v1)): continued contrastive pretraining of granite-embedding-small-english-r2 on ~23M code pairs.2. **Fine-tuning** (this model): contrastive training with mined hard negatives, plus distillation from embeddinggemma-2, on code retrieval data.
## Data (fine-tuning stage)
About 4.4M samples, deduplicated and decontaminated against the CoIR test sets:
| source | content | samples | share ||---|---|---|---|| [codefuse-ai/F2LLM-v2](https://huggingface.co/datasets/codefuse-ai/F2LLM-v2) | OCGI (instruction → Python), ProCQA (programming question → answer), xCodeEval (problem → solution) | 1,588,911 | 36.6% || [CoIR-Retrieval](https://huggingface.co/CoIR-Retrieval) train splits | CodeSearchNet, CodeSearchNet-CCR, CodeFeedback-ST/MT, synthetic Text2SQL, StackOverflow-QA, CodeTransOcean | 2,172,926 | 50.0% || [seeklhy/SynSQL-2.5M](https://huggingface.co/datasets/seeklhy/SynSQL-2.5M) | question → SQL (300K subset) | 299,996 | 6.9% || [microsoft/rStar-Coder](https://huggingface.co/datasets/microsoft/rStar-Coder) | problem → solution | 157,710 | 3.6% || [thinkerhui/CoSQA_Plus](https://huggingface.co/datasets/thinkerhui/CoSQA_Plus) | web query → Python | 37,866 | 0.9% || [deepmind/code_contests](https://huggingface.co/datasets/deepmind/code_contests), [IBM Project CodeNet](https://github.com/IBM/Project_CodeNet), [BAAI/TACO](https://huggingface.co/datasets/BAAI/TACO), [open-r1/codeforces](https://huggingface.co/datasets/open-r1/codeforces) | problem → solution | 90,344 | 2.1% |
The pretraining stage's data is described in the[pretrain-EN-v1 card](https://huggingface.co/f4roukb/denserepr-code-48M-pretrain-EN-v1#data).
## Limitations
- English queries; code mostly in Python, Go, Java, PHP, JavaScript, Ruby, C++ and SQL.
## License and attribution
Apache-2.0. This model is a modified version of[ibm-granite/granite-embedding-small-english-r2](https://huggingface.co/ibm-granite/granite-embedding-small-english-r2)(Apache-2.0, © IBM): its weights were changed by the training described above. It is not an IBM model. Thedistillation teacher, [google/embeddinggemma-2](https://huggingface.co/google/embeddinggemma-2), is Apache-2.0; thisis not a Google model.
Training data and licenses: cornstack (Apache-2.0), F2LLM-v2 (Apache-2.0; its OCGI and xCodeEval parts areCC-BY-4.0; ProCQA comes from StackOverflow), SynSQL-2.5M (Apache-2.0), rStar-Coder (CC-BY-4.0), CoSQA+ (CC-BY-4.0),code_contests (CC-BY-4.0), Project CodeNet (CDLA-Permissive-2.0), TACO (Apache-2.0), open-r1/codeforces (CC-BY-4.0),and the CoIR train splits, whose upstream sources are APPS (MIT), CodeSearchNet, Code-Feedback (Apache-2.0),gretelai synthetic text-to-SQL (Apache-2.0), CodeTransOcean and StackOverflow (CC-BY-SA). Thanks to their authors.
## Citation
```bibtex@misc{denserepr2026v1, title = {denserepr-code-48M-EN-v1: a small dense embedding model for code retrieval}, author = {Farouk B.}, year = {2026}, url = {https://huggingface.co/f4roukb/denserepr-code-48M-EN-v1}}```1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071{ "architectures": [ "ModernBertModel" ], "attention_bias": false, "attention_dropout": 0.0, "attention_probs_dropout_prob": 0.1, "bos_token_id": 50281, "classifier_activation": "silu", "classifier_bias": false, "classifier_dropout": 0.0, "classifier_pooling": "mean", "cls_token_id": 50281, "decoder_bias": true, "deterministic_flash_attn": false, "dtype": "float32", "embedding_dropout": 0.0, "eos_token_id": 50282, "global_attn_every_n_layers": 3, "gradient_checkpointing": false, "hidden_act": "gelu", "hidden_activation": "gelu", "hidden_dropout_prob": 0.1, "hidden_size": 384, "initializer_cutoff_factor": 2.0, "initializer_range": 0.02, "intermediate_size": 1536, "layer_norm_eps": 1e-05, "layer_types": [ "full_attention", "sliding_attention", "sliding_attention", "full_attention", "sliding_attention", "sliding_attention", "full_attention", "sliding_attention", "sliding_attention", "full_attention", "sliding_attention", "sliding_attention" ], "local_attention": 128, "max_position_embeddings": 8192, "mlp_bias": false, "mlp_dropout": 0.0, "model_type": "modernbert", "norm_bias": false, "norm_eps": 1e-05, "num_attention_heads": 12, "num_hidden_layers": 12, "pad_token_id": 50283, "position_embedding_type": "relative_key_query", "repad_logits_with_grad": false, "rope_parameters": { "full_attention": { "rope_theta": 80000, "rope_type": "default" }, "sliding_attention": { "rope_theta": 10000.0, "rope_type": "default" } }, "sep_token_id": 50282, "sparse_pred_ignore_index": -100, "sparse_prediction": false, "tie_word_embeddings": true, "transformers_version": "5.3.0", "vocab_size": 50368}1234567891011121314{ "model_type": "SentenceTransformer", "__version__": { "sentence_transformers": "5.3.0", "transformers": "5.3.0", "pytorch": "2.11.0+cu130" }, "prompts": { "query": "", "document": "" }, "default_prompt_name": null, "similarity_fn_name": "cosine"}123version https://git-lfs.github.com/spec/v1oid sha256:9562861bd00320640170ae8a36332a75e6efb58a11005f75fc9ca0a408727a75size 1906570161234567891011121314[ { "idx": 0, "name": "0", "path": "", "type": "sentence_transformers.models.Transformer" }, { "idx": 1, "name": "1", "path": "1_Pooling", "type": "sentence_transformers.models.Pooling" }]1234{ "max_seq_length": 8192, "do_lower_case": false}1234567891011121314151617181920212223{ "backend": "tokenizers", "clean_up_tokenization_spaces": true, "cls_token": "[CLS]", "is_local": true, "mask_token": "[MASK]", "max_length": 1024, "model_input_names": [ "input_ids", "attention_mask" ], "model_max_length": 8192, "pad_to_multiple_of": null, "pad_token": "[PAD]", "pad_token_type_id": 0, "padding_side": "right", "sep_token": "[SEP]", "stride": 0, "tokenizer_class": "TokenizersBackend", "truncation_side": "right", "truncation_strategy": "longest_first", "unk_token": "[UNK]"}1_Pooling/config.jsonAdded+10
README.mdAdded+156
config.jsonAdded+71
config_sentence_transformers.jsonAdded+14
model.safetensorsAdded+3
modules.jsonAdded+14
sentence_bert_config.jsonAdded+4
tokenizer.jsonAdded
tokenizer_config.jsonAdded+23