Views
No views yet
openai/privacy-filter (1.4B sparse MoE) and Snowflake/snowflake-arctic-embed-l-v2.0 (568M). Accepts any entity label at inference time with no retraining -- type in "dinosaur species", "gene mutation", or "spell name" and it just works.hidden -> Linear -> logits, it computes hidden . label_embedding -> score. The label embedding comes from a separate encoder that reads the label's natural language description.4x Label text --> [Arctic-embed-l (568M)] --> (1024,) --> [Proj 1024->640] --+
"beginning of email" |-- (4, 640) label matrix
"continuation of email" |
"end of email" |
"complete email" +
|
Input text --> [OpenAI NER backbone (1.4B MoE)] --> (T, 640) -- dot product --> Viterbi --> BIOES tags| Component | Model | Params | Role |
|---|---|---|---|
| NER backbone | openai/privacy-filter | 1.4B (sparse MoE, ~50M active) | Per-token hidden states (T, 640) |
| Label encoder | snowflake-arctic-embed-l-v2.0 | 568M (XLM-RoBERTa) | Encodes label descriptions -> (1024,) CLS vectors |
| Projection | nn.Linear(1024, 640) | 655K | Bridges Arctic's 1024-dim to backbone's 640-dim |
| O-embed | nn.Parameter(640) | 640 | Learnable embedding for the "no entity" tag |
| Viterbi decoder | Dynamic transition matrix | -- | Enforces valid BIOES sequences at decode time |
"beginning of {label}" -- entity start"continuation of {label}" -- middle tokens"end of {label}" -- entity end"complete {label}" -- single-token entitieshidden = (1 - sigmoid(alpha)) * hidden + sigmoid(alpha) * (hidden @ VtV / N)original/ # PyTorch (full precision, bf16)
arctic/ # Fine-tuned Arctic-embed-l encoder
config.json
model.safetensors # 1.1 GB
tokenizer.json
tokenizer_config.json
backbone/ # Fine-tuned OpenAI NER backbone
config.json
model.safetensors # 2.6 GB
tokenizer.json
tokenizer_config.json
label_encoder_extra.pt # 13 MB -- projection, O-embed, prefix projections, alphas
onnx/ # ONNX (quantized, for browser/edge inference)
arctic/
encoder_int8.onnx # 542 MB -- int8 quantized Arctic encoder
projection.npz # 2.6 MB -- projection weights + O-embed
tokenizer.json # Arctic tokenizer (XLMRobertaTokenizer)
tokenizer_config.json
backbone/
model_quantized_hidden.onnx # 159 KB -- graph only
model_quantized.onnx_data # 1.6 GB -- int8 quantized backbone weights
tokenizer.json # Backbone tokenizer
tokenizer_config.json1import torch
2import torch.nn as nn
3from transformers import AutoModelForTokenClassification, AutoModel, AutoTokenizer
4
5TEMPLATES = {
6 "B": "beginning of {label}",
7 "I": "continuation of {label}",
8 "E": "end of {label}",
9 "S": "complete {label}",
10}
11
12# Load models (download original/ folder from this repo)
13backbone_model = AutoModelForTokenClassification.from_pretrained(
14 "path/to/original/backbone", trust_remote_code=True, dtype=torch.float32
15)
16arctic_model = AutoModel.from_pretrained(
17 "path/to/original/arctic", dtype=torch.float32
18)
19extra = torch.load("path/to/original/label_encoder_extra.pt", map_location="cpu", weights_only=True)
20
21bb_tok = AutoTokenizer.from_pretrained("path/to/original/backbone", trust_remote_code=True)
22arctic_tok = AutoTokenizer.from_pretrained("path/to/original/arctic")
23
24# Build projection layer
25proj = nn.Linear(1024, 640)
26proj.weight.data = extra["proj.weight"]
27proj.bias.data = extra["proj.bias"]
28o_embed = extra["o_embed"] # (640,)
29
30# Define your labels -- any text works
31labels = ["dinosaur species", "geological period", "continent"]
32text = "Tyrannosaurus Rex lived during the late Cretaceous period in North America"
33
34# Encode labels
35label_texts = []
36for label in labels:
37 for pfx in ("B", "I", "E", "S"):
38 label_texts.append(TEMPLATES[pfx].format(label=label))
39
40le_enc = arctic_tok(label_texts, padding=True, truncation=True, max_length=32, return_tensors="pt")
41with torch.no_grad():
42 out = arctic_model(le_enc["input_ids"], le_enc["attention_mask"])
43 cls_vecs = out.last_hidden_state[:, 0] # (N*4, 1024)
44 projected = proj(cls_vecs) # (N*4, 640)
45 embeds = torch.cat([o_embed.unsqueeze(0), projected]) # (1 + N*4, 640)
46
47# Encode text and get hidden states
48enc = bb_tok(text, add_special_tokens=False, return_tensors="pt")
49
50# Hook into backbone to get pre-classifier hidden states
51hidden = None
52for name, m in backbone_model.named_modules():
53 if isinstance(m, nn.Linear) and m.out_features == backbone_model.config.num_labels:
54 def hook(module, args):
55 nonlocal hidden
56 hidden = args[0]
57 m.register_forward_pre_hook(hook)
58 break
59
60with torch.no_grad():
61 backbone_model(input_ids=enc["input_ids"], attention_mask=torch.ones_like(enc["input_ids"]))
62
63# Score and decode
64scores = hidden[0] @ embeds.T # (T, 1 + N*4)
65tags = scores.argmax(dim=-1).tolist() # or use Viterbi for valid BIOES sequencesonnx/ folder contains int8-quantized models for browser inference via ONNX Runtime Web:1import * as ort from 'onnxruntime-web';
2
3// Backbone MUST use WASM (fp32) -- WebGPU uses fp16 internally which
4// overflows during RMS norm (pre-norm values ~7000, squared = 49M > fp16 max 65504)
5const bb = await ort.InferenceSession.create(bbOnnxUrl, {
6 executionProviders: ['wasm'],
7 externalData: [{ data: bbDataBuf, path: 'model_quantized.onnx_data' }],
8});
9
10// Arctic label encoder can use WebGPU (values stay in safe fp16 range)
11const arctic = await ort.InferenceSession.create(arcticOnnxUrl, {
12 executionProviders: ['webgpu', 'wasm'],
13});
14
15// Load projection weights from projection.npz
16// Contains: proj_w (640, 1024), proj_b (640,), o_embed (640,)
17const projNpz = await parseNpz(await fetch(projectionNpzUrl).then(r => r.arrayBuffer()));
18
19// Tokenize labels using BIOES templates
20const TEMPLATES = {B:'beginning of {l}', I:'continuation of {l}', E:'end of {l}', S:'complete {l}'};
21// For each label, encode 4 template strings through Arctic -> project -> concat with O-embed
22// Then: scores = hidden @ embeds.T, decode with Viterbi| Test | Domain | Tokens | Time | Tok/s |
|---|---|---|---|---|
| C2 infra | Cybersecurity | 30 | 911ms | 32.9 |
| Leaked secrets | Security | 45 | 321ms | 140.2 |
| CVE disclosure | Security | 34 | 270ms | 125.9 |
| Contact info | PII | 28 | 170ms | 164.6 |
| Financial IDs | PII | 29 | 138ms | 209.6 |
| Dinosaurs | Science | 36 | 209ms | 172.3 |
| Basketball | Sports | 24 | 143ms | 168.3 |
| Classical music | Arts | 18 | 115ms | 156.8 |
| Recipe | General | 26 | 130ms | 200.2 |
| Oncology | Medical | 30 | 135ms | 222.6 |
| Space | Science | 32 | 127ms | 251.6 |
| Fantasy writing | Creative | 35 | 121ms | 288.4 |
| Contract | Legal | 36 | 140ms | 257.9 |
| Car specs | Automotive | 45 | 147ms | 306.9 |
| Negative (no entities) | Control | 18 | 113ms | 159.9 |