Notes

Conditional Random Field (CRF)

A tagger that decides each word on its own will happily produce impossible output — the middle of a person's name with no beginning, or a determiner followed by another determiner. A conditional random field removes that whole class of error by scoring the entire label sequence at once instead of one position at a time.

What makes it different
A CRF models the probability of the label sequence given the observed words directly, and normalises over all possible label sequences rather than per token. Two consequences follow:

  • Features may look anywhere in the input — the word itself, its suffix, its capitalisation, the two words either side, a gazetteer hit — and because nothing is being generated, they are free to overlap.
  • Transition scores between neighbouring labels are learned, so B-PER → I-PER becomes cheap and O → I-PER effectively impossible.

How it runs
Training maximises the conditional log-likelihood, with the normalising term computed by the forward-backward recursions; decoding picks the highest-scoring sequence with Viterbi. That global normalisation is what sidesteps the label-bias problem of locally normalised alternatives such as the MEMM. The linear-chain form — adjacent labels only — is the one in practical use, through libraries like CRFsuite, and it dominated named-entity recognition and chunking benchmarks before neural encoders arrived.

Why it matters
The idea outlived its era. A BiLSTM-CRF, or a CRF layer stacked on a fine-tuned transformer, is still a standard recipe for span tagging: contextual embeddings predict each token superbly but know nothing about which tag sequences are legal, and the CRF supplies exactly that missing constraint.

A conditional random field is a discriminative model that scores an entire label sequence given the observed tokens, normalising globally rather than position by position. Learned transition weights rule out illegal tag sequences, arbitrary overlapping features of the input are permitted, and Viterbi decoding recovers the best path. CRFs set the standard for entity recognition and chunking, and survive as the output layer of BiLSTM-CRF and transformer taggers, which alone ignore sequence validity.

Imagine filling in a crossword. You could guess each letter on its own, but you would end up with nonsense. You do far better by checking that the letters form legal words together.

A conditional random field brings that discipline to labelling the words in a sentence — marking which ones are names, places or dates. Rather than judging each word alone, it chooses the labelling of the whole sentence that holds together best, so it cannot mark the middle of a person's name without marking the start of the name first. That single habit removes a whole family of silly mistakes, which is why it is still bolted on to modern systems.