Upload README.md with huggingface_hub
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157---license: mitbase_model: microsoft/deberta-v3-baselanguage: - enlibrary_name: onnxtags: - token-classification - intent-classification - onnx - daw - music-production---
# MAGDA command model
Turns a typed request into a [MAGDA](https://github.com/Conceptual-Machines/magda-core)DAW command, offline and on-device. "put @serum on a new track" becomes`track(name="", new=true).fx.add(name="<serum>")`, which the DAW executes as oneundoable transaction.
Fine-tuned from `microsoft/deberta-v3-base`. English only.
## What it actually does
**It never writes the command.** It does perception only, in a single forwardpass, and emits two things:
1. which of 38 commands this is2. a BIO tag per word saying what role that word plays
```"can you drop @1176 onto the vocals" O O O PLUGIN O O TRACK_NAME intent = add_plugin```
Deterministic code then assembles the DSL from those labels. The model cannotemit malformed output, because it does not emit output — a property agenerative model would have to buy back with constrained decoding.
Plugin references never reach the model as identities: the host rewrites every`@mention` to an opaque `<alias>` token before tokenization and substitutes thereal one back by position. So an unseen plugin generalizes for free, and thevocabulary does not grow with the plugin registry.
## Results
Scored as exact-match on the fully rendered command, not on tags.
| | in-distribution | **held-out phrasing** ||---|---|---|| previous model (51k-param conv net, from scratch) | 98.2% | **46.5%** || **this model** | 100% | **91.5%** |
The two columns matter more than the numbers. The in-distribution set isauthored from the same case list the training templates come from, so a highscore there means the model recalls its templates. The held-out set is 71 caseshand-written from the command list alone, in the register people actually type:lowercase, filler, contractions, typos. That is the number that predictsbehaviour on input nobody has seen.
The previous model had no language prior — trained from scratch on syntheticEnglish, it named tracks after whichever word sat in the name position duringtraining:
```"can you mute the guitar" -> track(name="Can You").track.set(mute=true)"push Keys up to 2 dB" -> track(name="Push").track.set(volume_db=2)"the bass needs @pro_q_3" -> track(name="Bass Needs").track.set(colour="None")```
Politeness wrappers scored 10%. With a pretrained encoder they score 100%.
## Files
| file | size | what ||---|---|---|| `command_model.onnx` | 442 MB | encoder + intent head + slot head, one graph, opset 17 || `tokenizer.json` | 8 MB | HF fast tokenizer, including the `<alias>` special tokens || `maps.json` | 1 KB | intent and BIO tag id maps |
Inputs are `input_ids` and `attention_mask`, both `int64 [batch, seq]` withdynamic sequence length. Outputs are `intent_logits [batch, 38]` and`slot_logits [batch, seq, 18]`.
## Quantization warning
The embedding is int8; **the attention and FFN deliberately are not.**
| build | size | accuracy ||---|---|---|| fp32 | 736 MB | 96.5% || int8 embedding only (this) | 442 MB | 96.1% || int8 everything | 538 MB | **0.9%** |
DeBERTa-v3's disentangled attention is quantization-hostile. Running`quantize_dynamic` over the whole graph produces a model that loads, runs atfull speed, and emits garbage. If you re-quantize this, re-measure it.
## Usage
Two details will cost you accuracy if you get them wrong.
**Words, not subwords.** The tags are per word, and the deterministicreconstructor consumes per-word tags. Label the first subword of each word andread the tag back at that same index. Reading tags positionally shifts everytag after the first multi-piece word — it still produces plausible-lookingoutput, so it fails quietly.
**The alias tokens must stay atomic.** `<alias>` and `<alias.param>` areregistered as additional special tokens. If your tokenizer splits them into`<`, `alias`, `>`, every plugin slot breaks.
```pythonfrom transformers import AutoTokenizerimport onnxruntime as ort, numpy as np
tok = AutoTokenizer.from_pretrained("microsoft/deberta-v3-base", from_slow=True)tok.add_special_tokens({"additional_special_tokens": ["<alias>", "<alias.param>"]})sess = ort.InferenceSession("command_model.onnx")
words = ["put", "<alias>", "on", "a", "new", "track"]enc = tok(words, is_split_into_words=True, return_tensors="np")intent_logits, slot_logits = sess.run(None, { "input_ids": enc["input_ids"].astype(np.int64), "attention_mask": enc["attention_mask"].astype(np.int64),})```
A reference implementation in C++ (ONNX Runtime plus a hand-writtenSentencePiece Unigram tokenizer) is in `magda/agents/command_model_onnx.cpp`and `unigram_tokenizer.cpp` in the MAGDA repo.
## Training
24,000 template-generated English examples with LLM-paraphrased inputs, 4epochs, lr 3e-5 for the encoder and 1e-3 for the two heads. Checkpoints areselected on a hand-authored held-out set, never on the reported one — theval split is drawn from the same templates as training and saturates at 100%after one epoch, which makes it useless for ranking checkpoints.
## Limitations
- **English only.** The word splitter in front of the model is ASCII-only, so non-English input reaches it as an empty sequence. This is a limitation of the surrounding pipeline, not the encoder, which is multilingual-capable.- **Plugin references need the `@` sigil.** `track with @serum` works; `track with serum` does not, and degrades into an unrelated command rather than failing cleanly.- **Closed command set.** 38 commands. It cannot express anything outside them and will map an unsupported request onto the nearest one it has.- Sentences where the verb trails its object ("i don't need the perc track anymore, delete it") are a known weak spot.
## License
MIT, following `microsoft/deberta-v3-base`.README.mdAdded+157