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.
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
A classifier with an odd training step
ReadA 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.
Is 90% good?
PredictPredict first
On a pilot, the model gets 90% of support tickets right. Is that good?
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.
See it with kappa
ExploreThink 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.
| Rater 2: yes | Rater 2: no | |
|---|---|---|
| Rater 1: yes | 87 | 5 |
| Rater 1: no | 5 | 3 |
Green cells: agreement. κ = (agreement − chance) / (1 − chance), with chance = 85%.
Commit your prediction above to see the result
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.
Pilot first
ReadLabel 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.
Where do the examples come from?
PredictPredict 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?
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.
See leakage
ExploreThe 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?
The pipeline
Commit your prediction above to see the result
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.
On the leaderboard
ReadAn 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.
Will the text be sent?
ReflectUnlike an explanation, labeling sends row values: the text itself. So a gate decides:
| Situation | Result |
|---|---|
| The project is Metadata only | Refused |
| The column is marked Exclude or Sensitive | Refused |
| Local models only, with a cloud model | Refused |
| Allow samples or Allow full data, with a cloud model | Up 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.
Check your understanding
CheckpointCheck 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.
Do it on your own data
In the appIn 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.
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"]))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")
tabRecap
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