Text Classification
TensorRT
Core ML
ONNX
Safetensors
OpenVINO
code
multilingual
xlm-roberta
knowledge-graph
relation-extraction
relation-classification
cross-encoder
knowledge-distillation
Run this model with HF Jobs
Run faxenoff/code-daemon-relation-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/faxenoff/code-daemon-relation-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/faxenoff/code-daemon-relation-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 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
Upload README.md with huggingface_hub
Browse files123---license: mit---123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149---license: mitlanguage:- code- multilingualtags:- code- knowledge-graph- relation-extraction- cross-encoder- text-classification- knowledge-distillationpipeline_tag: text-classificationbase_model:- cross-encoder/mmarco-mMiniLMv2-L12-H384-v1datasets:- unicamp-dl/mmarco---# code-daemon-relation-v1A tiny **relation classifier**: given two entities marked inside a piece of text, it predicts **how theyrelate** β one of 8 relation types, or *no relation*. It reads the two entities and their surroundingcontext **jointly** (a cross-encoder) and emits 8 class logits in a single forward pass.The point of the model is to do a job people usually hand to a large generative LLM β reading a passageand extracting typed relations between the things it mentions β as **one cheap classification pass**instead of token-by-token generation. It was **distilled from a 7B instruct model** into a ~117Mcross-encoder, so it runs on a CPU/iGPU and is fast enough to sweep thousands of entity pairs whenbuilding a knowledge graph. It is used by the [UltraCode](https://github.com/faxenoff/ultracode) codeassistant to turn documentation into a graph of related concepts, but nothing about it is specific tothat tool.- **~117M params** β XLM-RoBERTa **12 layers / 384 hidden**, 250k **multilingual** SentencePiece vocab +4 entity-marker tokens (`[E1] [/E1] [E2] [/E2]`), so the embedding table is 250 006 rows.- **2-input ONNX** (`input_ids`, `attention_mask`; no `token_type_ids`) β **`logits[batch, 8]`**.- **Max sequence 256** tokens for the marked passage.- **Multilingual** β the XLM-R backbone handles text and code comments in many languages.## The 8 relation classesYou mark the two entities with `[E1]β¦[/E1]` and `[E2]β¦[/E2]` in their context; the model returns a logitper class. Take `argmax`; class 0 (`NO_RELATION`) is the **abstain** class, and a softmax-probabilitythreshold lets you drop low-confidence pairs.| idx | label | meaning ||--:|---|---|| 0 | `NO_RELATION` | the two entities co-occur but are not related (abstain) || 1 | `semantically_similar_to` | near-duplicate purpose / meaning || 2 | `shares_purpose_with` | related goal, different mechanism || 3 | `invalidates_with` | one makes the other wrong / stale || 4 | `configured_by` | one is configured / parameterised by the other || 5 | `depends_on` | one requires the other || 6 | `contradicts` | the two make opposing claims || 7 | `replaced_by` | one supersedes the other |## How it was made**Warm-started** from [`cross-encoder/mmarco-mMiniLMv2-L12-H384-v1`](https://huggingface.co/cross-encoder/mmarco-mMiniLMv2-L12-H384-v1)β a strong multilingual cross-encoder β with its single ranking logit swapped for an 8-class head, then**fine-tuned by sequence-level distillation** from a **Qwen2.5-7B-Instruct** teacher. The teacher readreal documentation and labelled the relations between the entities it mentioned; those labels became thetraining targets. The pairs were normalised to the 8 classes, filtered for hallucinated / junk entities,windowed so both markers stay in context, and balanced with synthesised *no-relation* negatives and extraexamples for the rarer classes.## What's special- **A 7B's task in one small forward pass.** Relation extraction is normally done by prompting a largeLLM; here it is a single ~sub-10 ms classification, cheap enough to run over a whole corpus.- **Joint (cross-encoder) reading.** The two entities and their context are read together in one pass, sothe model can weigh how they actually relate β far more precise than comparing two independentembeddings.- **Abstain + confidence.** `NO_RELATION` plus a softmax threshold keep spurious pairs out of your graph.- **Ships as compiled engines** (TensorRT / OpenVINO, fp16) for production-speed inference, plus the ONNXfor standalone use.## Intended useBuild a **knowledge graph**: for each pair of entities that co-occur in a passage, mark them and classifythe relation. Wrap the two entities with `[E1]β¦[/E1]` and `[E2]β¦[/E2]`, tokenize as an*(empty-query, marked-text)* pair (the format it was trained on), run the engine, `argmax` the 8 logits,and drop `NO_RELATION` / low-confidence results.```pythonimport onnxruntime as ort, numpy as npfrom transformers import AutoTokenizerLABELS = ["NO_RELATION","semantically_similar_to","shares_purpose_with","invalidates_with","configured_by","depends_on","contradicts","replaced_by"]tok = AutoTokenizer.from_pretrained(".") # bundled tokenizer incl. [E1]/[E2] markerssess = ort.InferenceSession("model.onnx", providers=["CPUExecutionProvider"])def classify(marked_text, max_len=256, tau=0.5):enc = tok([""], [marked_text], padding="max_length", truncation=True,max_length=max_len, return_tensors="np", return_token_type_ids=False)logits = sess.run(None, {"input_ids": enc["input_ids"].astype(np.int64),"attention_mask": enc["attention_mask"].astype(np.int64)})[0][0]p = np.exp(logits - logits.max()); p /= p.sum()i = int(p.argmax())return (LABELS[i], float(p[i])) if i != 0 and p[i] >= tau else ("NO_RELATION", float(p[0]))# classify("The [E1]FAISS[/E1] vector index was replaced by the [E2]native IVF[/E2] backend.")# -> ('replaced_by', 0.7x)```## What's in this repoReady-to-run compiled engines, named per **runtime Γ GPU arch Γ OS** (single-profile β no lengthbuckets):- **TensorRT** `code-daemon-relation-v1_{win_x64,linux_x64}_trt_sm_{86,89,120}.engine` β NVIDIA, fp16.- **OpenVINO** `code-daemon-relation-v1_ov_{cpu,igpu}_fp16_b16_s256.{xml,bin}` β Intel CPU / iGPU.- **Tokenizer** β `tokenizer.json` + `sentencepiece.bpe.model` + `tokenizer_config.json` (XLM-RSentencePiece with the 4 `[E1]/[E2]` marker tokens added).- **ONNX source** β `model.onnx` (+ `model.onnx.data`) FP32, for standalone `onnxruntime` / `optimum` use.> fp16 only: the mmarco format hits a known OpenVINO INT8 AccessViolation on the iGPU, so fp16 is shipped.## EvaluationThis is a **first distilled cut**, and the classes are naturally imbalanced (the teacher emits`semantically_similar_to` / `shares_purpose_with` far more often than `replaced_by` / `depends_on`).Reported honestly: **macro-F1 β 0.33** on a held-out dev split, with per-class F1 in the **~0.2β0.44**band for the well-populated classes and lower on the thin tail classes, which the data under-samples andwhich are supplemented with synthetic examples. The abstain class plus a softmax threshold keeplow-confidence pairs out of the graph. Metrics are advisory β for graph construction, spot-checking theedges it produces is the real test.## License & training dataReleased under the **MIT license** (the mmarco base + XLM-R backbone are MIT/Apache; fine-tuned weightsreleased MIT).| Source | Note ||---|---|| `cross-encoder/mmarco-mMiniLMv2-L12-H384-v1` (warm-start base) | **mMARCO β MS MARCO β non-commercial research terms** || distillation targets (Qwen2.5-7B-Instruct over open-source docs) | self-generated || synthesised negatives + rare-class augmentation | generated |β οΈ The warm-start base derives from **MS MARCO (non-commercial)**; whether a fine-tuned model inheritsdataset-use terms is legally unsettled β this is **not legal advice**. Retrain from a permissive base ifstrict compliance is required.## AttributionWarm-started from **[cross-encoder/mmarco-mMiniLMv2-L12-H384-v1](https://huggingface.co/cross-encoder/mmarco-mMiniLMv2-L12-H384-v1)**.Distilled from **Qwen2.5-7B-Instruct**. Backbone: XLM-RoBERTa.
README.md+146