Precision, recall, F1 and masked perplexity
Compute classification metrics and token-weighted perplexity.
What’s going wrong
Original LLM Architecture lab. Implement the missing behavior in solve(data) and keep the supplied JSON interface. Use Python’s standard library.
Input examples contains truth (binary), score, and token_nll (negative log-likelihoods, with null for ignored tokens). Classify score ≥ threshold as positive. Return confusion {tp,fp,tn,fn}, precision, recall, f1 and perplexity. Zero metric denominators give zero. Perplexity is exp(mean NLL across all non-null tokens) or null when there are none. Supplied mean NLL is within the floating-point exponential range.
Small, well-formed JSON inputs and standard-library Python arithmetic. Keep full precision during computation. The supplied output wrapper rounds results to six decimal places.
Expected behavior
Compute classification metrics and token-weighted perplexity.
Reproduction
{"threshold":0.5,"examples":[{"truth":1,"score":0.9,"token_nll":[0,1]},{"truth":0,"score":0.6,"token_nll":[]},{"truth":0,"score":0.1,"token_nll":[2]},{"truth":1,"score":0.1,"token_nll":[null,1,2]}]}{"confusion":{"tp":1,"fp":1,"tn":1,"fn":1},"precision":0.5,"recall":0.5,"f1":0.5,"perplexity":3.320117}{"threshold":0.5,"examples":[]}{"confusion":{"tp":0,"fp":0,"tn":0,"fn":0},"precision":0,"recall":0,"f1":0,"perplexity":null}{"threshold":0.5,"examples":[{"truth":1,"score":0.5,"token_nll":[0.5]}]}{"confusion":{"tp":1,"fp":0,"tn":0,"fn":0},"precision":1,"recall":1,"f1":1,"perplexity":1.648721}Before you begin
- Python functions, lists and dictionaries
Need a nudge?
Reveal one investigation hint at a time. Try each clue before opening the next.
Read the report, then sign in to start your investigation.