TriviaQA
Tests how many trivia-quiz questions a model can answer from the facts it memorised during training.
At a glance
What it tests
Trivia questions are the ideal probe of what a language model memorised: they are written by people who like obscure facts, the answers are short entities, and each answer comes with a list of aliases so 'JFK' and 'John F. Kennedy' both count.
There are two games here. Reading comprehension: the model gets evidence documents (which may or may not contain the answer, since they were collected after the fact). Closed-book: the model gets the question only. GPT-3 used the closed-book setting and reached 71.2% few-shot, matching the fine-tuned open-domain SOTA of the time.
Because frontier models keep reporting it, TriviaQA is one of the few GPT-3 benchmarks with a continuous record through to today (Llama 3.1 405B: 91.8%).
Examples
Items from the dataset (or representative items where the originals are not freely redistributable).
Reported results
Scores reported on this benchmark, with the evaluation setting each one used.
| Setting | Reported | Context |
|---|---|---|
| Few-shot (64 examples), closed-book, Wikipedia dev split | 71.2 EM | Zero-shot 64.3, one-shot 68.0; fine-tuned open-domain SOTA then 68.0 (RAG); T5-11B+SSM closed-book 60.5 |
State of the art
Retrieval-augmented Atlas 89.4 on unfiltered test. Splits and shot counts differ between papers; compare carefully. Source: huggingface.co ↗ · checked October 2026.
Quickstart
Load the benchmark and score a Hugging Face causal LM on it in a few lines.
pip install -U datasets transformers evaluate lm-eval sacrebleu rouge-score scikit-learn
question, answer (dict with value, aliases, normalized_aliases). Use `rc.nocontext` for closed-book, `rc` for evidence documents.
from datasets import load_dataset ds = load_dataset("mandarjoshi/trivia_qa", "rc.nocontext", split="validation") print(ds) # columns: question, answer (dict with value, aliases, normalized_aliases) print(ds[0])
Two helpers cover every benchmark in this collection: loglik for anything multiple-choice (score each option, pick the highest) and generate for anything free-form. Swap MODEL for whatever you are evaluating.
import torch from transformers import AutoTokenizer, AutoModelForCausalLM MODEL = "gpt2" # or "Qwen/Qwen2.5-1.5B", "meta-llama/Llama-3.2-1B", … tok = AutoTokenizer.from_pretrained(MODEL); model = AutoModelForCausalLM.from_pretrained(MODEL, torch_dtype=torch.bfloat16).eval().to("cuda") @torch.no_grad() def loglik(context, continuation): """Sum of log-probs of `continuation` tokens given `context` — the standard multiple-choice scorer.""" ids = tok(context + continuation, return_tensors="pt").input_ids.to(model.device) n_ctx = len(tok(context).input_ids) logp = model(ids).logits.log_softmax(-1)[0, :-1] return logp.gather(1, ids[0, 1:, None])[n_ctx - 1:].sum().item() @torch.no_grad() def generate(prompt, max_new_tokens=32, stop=None): ids = tok(prompt, return_tensors="pt").input_ids.to(model.device) out = model.generate(ids, max_new_tokens=max_new_tokens, do_sample=False, pad_token_id=tok.eos_token_id) text = tok.decode(out[0, ids.shape[1]:], skip_special_tokens=True) return text.split(stop)[0] if stop else text
import re, string def norm(s): s = s.lower(); s = "".join(c for c in s if c not in string.punctuation) s = re.sub(r"\b(a|an|the)\b", " ", s); return " ".join(s.split()) FEW = "Q: who wrote the novel 1984?\nA: George Orwell\n\nQ: what is the capital of australia?\nA: Canberra\n\n" em = 0 for ex in ds: golds = ex.get("answer") or ex.get("answers") or ex["answer"]["aliases"] pred = generate(FEW + f"Q: {ex['question']}\nA:", max_new_tokens=16, stop="\n") em += int(norm(pred) in {norm(g) for g in golds}) print("exact match", em / len(ds))
Task name(s): triviaqa. The harness reproduces the GPT-3 prompt formats and reports the standard metric.
lm_eval --model hf --model_args pretrained=gpt2,dtype=bfloat16 \
--tasks triviaqa --num_fewshot 0 --batch_size auto --output_path results/Pitfalls
- Match against `normalized_aliases`, not just `value`.
- 'rc' vs 'unfiltered' vs 'wiki' splits are not interchangeable; Llama reports Wiki, GPT-3 reported the Wikipedia dev split of rc.
- Modern models have almost certainly seen the test questions in pre-training (the questions come from public quiz sites).
References
- Paper (arXiv 1705.03551)https://arxiv.org/abs/1705.03551
- Dataset pagehttps://nlp.cs.washington.edu/triviaqa/
- Hugging Facehttps://huggingface.co/datasets/mandarjoshi/trivia_qa