Views
No views yet
encodr-snrv1-d-base is the ModernBERT-base member of the encodr-SNR ("Signal-to-Noise")
family, trained on labels from DeepSeek-V4-Flash. It's a LoRA adapter (r=16) on top of
answerdotai/ModernBERT-base (149M
params) with a token-classification head, so it is small, fast, and cheap to serve.encodr1/encodr-snrv1-c-base — same base model, GPT-5.6 labels (not yet published)encodr1/encodr-snrv2-d-large — ModernBERT-large, same DeepSeek labels (not yet published)encodr1/encodr-snrv2-c-large — ModernBERT-large, GPT-5.6 labels (not yet published)transformers and peft.1import torch
2from peft import PeftModel
3from transformers import AutoModelForTokenClassification, AutoTokenizer
4
5REPO = "encodr1/encodr-snrv1-d-base"
6BASE = "answerdotai/ModernBERT-base"
7
8tokenizer = AutoTokenizer.from_pretrained(REPO)
9base_model = AutoModelForTokenClassification.from_pretrained(BASE, num_labels=2)
10model = PeftModel.from_pretrained(base_model, REPO).eval()
11
12text = "User: What's the capital of France?\n\nAssistant: The capital of France is Paris."
13words = text.split()
14
15enc = tokenizer(words, is_split_into_words=True, truncation=True, max_length=1536, return_tensors="pt")
16word_ids = enc.word_ids()
17
18with torch.no_grad():
19 logits = model(**enc).logits[0]
20p_keep = torch.softmax(logits, dim=-1)[:, 1] # P(KEEP) per subword token
21
22# average subword scores back up to word level, then threshold at 0.5
23sums, counts = [0.0] * len(words), [0] * len(words)
24for tok_idx, word_id in enumerate(word_ids):
25 if word_id is not None:
26 sums[word_id] += p_keep[tok_idx].item()
27 counts[word_id] += 1
28word_scores = [s / c if c else 1.0 for s, c in zip(sums, counts)]
29
30compressed = " ".join(w for w, s in zip(words, word_scores) if s >= 0.5)
31print(compressed)text.split()),
with every subword of a word sharing that word's label, so score at the word level, not the
raw-token level, to match training.word_scores and keep the top-k for a target
compression ratio (LLMLingua-2 style):1target_keep_ratio = 0.5
2n_keep = max(1, round(len(words) * target_keep_ratio))
3keep_idx = set(sorted(range(len(words)), key=lambda i: word_scores[i], reverse=True)[:n_keep])
4compressed = " ".join(w for i, w in enumerate(words) if i in keep_idx)train_sft
split), extractively compressed by DeepSeek-V4-Flash (via Azure AI Foundry, temperature=0)
under a system prompt that only allows word deletion (no rewriting/paraphrasing/summarizing),
targeting ~60–85% word retention, with User:/Assistant: turn markers always preserved.difflib.SequenceMatcher) between the original
and teacher-compressed text: a word is KEEP if it survives in the same relative position,
DROP otherwise. A hard-keep overlay then force-labels structurally important spans as KEEP
regardless of what the teacher did — regex for URLs, emails, currency, percentages, decimal
numbers, years, dates, filenames, and snake_case/camelCase/PascalCase identifiers, plus
GLiNER NER for person/organization/location/date/product entities.answerdotai/ModernBERT-base (149M params), AutoModelForTokenClassification head (2 labels), fine-tuned via LoRA (PEFT)[Wqkv, Wi, Wo], task_type=TOKEN_CLS, classifier head also trained (modules_to_save=["classifier"])| Metric | Value |
|---|---|
| keep precision | 0.910 |
| keep recall | 0.941 |
| keep F1 | 0.926 |
| accuracy | 0.886 |
| eval loss | 0.280 |
text.split()); text without spaces (e.g. some non-Latin scripts) will not align correctly.answerdotai/ModernBERT-base is also Apache 2.0.