f4roukb commited on
Commit
8cbfa68
·
verified ·
1 Parent(s): 5931313

Release denserepr-code-48M-EN-v1

Browse files
1_Pooling/config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "word_embedding_dimension": 384,
3
+ "pooling_mode_cls_token": true,
4
+ "pooling_mode_mean_tokens": false,
5
+ "pooling_mode_max_tokens": false,
6
+ "pooling_mode_mean_sqrt_len_tokens": false,
7
+ "pooling_mode_weightedmean_tokens": false,
8
+ "pooling_mode_lasttoken": false,
9
+ "include_prompt": true
10
+ }
README.md ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ library_name: sentence-transformers
6
+ pipeline_tag: sentence-similarity
7
+ base_model: f4roukb/denserepr-code-48M-pretrain-EN-v1
8
+ tags:
9
+ - sentence-transformers
10
+ - feature-extraction
11
+ - sentence-similarity
12
+ - code
13
+ - code-search
14
+ - code-retrieval
15
+ - embeddings
16
+ - mteb
17
+ datasets:
18
+ - lightonai/cornstack
19
+ - codefuse-ai/F2LLM-v2
20
+ - CoIR-Retrieval/apps
21
+ - CoIR-Retrieval/codefeedback-mt
22
+ - CoIR-Retrieval/codefeedback-st
23
+ - CoIR-Retrieval/CodeSearchNet
24
+ - CoIR-Retrieval/CodeSearchNet-ccr
25
+ - CoIR-Retrieval/codetrans-contest
26
+ - CoIR-Retrieval/codetrans-dl
27
+ - CoIR-Retrieval/cosqa
28
+ - CoIR-Retrieval/synthetic-text2sql
29
+ - mteb/StackOverflowQA
30
+ - seeklhy/SynSQL-2.5M
31
+ - microsoft/rStar-Coder
32
+ - thinkerhui/CoSQA_Plus
33
+ - deepmind/code_contests
34
+ - BAAI/TACO
35
+ - open-r1/codeforces
36
+ ---
37
+
38
+ # denserepr-code-48M-EN-v1
39
+
40
+ A small dense embedding model for **code retrieval**: 48M parameters, one 384-d vector per text, cosine similarity,
41
+ 8,192-token context. It scores **68.86 mean nDCG@10 on CoIR** (10 tasks): +4.0 over
42
+ [denserepr-code-48M-pretrain-EN-v1](https://huggingface.co/f4roukb/denserepr-code-48M-pretrain-EN-v1), the model it
43
+ was trained from, and +15.4 over
44
+ [ibm-granite/granite-embedding-small-english-r2](https://huggingface.co/ibm-granite/granite-embedding-small-english-r2),
45
+ the original base.
46
+
47
+ It is denserepr-code-48M-pretrain-EN-v1 fine-tuned on 4.4M code retrieval samples, with
48
+ **mined hard negatives** and **listwise distillation** from
49
+ [google/embeddinggemma-2](https://huggingface.co/google/embeddinggemma-2).
50
+
51
+ **At the time of publication (2026-11-23), it is on the Pareto frontier of MTEB CoIR** (mean nDCG@10 vs.
52
+ parameters), across all model types: dense, multi-vector and sparse. It scores higher than every model on the
53
+ leaderboard with fewer than 149M parameters (3× its size), including F2LLM-v2-80M (80.1M, 68.38, dense) and
54
+ LateOn-Code-edge (17M, 64.96, multi-vector). The smallest models that score higher are gte-modernbert-base and
55
+ LateOn-Code, at 149M. The comparison uses the reported results of the models with all 10 tasks, from the MTEB results
56
+ repository as of 2026-11-22. This model's own scores are measured locally; it is not on the leaderboard yet.
57
+
58
+ ## Usage
59
+
60
+ ```python
61
+ from sentence_transformers import SentenceTransformer
62
+
63
+ model = SentenceTransformer("f4roukb/denserepr-code-48M-EN-v1")
64
+
65
+ queries = ["read a csv file into a list of dicts"]
66
+ docs = [
67
+ "def load(path):\n import csv\n with open(path) as f:\n return list(csv.DictReader(f))",
68
+ "def save(rows, path):\n import json\n with open(path, 'w') as f:\n json.dump(rows, f)",
69
+ ]
70
+ q = model.encode(queries)
71
+ d = model.encode(docs)
72
+ print(model.similarity(q, d)) # the first document scores higher
73
+ ```
74
+
75
+ No prompts or instructions: queries and documents are encoded the same way.
76
+
77
+ | | |
78
+ |---|---|
79
+ | parameters | 47,662,464 |
80
+ | embedding | 384-d, CLS pooling, cosine similarity |
81
+ | max sequence length | 8,192 tokens |
82
+ | architecture | ModernBERT (from granite-embedding-small-english-r2) |
83
+ | weights | fp32 safetensors |
84
+ | precision | mixed bf16 / fp32: fp32 weights, run with bf16 autocast |
85
+
86
+ ## Results: CoIR (MTEB)
87
+
88
+ nDCG@10 ×100 at 8,192 tokens, measured with `mteb`. All three models are measured the same way.
89
+
90
+ | task | granite-small-r2 (base) | pretrain-EN-v1 | **this model** |
91
+ |---|---|---|---|
92
+ | AppsRetrieval | 13.48 | 30.75 | **48.69** |
93
+ | CodeFeedbackMT | 52.20 | 81.19 | **87.71** |
94
+ | CodeFeedbackST | 76.84 | 81.26 | **83.40** |
95
+ | CodeSearchNetCCRetrieval | 48.42 | 75.97 | **84.17** |
96
+ | CodeTransOceanContest | 77.63 | 80.00 | **81.30** |
97
+ | CodeTransOceanDL | 33.63 | 34.84 | **35.19** |
98
+ | CosQA | **35.40** | 33.84 | 31.87 |
99
+ | COIRCodeSearchNetRetrieval | 60.42 | 79.90 | **81.06** |
100
+ | StackOverflowQA | 90.04 | 90.97 | **92.14** |
101
+ | SyntheticText2SQL | 46.44 | 59.69 | **63.04** |
102
+ | **mean** | 53.45 | 64.84 | **68.86** |
103
+
104
+ ## Training
105
+
106
+ Two stages:
107
+
108
+ 1. **Pretraining** ([denserepr-code-48M-pretrain-EN-v1](https://huggingface.co/f4roukb/denserepr-code-48M-pretrain-EN-v1)):
109
+ continued contrastive pretraining of granite-embedding-small-english-r2 on ~23M code pairs.
110
+ 2. **Fine-tuning** (this model): contrastive training with mined hard negatives, plus distillation from
111
+ embeddinggemma-2, on code retrieval data.
112
+
113
+ ## Data (fine-tuning stage)
114
+
115
+ About 4.4M samples, deduplicated and decontaminated against the CoIR test sets:
116
+
117
+ | source | content | samples | share |
118
+ |---|---|---|---|
119
+ | [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% |
120
+ | [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% |
121
+ | [seeklhy/SynSQL-2.5M](https://huggingface.co/datasets/seeklhy/SynSQL-2.5M) | question → SQL (300K subset) | 299,996 | 6.9% |
122
+ | [microsoft/rStar-Coder](https://huggingface.co/datasets/microsoft/rStar-Coder) | problem → solution | 157,710 | 3.6% |
123
+ | [thinkerhui/CoSQA_Plus](https://huggingface.co/datasets/thinkerhui/CoSQA_Plus) | web query → Python | 37,866 | 0.9% |
124
+ | [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% |
125
+
126
+ The pretraining stage's data is described in the
127
+ [pretrain-EN-v1 card](https://huggingface.co/f4roukb/denserepr-code-48M-pretrain-EN-v1#data).
128
+
129
+ ## Limitations
130
+
131
+ - English queries; code mostly in Python, Go, Java, PHP, JavaScript, Ruby, C++ and SQL.
132
+
133
+ ## License and attribution
134
+
135
+ Apache-2.0. This model is a modified version of
136
+ [ibm-granite/granite-embedding-small-english-r2](https://huggingface.co/ibm-granite/granite-embedding-small-english-r2)
137
+ (Apache-2.0, © IBM): its weights were changed by the training described above. It is not an IBM model. The
138
+ distillation teacher, [google/embeddinggemma-2](https://huggingface.co/google/embeddinggemma-2), is Apache-2.0; this
139
+ is not a Google model.
140
+
141
+ Training data and licenses: cornstack (Apache-2.0), F2LLM-v2 (Apache-2.0; its OCGI and xCodeEval parts are
142
+ CC-BY-4.0; ProCQA comes from StackOverflow), SynSQL-2.5M (Apache-2.0), rStar-Coder (CC-BY-4.0), CoSQA+ (CC-BY-4.0),
143
+ code_contests (CC-BY-4.0), Project CodeNet (CDLA-Permissive-2.0), TACO (Apache-2.0), open-r1/codeforces (CC-BY-4.0),
144
+ and the CoIR train splits, whose upstream sources are APPS (MIT), CodeSearchNet, Code-Feedback (Apache-2.0),
145
+ gretelai synthetic text-to-SQL (Apache-2.0), CodeTransOcean and StackOverflow (CC-BY-SA). Thanks to their authors.
146
+
147
+ ## Citation
148
+
149
+ ```bibtex
150
+ @misc{denserepr2026v1,
151
+ title = {denserepr-code-48M-EN-v1: a small dense embedding model for code retrieval},
152
+ author = {Farouk B.},
153
+ year = {2026},
154
+ url = {https://huggingface.co/f4roukb/denserepr-code-48M-EN-v1}
155
+ }
156
+ ```
config.json ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "ModernBertModel"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "attention_probs_dropout_prob": 0.1,
8
+ "bos_token_id": 50281,
9
+ "classifier_activation": "silu",
10
+ "classifier_bias": false,
11
+ "classifier_dropout": 0.0,
12
+ "classifier_pooling": "mean",
13
+ "cls_token_id": 50281,
14
+ "decoder_bias": true,
15
+ "deterministic_flash_attn": false,
16
+ "dtype": "float32",
17
+ "embedding_dropout": 0.0,
18
+ "eos_token_id": 50282,
19
+ "global_attn_every_n_layers": 3,
20
+ "gradient_checkpointing": false,
21
+ "hidden_act": "gelu",
22
+ "hidden_activation": "gelu",
23
+ "hidden_dropout_prob": 0.1,
24
+ "hidden_size": 384,
25
+ "initializer_cutoff_factor": 2.0,
26
+ "initializer_range": 0.02,
27
+ "intermediate_size": 1536,
28
+ "layer_norm_eps": 1e-05,
29
+ "layer_types": [
30
+ "full_attention",
31
+ "sliding_attention",
32
+ "sliding_attention",
33
+ "full_attention",
34
+ "sliding_attention",
35
+ "sliding_attention",
36
+ "full_attention",
37
+ "sliding_attention",
38
+ "sliding_attention",
39
+ "full_attention",
40
+ "sliding_attention",
41
+ "sliding_attention"
42
+ ],
43
+ "local_attention": 128,
44
+ "max_position_embeddings": 8192,
45
+ "mlp_bias": false,
46
+ "mlp_dropout": 0.0,
47
+ "model_type": "modernbert",
48
+ "norm_bias": false,
49
+ "norm_eps": 1e-05,
50
+ "num_attention_heads": 12,
51
+ "num_hidden_layers": 12,
52
+ "pad_token_id": 50283,
53
+ "position_embedding_type": "relative_key_query",
54
+ "repad_logits_with_grad": false,
55
+ "rope_parameters": {
56
+ "full_attention": {
57
+ "rope_theta": 80000,
58
+ "rope_type": "default"
59
+ },
60
+ "sliding_attention": {
61
+ "rope_theta": 10000.0,
62
+ "rope_type": "default"
63
+ }
64
+ },
65
+ "sep_token_id": 50282,
66
+ "sparse_pred_ignore_index": -100,
67
+ "sparse_prediction": false,
68
+ "tie_word_embeddings": true,
69
+ "transformers_version": "5.3.0",
70
+ "vocab_size": 50368
71
+ }
config_sentence_transformers.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_type": "SentenceTransformer",
3
+ "__version__": {
4
+ "sentence_transformers": "5.3.0",
5
+ "transformers": "5.3.0",
6
+ "pytorch": "2.11.0+cu130"
7
+ },
8
+ "prompts": {
9
+ "query": "",
10
+ "document": ""
11
+ },
12
+ "default_prompt_name": null,
13
+ "similarity_fn_name": "cosine"
14
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9562861bd00320640170ae8a36332a75e6efb58a11005f75fc9ca0a408727a75
3
+ size 190657016
modules.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "idx": 0,
4
+ "name": "0",
5
+ "path": "",
6
+ "type": "sentence_transformers.models.Transformer"
7
+ },
8
+ {
9
+ "idx": 1,
10
+ "name": "1",
11
+ "path": "1_Pooling",
12
+ "type": "sentence_transformers.models.Pooling"
13
+ }
14
+ ]
sentence_bert_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "max_seq_length": 8192,
3
+ "do_lower_case": false
4
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "backend": "tokenizers",
3
+ "clean_up_tokenization_spaces": true,
4
+ "cls_token": "[CLS]",
5
+ "is_local": true,
6
+ "mask_token": "[MASK]",
7
+ "max_length": 1024,
8
+ "model_input_names": [
9
+ "input_ids",
10
+ "attention_mask"
11
+ ],
12
+ "model_max_length": 8192,
13
+ "pad_to_multiple_of": null,
14
+ "pad_token": "[PAD]",
15
+ "pad_token_type_id": 0,
16
+ "padding_side": "right",
17
+ "sep_token": "[SEP]",
18
+ "stride": 0,
19
+ "tokenizer_class": "TokenizersBackend",
20
+ "truncation_side": "right",
21
+ "truncation_strategy": "longest_first",
22
+ "unk_token": "[UNK]"
23
+ }