Classify · Papers
File a research paper under its subject area
A repository, a library or a reviewer pool has to file every incoming paper under a subject. The title and the abstract are all there is to go on. Nenya reads both and names the area. This cookbook also shows the habit that saves you from a bad surprise: look at every label by itself, because a total can hide a label that never works.
- The move
- File a document under one of your subject areas from its title and abstract.
- The model’s role
- It takes the place of the first sort by a person.
- Why it fits
- Abstracts are dense and long (about 1,300 characters here), and the areas overlap. The model reads the whole abstract in one request of about 460 tokens.
- How it goes
- Title and abstract in → the question, the two blocks of text and your areas with a line on each → one area and a confidence → file it, or queue it.
- Payoff
- Measured: 73.2% right on 250 real papers and eight areas, 90.1% on the 60% of papers it was at least 90% sure of. Physics 44 of 46 and mathematics 24 of 26, and quantitative biology 0 of 20: the table that tells you where a person is still needed.
On this page
The data#
250 papers submitted to arXiv on ten days of 2026, each with the primary subject area its authors chose, grouped into arXiv’s eight areas. Titles and abstracts are arXiv metadata (CC0). They are a test set: the model has no training data for this task.
The eight areas, each with a line on what it covers:
Which arXiv subject area is this paper's primary one?
- Computer science: computing, AI and machine learning, software, systems, networks, theory of computation
- Economics: econometrics, economic theory and general economics
- Electrical engineering and systems science: signal, audio, image and video processing; systems and control
- Mathematics: pure and applied mathematics
- Physics: all of physics, including astrophysics, condensed matter, high-energy, nuclear, quantum and mathematical physics
- Quantitative biology: biology studied with quantitative, computational or physical methods
- Quantitative finance: finance studied with quantitative methods: pricing, risk, portfolios, trading
- Statistics: statistical methodology, theory, computation and applicationsSet up#
pip install openai. The API is free and needs no key.
import json
import math
import textwrap
from pathlib import Path
from openai import OpenAI
client = OpenAI(base_url="https://api.contrastivelabs.dev/v1", api_key="none")The recipe#
The classify function of the API page, unchanged.
def classify(question, text, labels, heading="Text", descriptions=None, allow_none=False):
"""(label, confidence)"""
options = "\n".join(f"- {label}: {descriptions[label]}" if descriptions else f"- {label}" for label in labels)
prompt = f"{question}\n\n{heading}:\n{text}\n\nOptions:\n{options}\n\nAnswer with the label only."
if allow_none:
prompt += ' If none of the options fits, answer "none".'
reply = client.chat.completions.create(
model="nenya",
messages=[{"role": "user", "content": prompt}],
temperature=0, # one right answer: do not sample
max_tokens=24,
logprobs=True, # for the confidence
extra_body={"structured_outputs": {"choice": labels + (["none"] if allow_none else [])}},
)
choice = reply.choices[0]
tokens = [t for t in choice.logprobs.content if not t.token.startswith("<|")]
confidence = math.exp(sum(t.logprob for t in tokens))
return choice.message.content, confidenceA paper is two pieces of text. text_of puts the title first and the abstract under a heading of its own, so the model reads Title:, the title, Abstract:, the abstract:
DATA = json.loads((Path(__file__).parent / "data" / "classify-research-papers.json").read_text())
QUESTION = DATA["question"]
AREAS = DATA["labels"] # arXiv's eight subject areas
ABOUT = DATA["descriptions"] # a few words on what each one covers
def text_of(paper):
"""The title, then the abstract under a heading of its own. Sent with heading="Title", this is the layout the
model was trained on, with two blocks of text in place of one."""
return f"{paper['title']}\n\nAbstract:\n{paper['text']}"
print(QUESTION)
for name in AREAS:
print(f"- {name}: {ABOUT[name]}")The request#
paper = DATA["examples"][0]
print(paper["title"])
print(textwrap.fill(paper["text"][:420] + " [...]", 100))
label, confidence = classify(QUESTION, text_of(paper), AREAS, heading="Title", descriptions=ABOUT)
print()
print(f"model: {label} ({confidence:.0%} sure)")
print(f"authors: {paper['label']}")The response#
Pricing Intelligence: Task-Based Learning and Labor Displacement in the AI Economy
What determines the speed of AI-driven labor displacement? I study this question in a microeconomic
model in which users choose between labor and AI to complete tasks of different complexity. Profit-
maximizing AI providers set the price of AI, and AI systems improve through task-specific learning
from deployment. In an initial technological state where labor has the comparative advantage at
complex tasks, the provide [...]
model: Economics (93% sure)
authors: Economics{
"model": "nenya-1",
"choices": [
{
"message": {
"content": "Economics",
"role": "assistant"
},
"finish_reason": "stop",
"logprobs": {
"content": [
{
"token": "E",
"logprob": -0.0729
},
{
"token": "conomics",
"logprob": -0.0003
}
]
}
}
],
"usage": {
"completion_tokens": 3,
"prompt_tokens": 378,
"total_tokens": 381
}
}Six papers#
for paper in DATA["examples"]:
label, confidence = classify(QUESTION, text_of(paper), AREAS, heading="Title", descriptions=ABOUT)
print(f"{label:<44} {confidence:4.0%} {paper['title'][:50]}")Economics 93% Pricing Intelligence: Task-Based Learning and Labo
Quantitative finance 94% Optimal Pricing and Hedging of SOFR Derivatives
Physics 100% Collider Detector Observables from Lattice Spin Sy
Mathematics 100% New examples of affine Calabi-Yau 3-folds with max
Computer science 96% The Future of Software Engineering Conferences: A
Electrical engineering and systems science 94% Stability Analysis of Grid-Following and Grid-FormAll six are the area the authors chose.
Check every label#
Sixty papers taken from the test set without looking at the answers. The first line is the total. The table is what you should read:
sample = DATA["sample"] # 60 papers, taken without looking at the answers
answers = [classify(QUESTION, text_of(paper), AREAS, heading="Title", descriptions=ABOUT)[0] for paper in sample]
right = sum(label == paper["label"] for label, paper in zip(answers, sample))
print(f"{right} of {len(sample)} right ({right / len(sample):.0%})")
print()
for area in AREAS:
said = [label for label, paper in zip(answers, sample) if paper["label"] == area]
print(f"{area:<44} {sum(label == area for label in said):2d} of {len(said):2d}")42 of 60 right (70%)
Computer science 16 of 18
Economics 4 of 6
Electrical engineering and systems science 0 of 1
Mathematics 3 of 4
Physics 13 of 13
Quantitative biology 0 of 8
Quantitative finance 2 of 6
Statistics 4 of 4Physics is right every time, and quantitative biology is never right. A total of 70% tells you neither.
On the whole test set#
All 250 papers, asked exactly as above, one request at a time:
| Right | |
|---|---|
| Area names only | 71.6% (179 of 250) |
| Names with a line on what each covers (this recipe) | 73.2% (183 of 250) |
| Area | Right |
|---|---|
| Physics | 44 of 46 |
| Mathematics | 24 of 26 |
| Computer science | 71 of 78 |
| Economics | 14 of 20 |
| Statistics | 14 of 20 |
| Quantitative finance | 10 of 20 |
| Electrical engineering and systems science | 6 of 20 |
| Quantitative biology | 0 of 20 |
The misses have a direction. Sixteen of the 20 quantitative biology papers and 11 of the 20 electrical engineering papers came back as computer science, and 9 of the 20 quantitative finance papers as economics. A paper on protein property prediction with kernels is biology to its authors and machine learning to the model. The areas overlap, the authors pick one, and the model picks the bigger neighbour.
The confidence helps with the rest:
| Act only when the confidence is at least | Papers you keep | Right among them |
|---|---|---|
| 0.80 | 71.6% | 86.0% |
| 0.90 | 60.4% | 90.1% |
| 0.95 | 50.0% | 90.4% |
Make it yours#
- Run this table on your own labels first. Fifty examples you know the answer to are enough to find a label that does not work.
- For a label that does not work, do one of three things: merge it with the neighbour it is confused with, send everything the model files under that neighbour to a person, or decide it with a rule you trust (the journal, a keyword list) before the model is asked.
- Send two pieces of text as two blocks, the first under the
headingargument and the second under a heading of its own, astext_ofdoes. - Describe the areas. A line each was worth 1.6 points here and 6 points on the complaints, where the names are jargon.
Run it#
pip install openai
curl -O https://contrastivelabs.com/cookbook/classify-research-papers.py
curl --create-dirs -o data/classify-research-papers.json \
https://contrastivelabs.com/cookbook/data/classify-research-papers.json
python classify-research-papers.pyThe file is this page’s code in one piece: classify-research-papers.py. The papers are in data/classify-research-papers.json, each with its arXiv link.