TriviaQA

TriviaQA

Tests how many trivia-quiz questions a model can answer from the facts it memorised during training.

Released May 2017 Metric TriviaQA-Wiki exact match (5-shot) SOTA 91.8 · Llama 3.1 405B (2024)
01

At a glance

Task
Factoid QA; evaluated with or without evidence documents
Size
95k Q/A pairs, 650k evidence documents; 'rc' (Wikipedia/web) and 'unfiltered' settings
Metric
Exact match and F1 against aliases of the gold entity
Source
Trivia and quiz-league websites; evidence gathered afterwards by search
Licence
Apache 2.0
TriviaQA: A Large Scale Distantly Supervised Challenge Dataset for Reading Comprehension
Joshi, Choi, Weld, Zettlemoyer · ACL 2017
Read the paper ↗ Hugging Face ↗
02

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%).

03

Examples

Items from the dataset (or representative items where the originals are not freely redistributable).

Question
Which American-born Sinclair won the Nobel Prize for Literature in 1930?
AnswerSinclair Lewis (aliases: Harry Sinclair Lewis, Lewis, Sinclair)
Question
Where in England was Dame Judi Dench born?
AnswerYork
Question
What is the name of the hotel in Stephen King's The Shining?
AnswerThe Overlook Hotel
04

Reported results

Scores reported on this benchmark, with the evaluation setting each one used.

SettingReportedContext
Few-shot (64 examples), closed-book, Wikipedia dev split71.2 EMZero-shot 64.3, one-shot 68.0; fine-tuned open-domain SOTA then 68.0 (RAG); T5-11B+SSM closed-book 60.5
05

State of the art

Best known · TriviaQA-Wiki exact match (5-shot)
91.8
✓ saturated · at or above human level
Model
Llama 3.1 405B (base)
2024
Human baseline
~80 (paper estimate on rc split)

Retrieval-augmented Atlas 89.4 on unfiltered test. Splits and shot counts differ between papers; compare carefully. Source: huggingface.co ↗ · checked October 2026.

06

Quickstart

Load the benchmark and score a Hugging Face causal LM on it in a few lines.

1Install
shell
pip install -U datasets transformers evaluate lm-eval sacrebleu rouge-score scikit-learn
2Load the data

question, answer (dict with value, aliases, normalized_aliases). Use `rc.nocontext` for closed-book, `rc` for evidence documents.

python · load
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])
3Score a model

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.

python · helpers
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
python · evaluate
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))
4Or use lm-evaluation-harness

Task name(s): triviaqa. The harness reproduces the GPT-3 prompt formats and reports the standard metric.

shell
lm_eval --model hf --model_args pretrained=gpt2,dtype=bfloat16 \
        --tasks triviaqa --num_fewshot 0 --batch_size auto --output_path results/
07

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).
08

References