--- language: - en license: apache-2.0 base_model: Qwen/Qwen3.5-2B library_name: transformers pipeline_tag: zero-shot-classification inference: false tags: - scientific-papers - taxonomy - classification - science-of-science - probabilities - qwen3_5 --- # paper-classifier-2B-v2 **Classify scientific papers into a user-supplied taxonomy, or judge whether a topic is central to a paper.** Returns probabilities in one forward pass, **without generating text**. Made for [Science Made Readable](https://sciencemadereadable.com). > **Use the supplied v2 helper. List questions MUST put the taxonomy before the paper.** > The [earlier public model](https://huggingface.co/maximerivest/paper-classifier-2B) used a different, > paper-first format. Its helper is **not compatible** with these weights. Yes/no questions intentionally keep > the paper first and the topic afterward. Do not reorder that prompt either. - Size tier: **2B**, derived from [Qwen3.5-2B](https://huggingface.co/Qwen/Qwen3.5-2B). Sibling: [paper-classifier-0.8B-v2](https://huggingface.co/maximerivest/paper-classifier-0.8B-v2). - Standalone **BF16 safetensors**, not a LoRA adapter. Load with `AutoModelForCausalLM`, not `AutoModelForSequenceClassification`. This is not an NLI model; the generic Hugging Face `zero-shot-classification` pipeline is not the supported interface. - Scope: scientific title/abstract classification, custom scientific labels, topic membership. Not a general chat model, embedding model, or reliable classifier for arbitrary non-research text. - Exported weights contain **2,390,384,448 stored parameters** (4.78 GB): the size tier follows the upstream name; the export includes an untied vocabulary-output matrix. - License: **Apache 2.0**, including the inference helpers. Training data and the data-generation recipe are not published with this release. No claim of open training-data availability is made. ## Quick start: Transformers ```bash pip install "transformers==5.3.0" torch huggingface_hub safetensors ``` The snippets fetch a small Python helper explicitly; inspect it before importing, as with any downloaded code. The model itself does not require `trust_remote_code=True`. Pin `revision="v2.0.0"` for reproducibility. ```python from huggingface_hub import hf_hub_download import importlib.util repo = "maximerivest/paper-classifier-2B-v2" revision = "v2.0.0" path = hf_hub_download(repo, "paper_classifier.py", revision=revision) spec = importlib.util.spec_from_file_location("paper_classifier", path) pc = importlib.util.module_from_spec(spec) spec.loader.exec_module(pc) clf = pc.PaperClassifier(repo, revision=revision) paper = pc.paper_text( "Habitat fragmentation and tropical forest birds", "We surveyed bird communities across 40 forest fragments. Species richness " "declined with fragment area and increased with connectivity.", ) print(clf.classify( paper, ["Ecology", "Ornithology", "Particle physics", "Economics"], scheme="Fields of science", )) # Measured with this model (rounding and hardware may change the last digits): # {'Ornithology': 0.724677, 'Ecology': 0.275036, 'Particle physics': 0.000159, 'Economics': 0.000128} print(clf.is_on_topic(paper, "habitat fragmentation")) # approximately 0.999988 ``` CPU loading works with float32 by default, but is slower. On CUDA the default is bfloat16. `batch_size` controls Transformers memory use; lower it if a batch does not fit. The Transformers helper **does not reuse prefix states**. ## API: inputs and outputs ```python classify(paper: str, options: list, scheme: str, question: str, ...) -> dict[str, float] classify_many(papers: list[str], options: list, scheme: str, question: str, ...) -> list[dict[str, float]] is_on_topic(paper: str, topic: str, definition: str | None = None) -> float is_on_topic_many(papers: list[str], topic: str, definition: str | None = None) -> list[float] ``` **Options** are strings, or dictionaries with `name`, optional `about`, optional `parent`, optional `id`: ```python options = [ {"id": "eco", "name": "Ecology", "about": "Organisms, populations and their environment", "parent": "Biology"}, {"id": "opt", "name": "Optics", "about": "Light, optical phenomena and optical methods", "parent": "Physics"}, ] p = clf.classify(paper, options, scheme="My scientific taxonomy") # {"eco": ..., "opt": ...}; keys are IDs if supplied, otherwise option names. p_yes = clf.is_on_topic( paper, "habitat fragmentation", definition="Effects of splitting habitat into smaller or isolated patches; not habitat loss alone.", ) ``` - Choice probabilities sum to one **over the supplied options**. They are relative best-fit probabilities, not independent membership probabilities or a guarantee that any option is appropriate. - Yes/no returns `P(yes | yes, no)` for central topic membership. A paper may be central to several topics. - Names/IDs must be unique. Supply distinct IDs if two options have the same name. - `none_option=True` adds an explicit rejection option, returned under `"__none__"`. Rejection remains unreliable on unfamiliar/non-scientific text; do not treat this switch as a dependable out-of-domain detector. - `orders=3` averages three option orders. It costs three passes and is optional: improvement is not guaranteed. - `describe=False` removes option descriptions; `parents=False` removes parent names. These are explicit quality/speed trade-offs, not automatic reductions made silently by the helper. - The codebook has **562 single-token codes**. This is a token-interface limit, **not** a claim of reliable accuracy with 562 long descriptions. Lists must also fit the prompt budget; most measured long-list tests use 149–176 options. The helper raises on overflow. Shorten descriptions or split the taxonomy; do not truncate away options. - For large hierarchies, classify one level at a time, or classify a feasible leaf list and sum its probabilities into parents. Direct broad-field and hierarchical routing accuracy can be weaker than flat classification. ## Fast bulk use: taxonomy first, shared-prefix caching Use this when many papers share the same taxonomy. The vLLM helper reuses the taxonomy's full-attention and recurrent states; the paper is the changing suffix. It reads final hidden states and projects onto the offered answer codes—no generated tokens and no 128-logprob limit. Tested with **vLLM 0.29.0**. Install a matching supported CUDA/PyTorch build for your platform; keep it in a separate environment if its dependencies conflict with the Transformers-only environment. ```bash pip install "vllm==0.29.0" huggingface_hub safetensors numpy ``` ```python from huggingface_hub import snapshot_download import sys repo = "maximerivest/paper-classifier-2B-v2" revision = "v2.0.0" helpers = snapshot_download(repo, revision=revision, allow_patterns=["paper_classifier.py", "vllm_fast.py"]) sys.path.insert(0, helpers) from vllm_fast import FastPaperClassifier from paper_classifier import paper_text clf = FastPaperClassifier(repo, revision=revision, gpu_memory_utilization=0.8) papers = [ paper_text("Bird diversity in forest fragments", "We measured species richness and habitat connectivity."), paper_text("A liquid xenon dark matter search", "We report limits on weakly interacting massive particles."), ] print(clf.classify_many(papers, ["Ecology", "Particle physics"], scheme="Fields of science")) ``` Prefix reuse benefits repeated taxonomies. It does not make arbitrary new lists free, and yes/no still uses the paper-first prompt. Do not transplant speed/cost numbers from the older public models to this release. Hardware, list length, batch size, cache hits, library version and numerical settings all matter. ## Exact prompt and score contract System message (shared by both tasks, verbatim): ```text You classify scientific papers. You get a paper (its title, and its abstract when available), then a question. For a list of options, answer with the code of the option that best describes the research content of the paper, following the classification's own meaning of each option. For a single topic, answer yes if the topic is a central subject of the paper, else no. On topic: the paper studies the topic itself as a main subject: the phenomenon, its causes, consequences, mechanisms, measurement, methods, or how it is managed, in any system or organism. Not on topic: the topic is absent or only mentioned in passing; or the words mean something else in this paper; or the paper studies a neighbouring subject without studying the topic itself. ``` Choice user message, conceptually: ```text ## Classification: Options: AA.