Skip to content

Treat a language model like any other model

Label text with a language model, then score it honestly. Run a pilot against known labels, keep examples out of the rows being scored, and compare it with cheaper models on the same folds.

Advanced ~14 min11 steps

You will be able to

  • Run a labeling pilot, and read accuracy, macro-F1, kappa and cost per correct label
  • Explain why few-shot examples must come from each fold's training rows
  • Compare a language model with other learners on the same split plan
  • Predict when the privacy gate refuses to send text

Read first

01

A classifier with an odd training step

Read

A language model can sort text into your labels with no training at all (zero-shot), or from a handful of examples in the promptFew-shot promptingGiving a language model a handful of labeled examples in the prompt; zero-shot gives it none. (few-shot). It looks like a shortcut, and it might be one, but it's still a model.

So it gets the same questions as any other model. How good is it on rows it hasn't seen? Better than a simple baseline? And at what cost?

CodeSplash offers this in two places: Label with AI, from a text column's header in a saved dataset, and LLM classifier in Predict.

02

Is 90% good?

Predict

Predict first

On a pilot, the model gets 90% of support tickets right. Is that good?

Yes: 90% is highIt depends on how common each label isNo: under 95% is poor
Reveal

It depends. If 90% of tickets carry one label, always answering that label also scores 90%. Accuracy can't tell those two models apart. That's why a pilot also reports macro-F1, which weighs each label equally, and Cohen's kappaCohen's kappaAgreement between raters beyond what chance would produce; 0 is chance level, 1 is perfect., which discounts chance agreement.

03

See it with kappa

Explore

Think of the model as one rater and your known labels as the other.

GExplorable · The kappa paradox

How can two raters agree 90% of the time and still get a low kappa?

Guess Cohen's κ for this table.

0.00
How sure?
0.90
0.92
Rater 2: yesRater 2: no
Rater 1: yes875
Rater 1: no53

Green cells: agreement. κ = (agreement − chance) / (1 − chance), with chance = 85%.

Commit your prediction above to see the result

Make your prediction first; the figure appears when you commit.

Make your prediction to see the result.

Keep agreement high, and raise the share rated "yes". Then press a rare category. Agreement stays high, and kappa falls toward zero.

04

Pilot first

Read

Label with AI begins with a pilot on a stratified sample of rows that already have known labels. It reports accuracy, macro-F1, kappa, a confusion matrix and the cost per correct label. An answer of "unsure", or no answer, counts as wrong.

If the pilot looks good, a full run labels every distinct text and saves a new version of the dataset, with <column>_label and <column>_label_confidence.

Answers are cached per text, so a rerun sends nothing it has already sent.

05

Where do the examples come from?

Predict

Predict first

You pick the ten clearest examples from the whole table, and put them in the prompt. Then you score the model on the whole table. What goes wrong?

Nothing: examples are only hintsThe score is inflated, as the answers are in the promptThe model refuses to answer
Reveal

The score is inflated. Those examples are training data, and now they're also test data, so the model can read those answers off the prompt. Choosing them by looking at the whole table also tells you things about the test rows. This is leakageData leakageInformation from the validation data or the future seeps into training, so scores look better than reality., in a new form.

06

See leakage

Explore

The form differs, but the mechanism is the same as in any other pipeline.

DExplorable · Leakage detective

Why does a model that scores brilliantly in testing fail on real data?

Read the pipeline on the left. Will its cross-validation score overstate real-world accuracy by more than 6 points?

How sure?

The pipeline

200
60
Simulating…

Commit your prediction above to see the result

Make your prediction first; the figure appears when you commit.

Make your prediction to see the result.

Compare Pick features on all rows, then cross-validate with Pick features inside each fold, and watch the gap between cross-validated accuracy and accuracy on new data.

In the LLM classifier run, each fold's examples come only from that fold's training rows, and the locked test rows use examples from the training rows. A row is never shown as an example while it's being predicted.

07

On the leaderboard

Read

An LLM classifierLLM classifierA language model that labels text, scored on the same folds as your other models. run uses the experiment's own split plan, so it's scored by the same metrics, on the same folds, as your other learners. That makes the comparison fair, and paired.

So train a cheap baseline first. A linear model costs nothing per row and returns the same answer every time. The language model has to beat it by enough to pay for its calls.

A middle path is text embeddingsText embeddingA list of numbers from a language model that places similar texts close together, usable as model features. as features, from a local model. Text stays on your machine, and PCA is fitted on each fold's training rows.

08

Will the text be sent?

Reflect

Unlike an explanation, labeling sends row values: the text itself. So a gate decides:

SituationResult
The project is Metadata onlyRefused
The column is marked Exclude or SensitiveRefused
Local models only, with a cloud modelRefused
Allow samples or Allow full data, with a cloud modelUp to a row limit, with personal details masked when the project masks them

Think of a text column you'd like to label. Who wrote it, and did they expect it to leave? What will be sent shows you exactly what would go.

09

Check your understanding

Checkpoint

Check yourself

You're running 5-fold validation with few-shot examples. Where must the examples for fold 3's test rows come from?

Show the answer

Answer: a

Examples are training data. If they include rows being scored, the validation score no longer predicts performance on new rows.

Check yourself

Observed agreement is 0.80, and agreement expected by chance is 0.50. What is Cohen's kappa?

Show the answer

Answer: 0.6

κ = (0.80 − 0.50) / (1 − 0.50) = 0.60.

Check yourself

Your project is Metadata only, and you ask a cloud model to label a text column. What happens?

Show the answer

Answer: a

Metadata-only sends no rows, and labeling can't work without them. The message tells you which modes would allow it.

10

Do it on your own data

In the app

In a saved dataset, open a text column's header menu and choose Label with AI. Write your labels, pick a column of known labels, and run a pilot. Then check its numbers by hand from a file of known and predicted labels.

Python
import pandas as pd
from sklearn.metrics import accuracy_score, cohen_kappa_score, confusion_matrix, f1_score

d = pd.read_csv("pilot.csv")  # columns: known, predicted
print("accuracy", round(accuracy_score(d["known"], d["predicted"]), 3))
print("macro F1", round(f1_score(d["known"], d["predicted"], average="macro"), 3))
print("kappa", round(cohen_kappa_score(d["known"], d["predicted"]), 3))
print(confusion_matrix(d["known"], d["predicted"]))
R
d <- read.csv("pilot.csv")  # columns: known, predicted
labels <- sort(unique(c(d$known, d$predicted)))
tab <- table(factor(d$known, labels), factor(d$predicted, labels))

po <- sum(diag(tab)) / sum(tab)
pe <- sum(rowSums(tab) * colSums(tab)) / sum(tab)^2
f1 <- 2 * diag(tab) / (rowSums(tab) + colSums(tab))

cat("accuracy", round(po, 3), "\n")
cat("macro F1", round(mean(f1), 3), "\n")
cat("kappa", round((po - pe) / (1 - pe), 3), "\n")
tab
11

Recap

Recap
  • A language model used as a classifier gets the same tests as any other model.
  • Accuracy can hide a base rate, so also read macro-F1 and kappa.
  • Few-shot examples are training data: keep them out of the rows being scored.
  • Compare with a cheap baseline on the same folds, and check what the text's authors would expect before you send it.

Concepts in this lesson