Text Classification
TensorRT
Core ML
ONNX
Safetensors
OpenVINO
code
multilingual
xlm-roberta
knowledge-graph
relation-extraction
relation-classification
cross-encoder
knowledge-distillation
Instructions to use faxenoff/code-daemon-relation-v1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- TensorRT
How to use faxenoff/code-daemon-relation-v1 with TensorRT:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
docs: simplified model card — purpose, trade-offs vs alternatives, usage profiles, files
Browse files
README.md
CHANGED
|
@@ -19,157 +19,77 @@ base_model:
|
|
| 19 |
|
| 20 |
# code-daemon-relation-v1
|
| 21 |
|
| 22 |
-
A **117M-parameter relation classifier**
|
| 23 |
-
|
|
|
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
|
| 30 |
-
logits = session.run(None, {"input_ids": ids, "attention_mask": mask})[0] # [B, 4]
|
| 31 |
-
```
|
| 32 |
|
| 33 |
-
|
| 34 |
-
and code comments in many languages.
|
| 35 |
-
|
| 36 |
-
---
|
| 37 |
-
|
| 38 |
-
## 1. The four classes
|
| 39 |
-
|
| 40 |
-
Wrap each entity in `[E1]…[/E1]` and `[E2]…[/E2]` inside its natural context. Take the `argmax`;
|
| 41 |
-
class 0 is an explicit **abstain**, and a softmax threshold drops the rest of the low-confidence tail.
|
| 42 |
|
| 43 |
| idx | label | meaning |
|
| 44 |
|--:|---|---|
|
| 45 |
-
| 0 | `NO_RELATION` | co-occur
|
| 46 |
-
| 1 | `semantically_similar_to` | same purpose or
|
| 47 |
-
| 2 | `supersedes_or_conflicts` | one
|
| 48 |
| 3 | `depends_on` | one requires or configures the other |
|
| 49 |
|
| 50 |
-
The taxonomy is
|
| 51 |
-
|
| 52 |
-
`configured_by`) and the distinctions were not reliably separable from context — the classifier spent
|
| 53 |
-
its capacity on boundaries that downstream consumers then collapsed anyway. Merging them into three
|
| 54 |
-
positives plus abstain is what the model is actually good at.
|
| 55 |
-
|
| 56 |
-
**Decision rule as shipped:** `argmax != NO_RELATION` **and** `1 - softmax[NO_RELATION] >= tau`.
|
| 57 |
-
Gating on the *probability that any relation exists* rather than on the winning class's own
|
| 58 |
-
probability is more robust: when a real relation's mass spreads across two plausible classes, the
|
| 59 |
-
per-class maximum sags while "something is here" stays high.
|
| 60 |
-
|
| 61 |
-
---
|
| 62 |
-
|
| 63 |
-
## 2. Architecture
|
| 64 |
-
|
| 65 |
-
- **Warm-start** — [`cross-encoder/mmarco-mMiniLMv2-L12-H384-v1`](https://huggingface.co/cross-encoder/mmarco-mMiniLMv2-L12-H384-v1).
|
| 66 |
-
- **Encoder** — XLM-RoBERTa, **12 layers / 384 hidden / 12 heads**, FFN 1536. **~117M**
|
| 67 |
-
parameters, of which 96M is the multilingual embedding table.
|
| 68 |
-
- **Vocabulary** — **250 006** pieces = 250 002 XLM-R + 4 markers `[E1]` `[/E1]` `[E2]` `[/E2]`
|
| 69 |
-
(ids 250002–250005).
|
| 70 |
-
- **I/O** — `input_ids`, `attention_mask` (**no `token_type_ids`**) → `logits[batch, 4]`.
|
| 71 |
-
Sequence **256** on the shipped engines; 64 / 128 also provided.
|
| 72 |
-
|
| 73 |
-
### Entity-marker pooling, not `[CLS]`
|
| 74 |
-
|
| 75 |
-
The classification head does **not** read the `[CLS]` vector. It mean-pools the hidden states at the
|
| 76 |
-
**entity-start markers** — the `[E1]` and `[E2]` positions — concatenates the two, and passes that
|
| 77 |
-
through a single linear layer.
|
| 78 |
-
|
| 79 |
-
This matters for a relation task. A `[CLS]` vector summarises the whole passage, so the head has to
|
| 80 |
-
recover *which two things* the question is about from a global summary. Reading the marker positions
|
| 81 |
-
instead gives the head both arguments directly and in order, so the relation is scored between the
|
| 82 |
-
two entities rather than inferred from the sentence as a whole. Direction comes free: swap the
|
| 83 |
-
markers and the input genuinely changes.
|
| 84 |
-
|
| 85 |
-
---
|
| 86 |
-
|
| 87 |
-
## 3. How it was made
|
| 88 |
-
|
| 89 |
-
**Warm-started** from a strong multilingual ranking cross-encoder, with its single ranking logit
|
| 90 |
-
replaced by the 4-class marker-pooling head, then fine-tuned by **sequence-level distillation** on
|
| 91 |
-
relation tuples, each grounded in the passage it was drawn from.
|
| 92 |
-
|
| 93 |
-
Two consequences are visible at inference and worth knowing. `NO_RELATION` is **trained, not
|
| 94 |
-
inferred** — abstain is a class the model was shown explicitly, which is why the `tau` gate below
|
| 95 |
-
behaves sensibly instead of firing on every co-occurrence. And the passage is expected to arrive
|
| 96 |
-
**windowed so that both markers survive truncation**: a pair whose second entity falls outside the
|
| 97 |
-
sequence budget is not a hard case, it is an unanswerable one.
|
| 98 |
-
|
| 99 |
-
---
|
| 100 |
-
|
| 101 |
-
## 4. Speed
|
| 102 |
-
|
| 103 |
-
Measured on one laptop: Intel Core Ultra 9 275HX / NVIDIA RTX 5060 Laptop.
|
| 104 |
-
|
| 105 |
-
All lanes at batch 16 × seq 256:
|
| 106 |
-
|
| 107 |
-
| lane | pairs/s | per batch |
|
| 108 |
-
|---|--:|--:|
|
| 109 |
-
| **TensorRT FP16, RTX 5060** | **2 942** | 5.44 ms |
|
| 110 |
-
| **OpenVINO FP16, iGPU** | **111** | 143 ms |
|
| 111 |
-
| OpenVINO FP16, CPU | 44 | 366 ms |
|
| 112 |
-
| ONNX Runtime FP32, CPU | 42 | 380 ms |
|
| 113 |
-
|
| 114 |
-
OpenVINO rows were measured on 2026.3; the IRs in this repository are built for 2026.4 (re-timed on the embedding model: within a few percent either way).
|
| 115 |
-
|
| 116 |
-
Per bucket, OpenVINO 2026.3 on the same laptop (pairs/s, solo):
|
| 117 |
-
|
| 118 |
-
| bucket | batch × seq | CPU FP16 | iGPU FP16 |
|
| 119 |
-
|---|---|--:|--:|
|
| 120 |
-
| s | 16 × 64 | 159 | **508** |
|
| 121 |
-
| m | 16 × 128 | 85 | **245** |
|
| 122 |
-
| l | 16 × 256 | 44 | **111** |
|
| 123 |
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
|
| 128 |
-
|
| 129 |
-
of thousands of candidate pairs, and only the compiled-engine path makes that a background task
|
| 130 |
-
rather than a batch job.
|
| 131 |
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
length. Padding is attention-masked, so a pair produces the same logits from any bucket that fits it.
|
| 135 |
|
| 136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
|
| 138 |
-
The
|
| 139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
|
| 141 |
-
|
| 142 |
-
|---|--:|
|
| 143 |
-
| GPU inference, 267 pairs/call at seq 256 | **5.87 ms** → ~45 000 pairs/s |
|
| 144 |
-
| End-to-end incl. tokenisation, 12 threads | **~2 500 pairs/s** |
|
| 145 |
-
| Relations written, 3 043 chunks | 15 175 in 15.3 s → **994/s** |
|
| 146 |
-
| Relations written, 4 975 chunks | 31 696 in 45.0 s → **704/s** |
|
| 147 |
-
|
| 148 |
-
Once the engine is batched this wide the GPU is no longer the limit — **tokenisation is**, and it is
|
| 149 |
-
worth giving it real thread count. Measured padding waste at these batch sizes is 18–20%, which is
|
| 150 |
-
what the length buckets are there to keep down.
|
| 151 |
-
|
| 152 |
-
---
|
| 153 |
|
| 154 |
-
|
| 155 |
|
| 156 |
-
|
| 157 |
-
~263 pairs per call:
|
| 158 |
-
|
| 159 |
-
| metric | value |
|
| 160 |
|---|--:|
|
| 161 |
-
|
|
| 162 |
-
|
|
| 163 |
-
|
|
| 164 |
-
|
|
| 165 |
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
acceptance threshold and are rejected, which is the point of the threshold.
|
| 169 |
|
| 170 |
-
|
| 171 |
|
| 172 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
|
| 174 |
```python
|
| 175 |
import numpy as np, onnxruntime as ort
|
|
@@ -195,135 +115,46 @@ classify("The [E1]FAISS[/E1] index was replaced by the [E2]native IVF[/E2] backe
|
|
| 195 |
# -> ('supersedes_or_conflicts', 0.7x)
|
| 196 |
```
|
| 197 |
|
| 198 |
-
|
| 199 |
-
pair of names with no surrounding text carries little signal.
|
| 200 |
-
|
| 201 |
-
---
|
| 202 |
-
|
| 203 |
-
## 6. Evaluation
|
| 204 |
-
|
| 205 |
-
**Dev macro-F1 = 0.547** over the four classes, on a 691-row held-out split of the distillation set.
|
| 206 |
-
|
| 207 |
-
Read that as what it is. The classes are intrinsically imbalanced — a teacher describing
|
| 208 |
-
documentation emits "similar" far more often than "depends on" — and the merged taxonomy still
|
| 209 |
-
contains genuinely ambiguous boundaries that human annotators would also disagree on. The abstain
|
| 210 |
-
class plus the `tau` gate exist because the useful operating point is *high-precision edges*, not
|
| 211 |
-
maximum recall: for building a graph, the real test is spot-checking the edges it emits at your
|
| 212 |
-
chosen threshold.
|
| 213 |
-
|
| 214 |
-
### Against zero-shot NLI — the alternative to training a head
|
| 215 |
-
|
| 216 |
-
With no training data for these classes, the textbook approach is a **zero-shot NLI** model: state
|
| 217 |
-
each class as a hypothesis and take the entailment score.
|
| 218 |
-
[`MoritzLaurer/mDeBERTa-v3-base-xnli-multilingual-nli-2mil7`](https://huggingface.co/MoritzLaurer/mDeBERTa-v3-base-xnli-multilingual-nli-2mil7)
|
| 219 |
-
is the standard pick. Same 691 rows, same 4-way mapping, same machine.
|
| 220 |
-
|
| 221 |
-
**What matches and what does not.** There is no public model trained on these four merged
|
| 222 |
-
classes, so the comparator matches on **task and dev set** but not on size (279 M against 117 M)
|
| 223 |
-
or runtime (PyTorch against onnxruntime) — and zero-shot pays one forward pass per class by
|
| 224 |
-
construction, which the speed figure below makes visible:
|
| 225 |
-
|
| 226 |
-
| model | params | macro-F1 | accuracy |
|
| 227 |
-
|---|--:|--:|--:|
|
| 228 |
-
| **this model** | 117 M | **0.569** | **0.670** |
|
| 229 |
-
| mDeBERTa-v3-xnli, zero-shot | 279 M | 0.194 | 0.295 |
|
| 230 |
-
| always `NO_RELATION` | — | 0.158 | 0.463 |
|
| 231 |
-
|
| 232 |
-
On the question the daemon actually asks — *is there a relation at all* — the gap is narrower on
|
| 233 |
-
F1 and wider in kind:
|
| 234 |
-
|
| 235 |
-
| model | has-rel F1 | P | R |
|
| 236 |
-
|---|--:|--:|--:|
|
| 237 |
-
| **this model** | **0.810** | **0.793** | 0.828 |
|
| 238 |
-
| mDeBERTa-v3-xnli | 0.699 | 0.538 | **0.997** |
|
| 239 |
-
|
| 240 |
-
A recall of 0.997 at a precision of 0.538 is the whole story: asked whether two entities in the
|
| 241 |
-
same paragraph are related, an NLI model says yes almost every time. For a graph builder that reads
|
| 242 |
-
the score as an edge weight, that is not a usable signal.
|
| 243 |
-
|
| 244 |
-
**Speed, same hardware, same 691 pairs:** **351 pairs/s** for this model (onnxruntime CUDA, FP32,
|
| 245 |
-
batch 16 × seq 256) against **61 pairs/s** for the zero-shot baseline (PyTorch CUDA). The 5.8× is
|
| 246 |
-
structural, not an implementation detail — zero-shot needs one forward pass **per class**, so a
|
| 247 |
-
4-class taxonomy costs four passes per pair where this model costs one. The shipped TensorRT FP16
|
| 248 |
-
engine is faster again (2 942 pairs/s, above).
|
| 249 |
-
|
| 250 |
-
Measured 2026-09-11; harness and raw JSON ship in the UltraCode repo
|
| 251 |
-
(`models/_distill_shared/bench_vs_generic.py`).
|
| 252 |
-
|
| 253 |
-
**Suited to**
|
| 254 |
-
- Turning prose or documentation into a typed concept graph.
|
| 255 |
-
- Any sweep where a large LLM per pair would be too slow or too expensive.
|
| 256 |
-
- Multilingual corpora, including code comments.
|
| 257 |
-
|
| 258 |
-
**Not suited to**
|
| 259 |
-
- Fine-grained relation ontologies — this is 3 positives plus abstain by design.
|
| 260 |
-
- Entity *extraction*: it classifies pairs you already found, it does not find them.
|
| 261 |
-
- Passages where the two entities are far apart — the marked window is 256 tokens.
|
| 262 |
-
|
| 263 |
-
---
|
| 264 |
-
|
| 265 |
-
## 7. What is in this repo
|
| 266 |
-
|
| 267 |
-
Compiled engines, named per **runtime × OS × GPU arch**, plus the ONNX for standalone use.
|
| 268 |
-
|
| 269 |
-
- **TensorRT FP16** — `code-daemon-relation-v1-{s,m,l}_{win_x64,linux_x64}_trt11.0_sm_{75,80,86,89,120}.engine`,
|
| 270 |
-
plus `code-daemon-relation-v1-{s,m,l}_linux_x64_trt11.0_sm_90.engine` (H100 / H200, Linux only)
|
| 271 |
-
(buckets seq 64 / 128 / 256, batch 16).
|
| 272 |
-
- **OpenVINO FP16** — `code-daemon-relation-v1-{s,m,l}_ov2026.4_{cpu,igpu}_fp16_b16_s{64,128,256}.{xml,bin}`.
|
| 273 |
-
- **Tokenizer** — `tokenizer.json`, `sentencepiece.bpe.model`, `tokenizer_config.json` (XLM-R
|
| 274 |
-
SentencePiece with the four marker tokens added).
|
| 275 |
-
- **ONNX** — `model.onnx` (+ `model.onnx.data`), FP32, the build source for every engine above.
|
| 276 |
-
- **Raw weights** — `model.safetensors` + `config.json`, the same FP32 weights under transformers
|
| 277 |
-
names: the encoder as `roberta.*`, the head as `classifier.weight` `[4, 768]` + `classifier.bias`.
|
| 278 |
-
⚠ The head is NOT the stock one — `AutoModelForSequenceClassification` would leave its own
|
| 279 |
-
`classifier.dense` / `classifier.out_proj` randomly initialised and ignore ours. Load the
|
| 280 |
-
encoder with `AutoModel`, mean-pool the last hidden state over the tokens equal to each marker
|
| 281 |
-
id (`config.json` → `ultracode.entity_marker_ids`, 250002 and 250004), concatenate the two and
|
| 282 |
-
apply the classifier. Done that way it matches the ONNX to 2e-6. The Apple (MLX) build is
|
| 283 |
-
prepared from this pair: the UltraCode MLX runtime implements this entity-pool head, with the
|
| 284 |
-
marker ids carried in the prepared file's header.
|
| 285 |
-
|
| 286 |
-
FP16 rather than INT8: this architecture's activation outliers make per-tensor INT8 calibration
|
| 287 |
-
lossy, and FP16 costs nothing on any GPU that can run it.
|
| 288 |
-
|
| 289 |
-
---
|
| 290 |
-
|
| 291 |
-
## Apple Neural Engine (Core ML)
|
| 292 |
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
entries (`Manifest.json`, `shapes.json`, `Data/com.apple.CoreML/model.mlmodel`,
|
| 296 |
-
`Data/com.apple.CoreML/weights/weight.bin`) that must keep their relative paths.
|
| 297 |
|
| 298 |
-
|
| 299 |
-
Fixed shapes are not a simplification. `ct.EnumeratedShapes` converts and runs, and
|
| 300 |
-
measures 233 emb/s against 2 873 on the same encoder, because the dynamic ops it
|
| 301 |
-
injects push the graph off the Neural Engine. `shapes.json` lists what was compiled,
|
| 302 |
-
so a caller can ask instead of assuming.
|
| 303 |
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 307 |
|
| 308 |
-
|
| 309 |
-
is ANE-ready exactly when it is MLX-ready — there is no second set of source weights.
|
| 310 |
-
Load it with `MLComputeUnits.cpuAndNeuralEngine`: plain `.all` lets Core ML place the
|
| 311 |
-
graph on the GPU instead, which measured 809 emb/s against the ANE's 2 873.
|
| 312 |
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
|
| 317 |
-
|
|
|
|
|
|
|
|
|
|
| 318 |
|
| 319 |
-
|
| 320 |
|
| 321 |
-
**
|
| 322 |
-
are **non-commercial research**.
|
| 323 |
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
|
|
|
| 327 |
|
| 328 |
Warm-started from **[cross-encoder/mmarco-mMiniLMv2-L12-H384-v1](https://huggingface.co/cross-encoder/mmarco-mMiniLMv2-L12-H384-v1)**.
|
| 329 |
Backbone: XLM-RoBERTa. Used by the [UltraCode](https://github.com/faxenoff/ultracode) code assistant,
|
|
|
|
| 19 |
|
| 20 |
# code-daemon-relation-v1
|
| 21 |
|
| 22 |
+
A **117M-parameter relation classifier** for building knowledge graphs from documentation. Mark two
|
| 23 |
+
entities inside a passage and it answers, in **one forward pass**, how they relate — one of three
|
| 24 |
+
relation types, or *no relation*.
|
| 25 |
|
| 26 |
+
**What makes it different:** typed relation extraction is usually handed to a large generative
|
| 27 |
+
model, token by token. This does it as a single classification, which makes it cheap enough to
|
| 28 |
+
sweep a whole corpus — **~2 900 pairs/s** on a laptop RTX 5060 — and its head reads the two
|
| 29 |
+
marked entities directly instead of a whole-passage summary, so the relation is scored between
|
| 30 |
+
them and in order. Multilingual: the XLM-R backbone reads prose and code comments in many languages.
|
| 31 |
|
| 32 |
+
## The four classes
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
Wrap the entities in `[E1]…[/E1]` and `[E2]…[/E2]` in their own context.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
| idx | label | meaning |
|
| 37 |
|--:|---|---|
|
| 38 |
+
| 0 | `NO_RELATION` | they co-occur but are unrelated — **abstain** |
|
| 39 |
+
| 1 | `semantically_similar_to` | same purpose or goal, different mechanism |
|
| 40 |
+
| 2 | `supersedes_or_conflicts` | one replaces, supersedes or contradicts the other |
|
| 41 |
| 3 | `depends_on` | one requires or configures the other |
|
| 42 |
|
| 43 |
+
The taxonomy is coarse on purpose: an earlier 8-way split (`replaced_by` vs `contradicts`,
|
| 44 |
+
`depends_on` vs `configured_by`, …) drew boundaries the context could not support.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
**Decision rule:** accept when `argmax != NO_RELATION` **and** `1 − softmax[NO_RELATION] ≥ tau`.
|
| 47 |
+
Gating on "is there any relation" holds up better than gating on the winning class, whose
|
| 48 |
+
probability sags when a real relation splits between two plausible types.
|
| 49 |
|
| 50 |
+
## Numbers
|
|
|
|
|
|
|
| 51 |
|
| 52 |
+
Same 691 held-out pairs, same 4-way mapping, same machine. The textbook alternative with no
|
| 53 |
+
training data is a zero-shot NLI model that scores each class as a hypothesis:
|
|
|
|
| 54 |
|
| 55 |
+
| model | params | macro-F1 | "has a relation" F1 | P | R | pairs/s |
|
| 56 |
+
|---|--:|--:|--:|--:|--:|--:|
|
| 57 |
+
| **this model** | 117M | **0.569** | **0.810** | **0.793** | 0.828 | **351** |
|
| 58 |
+
| mDeBERTa-v3-xnli, zero-shot | 279M | 0.194 | 0.699 | 0.538 | **0.997** | 61 |
|
| 59 |
+
| always `NO_RELATION` | — | 0.158 | — | — | — | — |
|
| 60 |
|
| 61 |
+
- **The NLI model says "related" to almost everything** (recall 0.997 at precision 0.538); as an
|
| 62 |
+
edge weight for a graph that is not a usable signal.
|
| 63 |
+
- **5.8× faster on the same runtime, structurally**: zero-shot pays one forward pass per class,
|
| 64 |
+
this pays one per pair. Speeds above are onnxruntime CUDA FP32 at batch 16 × seq 256; the
|
| 65 |
+
shipped TensorRT engine is faster again.
|
| 66 |
+
- **The trade:** three relation types plus abstain, nothing finer, and macro-F1 0.57 — the
|
| 67 |
+
classes are imbalanced and some boundaries are genuinely ambiguous. It is built for a
|
| 68 |
+
high-precision operating point: spot-check the edges at the `tau` you choose.
|
| 69 |
|
| 70 |
+
### Speed by lane
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
+
Batch 16 × seq 256, laptop Intel Core Ultra 9 275HX + RTX 5060:
|
| 73 |
|
| 74 |
+
| lane | pairs/s |
|
|
|
|
|
|
|
|
|
|
| 75 |
|---|--:|
|
| 76 |
+
| **TensorRT FP16, RTX 5060** | **2 942** |
|
| 77 |
+
| OpenVINO FP16, Intel iGPU | 111 |
|
| 78 |
+
| OpenVINO FP16, CPU | 44 |
|
| 79 |
+
| Apple M4, Neural Engine (seq 64 / 128 / 256) | 1 909 / 829 / 275 |
|
| 80 |
|
| 81 |
+
Inside a real index, with wide batches, the daemon sustains **~2 160 pairs/s** and creates
|
| 82 |
+
1 000–1 350 relations/s; at that width tokenisation, not the GPU, is the limit — give it threads.
|
|
|
|
| 83 |
|
| 84 |
+
## How to use it
|
| 85 |
|
| 86 |
+
- **One passage, both entities marked in place.** The model reads context; two bare names carry
|
| 87 |
+
little signal. Window the passage so **both markers survive truncation** — a pair whose second
|
| 88 |
+
entity falls outside the window cannot be answered.
|
| 89 |
+
- **Three length buckets** at batch 16: **s** seq 64, **m** 128, **l** 256. Attention is quadratic
|
| 90 |
+
in length, so route short passages to short engines (on the iGPU, s is 4.6× l). Padding is
|
| 91 |
+
masked: a pair gives the same logits from any bucket that fits it.
|
| 92 |
+
- **`tau` ≈ 0.7** is a reasonable start; raise it for fewer, surer edges.
|
| 93 |
|
| 94 |
```python
|
| 95 |
import numpy as np, onnxruntime as ort
|
|
|
|
| 115 |
# -> ('supersedes_or_conflicts', 0.7x)
|
| 116 |
```
|
| 117 |
|
| 118 |
+
Text goes in as an *(empty query, marked passage)* pair.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
+
**Not suited to:** fine-grained relation ontologies; finding the entities (it classifies pairs you
|
| 121 |
+
already have); entities more than a 256-token window apart.
|
|
|
|
|
|
|
| 122 |
|
| 123 |
+
## How it was made
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
+
- **Warm start:** the multilingual ranking cross-encoder `mmarco-mMiniLMv2-L12-H384-v1`
|
| 126 |
+
(XLM-RoBERTa, 12 layers × 384), with four marker tokens added to its vocabulary.
|
| 127 |
+
- **New head:** its single ranking logit was replaced by a 4-class layer over the hidden states at
|
| 128 |
+
the `[E1]` and `[E2]` positions, concatenated — not over `[CLS]`. Direction comes free: swap
|
| 129 |
+
the markers and the input genuinely changes.
|
| 130 |
+
- **Training:** sequence-level distillation from an LLM teacher on relation tuples, each grounded
|
| 131 |
+
in its passage; `NO_RELATION` is a trained class, not an inferred one.
|
| 132 |
+
- **FP16 engines**, not INT8: this architecture's activation outliers make INT8 calibration lossy.
|
| 133 |
|
| 134 |
+
## Files
|
|
|
|
|
|
|
|
|
|
| 135 |
|
| 136 |
+
| file | what it is |
|
| 137 |
+
|---|---|
|
| 138 |
+
| `model.onnx` + `model.onnx.data` | FP32 ONNX — the build source and the standalone path |
|
| 139 |
+
| `model.safetensors`, `config.json` | the same weights: encoder as `roberta.*`, head as `classifier.weight` `[4, 768]` + `classifier.bias` (see below); the Apple (MLX) build is prepared from this pair |
|
| 140 |
+
| `tokenizer.json`, `tokenizer_config.json`, `sentencepiece.bpe.model` | XLM-R tokenizer with the four marker tokens |
|
| 141 |
+
| `code-daemon-relation-v1-{s,m,l}_{win_x64,linux_x64}_trt11.0_sm_{75,80,86,89,120}.engine` | TensorRT FP16 per bucket × OS × GPU; `sm_90` (H100/H200) Linux only |
|
| 142 |
+
| `code-daemon-relation-v1-{s,m,l}_ov2026.4_{cpu,igpu}_fp16_b16_s{64,128,256}.{xml,bin}` | OpenVINO 2026.4 FP16, Intel CPU / iGPU |
|
| 143 |
+
| `coreml_ane/embed.mlpackage/` | Core ML for the Apple Neural Engine, functions `b16 s64 / s128 / s256`; load with `cpuAndNeuralEngine` |
|
| 144 |
|
| 145 |
+
⚠ The head is not the stock `transformers` one — `AutoModelForSequenceClassification` would
|
| 146 |
+
initialise its own and ignore this. Load the encoder with `AutoModel`, mean-pool the last hidden
|
| 147 |
+
state over the tokens equal to each marker id (`config.json` → `ultracode.entity_marker_ids`),
|
| 148 |
+
concatenate the two and apply the classifier; that matches the ONNX to 2e-6.
|
| 149 |
|
| 150 |
+
## License & attribution
|
| 151 |
|
| 152 |
+
Released under the **MIT license**.
|
|
|
|
| 153 |
|
| 154 |
+
⚠️ The warm-start base `cross-encoder/mmarco-mMiniLMv2-L12-H384-v1` derives from mMARCO ← MS MARCO,
|
| 155 |
+
whose terms are **non-commercial research**. Whether a fine-tuned model inherits dataset-use terms
|
| 156 |
+
is legally unsettled — this is **not legal advice**. Retrain from a permissive base if strict
|
| 157 |
+
compliance matters to you.
|
| 158 |
|
| 159 |
Warm-started from **[cross-encoder/mmarco-mMiniLMv2-L12-H384-v1](https://huggingface.co/cross-encoder/mmarco-mMiniLMv2-L12-H384-v1)**.
|
| 160 |
Backbone: XLM-RoBERTa. Used by the [UltraCode](https://github.com/faxenoff/ultracode) code assistant,
|