Project

Is model A really better than model B?

You build a notebook that runs two sentiment models on the same 872 sentences, puts an error bar on each score and on the gap between them, runs the shuffle test, says whether the gap is real and how many sentences it would take to tell, then does the same for two models you pick.

About 3 hours. You need your own computer, with uv; Windows, Linux or a Mac with Apple silicon, since PyTorch no longer ships for Intel Macs; about 2 GB of disk for the packages and the models; or Colab, which needs a Google account.

You build it in the starter, one step at a time. The finished project is there to read when you are stuck.

Get the starterRead the finished project

  1. Part 1

    Two models, one test

    Model A is DistilBERT, trained to say whether a sentence is positive or negative. Its page claims 91.06% right on SST-2's 872 test sentences, short lines from film reviews. Model B starts from BERT, the bigger model DistilBERT was made from, and was trained for the same job: 110 million weights to A's 67 million. Here you run both on the same sentences and see where each one is right.

    UsesProbabilityConditional probability and Bayes' ruleRandom variables and distributionsExpectation and varianceCorrelation

    1. Ask both modelsRun it
    2. Right or wrongYour turn
    3. Four pilesYour turn
    4. Wrong togetherYour turn
    5. Hard for bothRun it

    Open this part in Colab

    When you have run it

    On how many of the 872 sentences do the two models give different answers?

  2. Part 2

    An error bar on every score

    Two scores, 1.49 points apart, from one test of 872 sentences. Here each score gets its error bar by the bootstrap, and then the gap gets its own, drawn on the same sentences for both models. Last, a second score, the surprise, gets one too, and it tells another story.

    UsesExpectation and varianceSamples, averages and the normal distributionCorrelationMaximum likelihoodEntropyCross-entropy and KL divergenceConfidence intervals and the bootstrap

    1. A's error barYour turn
    2. Two standard errorsYour turn
    3. The gap's own barYour turn
    4. Each drawn aloneRun it
    5. A second score: surpriseYour turn
    6. Sure and wrongRun it

    Open this part in Colab

    When you have run it

    What is B's average surprise minus A's, in bits, to two decimal places?

  3. Part 3

    Luck, or a real gap?

    On right answers, the gap's bar runs from about zero to three points. Here the shuffle test asks the same question another way: if the two models were equally good, how often would luck alone give a gap this big? Then you write the verdict, and work out how many sentences it would take to settle it.

    UsesProbabilitySamples, averages and the normal distributionConfidence intervals and the bootstrapA/B tests and p-values

    1. Coin tossesYour turn
    2. The shuffles, drawnRun it
    3. The verdictYour turn
    4. How many sentences?Your turn
    5. Check it by drawingOn your own

    Open this part in Colab

    When you have run it

    How many sentences, to the nearest hundred, would settle B's lead at least 8 times in 10?

  4. Part 4

    Two models of your own

    Now the whole comparison in one function, and two models you pick. You write `compare`, check it on the videos' 200 questions, and then run it on two sentiment models from the Hub. This part is yours: each cell starts empty.

    UsesExpectation and varianceSamples, averages and the normal distributionConfidence intervals and the bootstrapA/B tests and p-values

    1. One functionOn your own
    2. Your two modelsOn your own
    3. Your verdictOn your own

    Open this part in Colab

    When you have run it

    Run your compare on the videos' two models from step 4.1. How many questions would it take for the gap's bar to just reach zero?

Run on Python 3.12, PyTorch 2.15.0, transformers 5.25.0, datasets 5.2.0, NumPy 2.5.5, SciPy 1.18.1, matplotlib 3.11.2. Checked on .