What it is for. Step 1 of the news pipeline of gamug/portfolio-nlp (PLAN D39/D40): the scope of a news body from its
title and its first 800 characters, in four classes: single (one company is the subject), multi (several companies are
cut apart later), sector (about a sector, not a company) and out_of_scope (neither; the pipeline stops there).
Two models, one repository. Both are MoritzLaurer/deberta-v3-base-zeroshot-v2.0@8e7e5af5983a0ddb1a5b45a38b129ab69e2258e8 fine-tuned as an NLI (entailment margin of a hypothesis):
stage_a/: company / sector / not_related, for every body.stage_b/: single / multi, asked only of the bodies stage A calls company.
The hypotheses, the recipe and the data counts are in training_record.json. The step revision stored with every result
(body_scope.classifier_revision) is scope-nli-8ff21e50796b: the hash of that record and of the weight files.365 bodies tagged and reviewed by the project owner (284 + 51 chosen for the rare scopes + 30 whose title names a company
but whose body is not about it): stage A on all, stage B on the 210 company bodies. Title + first 800 characters, 3 epochs,
learning rate 2e-5, batch 16, float32 weights with bf16 autocast, seed 1. The texts are in the project repository
(gold/), not here. Recipe and the story of the choices: docs/scope_training.md.
Held-out 200 bodies the model never trained on, weighted to the corpus by the draw's strata, scored from these weights
through the step's own classifier (scripts/score_scope_heldout_2026_11_11.py): agreement
83.6% [78.1, 88.9] (rules triage 67.2%; paired gain +16.5 [+9.6, +23.4] points); single recall
92.2%, out_of_scope recall 53.0% [32.3, 73.8]. Three fits of this recipe (seed 1) scored 83.0%, 83.6% and 83.6%; this is one seed and not a noise estimate.
out_of_scope is the weak class. In the held-out 200, about half of the out-of-scope bodies are read as single or
multi and continue in the pipeline; the owner accepted this on purpose (a body wrongly kept costs a review, a body wrongly
stopped is lost). How many bodies continue in the corpus is not known. An estimate from a 1,000-body sample said about
6.7% of all bodies, but over the 309,972 unique bodies of the corpus the model calls 49% out_of_scope: 11% of the ok
bodies and 59% of the quarantined ones (those pairs are 79% of the corpus). A read of 50 of the latter found most not about
a company, a few with a company hook and two clear errors. The held-out gold may not represent the quarantined bodies.sector has 7 gold bodies in the held-out 200: its recall is reported, not gated.No token is needed. The function below is the whole classifier.
import json, torch
from huggingface_hub import snapshot_download
from transformers import AutoModelForSequenceClassification, AutoTokenizer
root = snapshot_download("gamug/deberta-v3-news-scope-nli")
rec = json.load(open(f"{root}/training_record.json"))
tok = AutoTokenizer.from_pretrained(f"{root}/stage_a")
A = AutoModelForSequenceClassification.from_pretrained(f"{root}/stage_a").eval()
B = AutoModelForSequenceClassification.from_pretrained(f"{root}/stage_b").eval()
def margins(model, text, stage):
out = {}
for name, hypothesis in rec[stage]["hypotheses"].items():
x = tok(text, hypothesis, truncation="only_first", max_length=rec[stage]["recipe"]["max_length"], return_tensors="pt")
with torch.no_grad():
logits = model(**x).logits[0].float()
out[name] = (logits[0] - logits[1]).item() # entailment minus not-entailment
return out
def scope(title, body):
text = f"{title}. {body[:rec['fragment_chars']]}"
a = margins(A, text, "stage_a")
topic = max(rec["stage_a"]["topics"], key=a.get)
if topic != "company":
return "sector" if topic == "sector" else "out_of_scope"
b = margins(B, text, "stage_b")
return max(rec["stage_b"]["classes"], key=b.get) # "single" or "multi"
print(scope("Apple shares fall", "Apple Inc. said on Tuesday that iPhone sales were weaker than expected."))
The same logic, batched and on the GPU, is src/scope_stage.py of the project repository (gamug/portfolio-nlp); the example above does not need it.
The first upload (commit 5f5b2c27) did not contain the weights because of a script error; use the latest commit, the one
the project's config/scope_model.json names.
stage_a/model.safetensors 738 MBstage_b/model.safetensors 738 MBMoritzLaurer/deberta-v3-base-zeroshot-v2.0