Sub topic 2
Designing a label schema
This chapter assumes you know basic Python and have seen text classification and named entity recognition (NER). You don't need any agreement statistics yet. Later chapters measure how well annotators agree, and this chapter explains why the schema you design here limits that agreement.
What a label schema is
A label schema is the formal list of labels annotators may assign, plus the rules for how they may assign them. It answers four questions:
- What is the unit of annotation: a document, a sentence, a token, or a span of characters?
- How many labels can one unit receive: exactly one, several, or a position on a scale?
- Which labels exist, and what is each one called?
- What happens when no label fits?
The schema is a different thing from the guidelines. The schema is the structure of the answer space. The guidelines, covered in the next chapter, explain how to decide which answer is correct. A badly designed schema cannot be rescued by good guidelines, because annotators will still be forced to pick from options that don't fit the data.
Choose the label type first
The label type follows from the task and from how you will use the data. Pick it before you pick label names.
| Label type | Annotator output | Example task | Typical agreement measure |
|---|---|---|---|
| Single-label (multi-class) | One label per item | Sentiment: pos, neu, neg | Cohen's or Fleiss' kappa |
| Multi-label | A set of labels per item | Topic tags on a news article | Per-label kappa, or Krippendorff's alpha with a set distance |
| Ordinal | A value on an ordered scale | Rating 1 to 5 | Weighted kappa, Krippendorff's alpha |
| Span | Start, end, and label | Named entities | Span-level F1 |
| Relation | A link between two spans plus a label | Person works for organization | F1 over (head, tail, label) triples |
Choosing the type is a trade-off. A multi-label schema is more faithful when texts really mix topics, but it is harder to measure and slower to annotate. A single-label schema is easier on both counts, but it forces annotators to invent a tie-breaking rule for mixed texts.
Four properties of a good label set
Mutually exclusive
In a single-label task, two labels should rarely apply to the same item. If "complaint" and "negative sentiment" overlap heavily, annotators will split between them and your agreement will drop. The cause is the overlap in the schema. The annotators are not careless.
Exhaustive, with an escape label
Every item needs somewhere to go. Add an explicit fallback such as other or unclear. Without one, annotators pick an arbitrary label for items that fit nowhere, and that noise is hard to detect afterwards. A separate unclear or not_applicable label also lets you filter out bad items such as truncated text or the wrong language.
Right-grained
Too few labels merge distinct phenomena. Too many labels make annotators hesitate and fragment the data into classes with a handful of examples each. A useful rule is to start coarse. You can split a label later by reannotating only the items that carry it. Merging fine labels back together is easier still, but it throws away annotation effort you already paid for.
Decidable from the text
Each label should be something an annotator can decide from the item alone. A label like "the author is being sarcastic" often depends on context the annotator does not have. Either provide the context (the parent post, the speaker) or drop the label.
Common schema errors
- Mixing dimensions in one label set. A set like
positive, negative, question, spammixes sentiment, speech act, and quality. Split it into separate annotation questions. - Labels defined by the model's needs, not the text's features. If you can't explain a label from the text, annotators can't apply it consistently.
- Hidden hierarchy. If
sportshas childrenfootballandtennis, say so. Then annotators who disagree at the leaf level can still agree at the parent level, and you can report agreement at both levels. - Numeric scales with unclear anchors. A 1 to 5 scale where only 1 and 5 are described will give each annotator a different private meaning for 2, 3, and 4. Describe every point or use fewer points.
- Unstable boundaries for spans. For NER, decide in the schema whether titles ("Dr."), determiners ("the"), and nested entities are included. Otherwise, matching spans will almost never agree exactly.
Why the schema sets the ceiling on agreement
Chance agreement depends on the schema. With two labels, annotators who guess agree about half the time. With ten labels, guessing agrees far less often, so the same observed agreement is more impressive. A skewed label distribution has the opposite effect. If 90% of items are neg, guessing alone produces high agreement. You will see in the chapters on chance agreement and kappa how these facts enter the formulas. For now, treat the number of labels and their expected frequencies as design decisions that affect how you will interpret your results.
Writing the schema as code
A schema kept only in a document drifts. Encode it so that annotation exports can be validated automatically. The following example is self-contained and validates single-label and multi-label annotations.
from dataclasses import dataclass
@dataclass(frozen=True)
class LabelSchema:
name: str
version: str
labels: frozenset
multi_label: bool = False
def validate(self, annotation):
"""Return a list of problems; an empty list means valid."""
if self.multi_label:
if not isinstance(annotation, (list, set, tuple)) or not annotation:
return ["multi-label annotation must be a non-empty collection"]
values = list(annotation)
else:
if not isinstance(annotation, str):
return ["single-label annotation must be one string"]
values = [annotation]
return [f"unknown label: {v!r}" for v in values if v not in self.labels]
sentiment = LabelSchema(
name="sentiment",
version="1.1",
labels=frozenset({"pos", "neu", "neg", "unclear"}),
)
topics = LabelSchema(
name="topics",
version="1.0",
labels=frozenset({"sports", "politics", "tech", "other"}),
multi_label=True,
)
print(sentiment.validate("pos"))
print(sentiment.validate("positive"))
print(topics.validate(["tech", "politics"]))
print(topics.validate([]))Running it prints:
[]
["unknown label: 'positive'"]
[]
['multi-label annotation must be a non-empty collection']Validation catches typos and stray labels before you compute any agreement score. An unnoticed positive next to pos would otherwise count as a disagreement between two annotators who meant the same thing.
Versioning and revising the schema
Expect to revise the schema after the pilot round. Keep a short changelog with each version: what changed, why, and which items need reannotation. Typical revisions are:
- Merging two labels annotators cannot separate.
- Adding an escape label for a recurring kind of item.
- Splitting a label that is too broad and contains clearly distinct cases.
- Clarifying span boundary rules.
Summary of decisions to make
Before annotation starts, you should be able to state: the unit of annotation, the label type, the full label list with an escape label, any hierarchy among labels, the rules for span boundaries if relevant, and the schema version number. If any of these is missing, expect it to show up later as low agreement.
Exercise
A team labels customer emails with one label from: complaint, refund_request, praise, negative_sentiment, other. In a pilot, two annotators often disagree between complaint and negative_sentiment. Name the schema flaw and give one concrete fix.
Show answer
The labels are not mutually exclusive, and the set mixes two dimensions (the email's purpose and its sentiment). Almost every complaint is also negative, so annotators have no principled way to choose. Fix it by splitting the task into two questions: one single-label question for purpose (complaint, refund_request, praise, other) and one for sentiment (pos, neu, neg, unclear). Alternatively, drop negative_sentiment if sentiment is not needed.
Exercise
Why does the schema include an unclear label even if you plan to discard those items later?
Show answer
Without it, annotators must force an arbitrary label onto items that don't fit, which adds noise that looks like real data. With it, you can measure how often items are problematic, exclude them from agreement and training, and find systematic problems such as truncated text.