nethunter2023 commited on
Commit
f3271f7
Β·
verified Β·
1 Parent(s): 35584e2

Add general-purpose baseline, paired significance test, and eval protocol

Browse files
Files changed (1) hide show
  1. README.md +75 -17
README.md CHANGED
@@ -20,8 +20,7 @@ A 42.6M-parameter bi-encoder for retrieving **Linux kernel C** from
20
  natural-language queries. Queries and code go through the same encoder, with no
21
  prefix or instruction prompt.
22
 
23
- 512-dim output, mean pooling, L2-normalised. `max_seq_length` is **320** and
24
- should not be raised β€” longer inputs degrade retrieval. Chunk longer functions.
25
 
26
  ## Usage
27
 
@@ -37,26 +36,85 @@ emb = model.encode([query, code], normalize_embeddings=True)
37
  print(emb @ emb.T) # cosine similarity
38
  ```
39
 
 
 
 
 
 
 
 
40
  ## Results
41
 
42
- Retrieval over the whole kernel β€” **914,554 candidate chunks**:
 
 
 
 
 
 
43
 
44
- | | dense | hybrid (+ BM25) |
45
  |---|---|---|
46
- | recall@1 | 0.8125 | **0.9050** |
47
- | recall@5 | 0.9375 | **0.9725** |
48
- | recall@10 | 0.9575 | **0.9775** |
49
- | recall@50 | 0.9850 | **0.9950** |
50
- | MRR | 0.8682 | **0.9374** |
51
- | median rank | 1 | 1 |
52
 
53
- The correct function ranks first out of 914,554 candidates 90% of the time.
 
54
 
55
- Against a lexical baseline on a held-out set:
 
 
56
 
57
- | | BM25 | this model |
58
- |---|---|---|
59
- | accuracy@1 | 0.7115 | **0.9225** |
60
- | NDCG@10 | 0.8297 | **0.9659** |
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
- Trained on Linux kernel C only; not a general-purpose code embedding model.
 
 
 
 
 
20
  natural-language queries. Queries and code go through the same encoder, with no
21
  prefix or instruction prompt.
22
 
23
+ 512-dim output, mean pooling, L2-normalised β€” score with cosine similarity.
 
24
 
25
  ## Usage
26
 
 
36
  print(emb @ emb.T) # cosine similarity
37
  ```
38
 
39
+ ### Sequence length
40
+
41
+ `max_seq_length` is **320**, and should not be raised even though
42
+ `max_position_embeddings` is 512. Pretraining saw 512 tokens but the retrieval
43
+ stage trained at 320, so positions 320–511 are undertrained; feeding longer
44
+ inputs measurably degrades ranking. Chunk longer functions instead.
45
+
46
  ## Results
47
 
48
+ Two different protocols. Read them separately β€” the candidate pools differ by
49
+ two orders of magnitude, so the numbers are **not** comparable across tables.
50
+
51
+ ### 1. Open retrieval β€” the whole kernel
52
+
53
+ Every `.c`/`.h` chunk of Linux v7.1-rc5 as the index (**914,554 candidates**),
54
+ **N = 400** held-out queries, one correct answer each.
55
 
56
+ | | this model | + BM25 fusion |
57
  |---|---|---|
58
+ | recall@1 | **0.8125** | 0.9050 |
59
+ | recall@5 | 0.9375 | 0.9725 |
60
+ | recall@10 | 0.9575 | 0.9775 |
61
+ | recall@50 | 0.9850 | 0.9950 |
62
+ | MRR | 0.8682 | 0.9374 |
 
63
 
64
+ **The model alone ranks the correct function first 81% of the time out of
65
+ 914,554 candidates** (95% CI Β±3.8pp at N=400).
66
 
67
+ The second column is reciprocal-rank fusion of this model with BM25. It is
68
+ higher, but part of that lift is BM25's, so the 0.8125 figure is the one that
69
+ belongs to this model.
70
 
71
+ ### 2. Closed set β€” against other encoders
72
+
73
+ **N = 2,000** held-out queries, 4,000 candidates, where each distractor is a
74
+ sibling function from the same source file as the answer.
75
+
76
+ | | params | accuracy@1 | NDCG@10 |
77
+ |---|---|---|---|
78
+ | BM25 (lexical) | β€” | 0.7115 | 0.8297 |
79
+ | `jina-embeddings-v2-base-code` | 161M | 0.9035 | 0.9541 |
80
+ | **this model** | **42.6M** | **0.9230** | **0.9661** |
81
+
82
+ Scored with the identical query set, candidate pool and metric code. The
83
+ general-purpose code embedder was given a 512-token budget β€” more than this
84
+ model's 320.
85
+
86
+ The +2.0pp accuracy@1 margin over `jina-embeddings-v2-base-code` is significant
87
+ under a paired McNemar test: p = 0.003, 95% CI on the paired difference
88
+ +0.7pp to +3.4pp (N = 2,000). A 42.6M domain model edging out a 161M
89
+ general-purpose one β€” at 3.8Γ— fewer parameters β€” is the result worth having.
90
+
91
+ ## How the evaluation set was built
92
+
93
+ This matters for reading the numbers above.
94
+
95
+ Queries are **kernel-doc comments written by kernel developers**, not generated
96
+ by a language model β€” so they are not distribution-matched to the training data
97
+ by construction. They are held out from training. The **symbol name is stripped
98
+ from the query**: left in, `kmalloc_node` would appear in both the query and the
99
+ answer's signature and the task would collapse to identifier matching.
100
+
101
+ Training used InfoNCE over in-batch negatives (batch size 24, softmax scale
102
+ 20.0), with hard negatives drawn as sibling functions from the same file.
103
+
104
+ ## Limitations
105
+
106
+ - **Domain-specific.** Linux kernel C only. Not a general-purpose code or text
107
+ embedding model; do not expect transfer to other languages or codebases.
108
+ - **Short context** β€” 320 tokens. Long functions must be chunked.
109
+ - **kernel-doc phrasing.** Queries are developer-written documentation, which is
110
+ more precise than typical end-user questions. Expect lower accuracy on casual
111
+ or ambiguous phrasing.
112
+ - **Single held-out split**, no seed variance reported.
113
+
114
+ ## License
115
 
116
+ GPL-2.0, matching the Linux kernel corpus it was trained on. Whether a GPL
117
+ training corpus propagates to model weights is legally unsettled; this is the
118
+ conservative reading, chosen deliberately rather than by default. If you need
119
+ different terms for commercial use, treat that as an open question to resolve
120
+ with counsel rather than an answered one.