Algorithm Search⌘K

Problemintro

Sequence labeling

Also called sequence tagging.

Assign one label from a fixed set to each token of a sequence, using the whole sequence, as in tagging, chunking and entity recognition.

Sequence labeling asks for one label per token of an input sequence, chosen from a fixed set of kk labels, so that the whole label sequence is right. The labels of nearby tokens depend on each other, so a good method decides them jointly, not one token at a time. It is the most common form of structured prediction in language processing: part-of-speech tagging, text chunking and named entity recognition are all instances. This page is about the problem in general; the pages of the instances describe their label sets, data and scores.

In plain words

You get a sentence and must write one tag under each word. The tags come from a short list, such as noun, verb and adjective, or "start of a name", "inside a name" and "not a name". You cannot decide each word alone: "can" is a verb after "you" and a noun after "the", and a name that starts must go on until it ends. So a method looks at the whole sentence and at how the tags fit together. When each tag only interacts with the tag before it, a table filled from left to right finds the best tag sequence quickly, even though there are very many sequences.

Definition

Input. A sequence x=x1…xnx = x_1 \ldots x_n of tokens, a set YY of kk labels, and a model that gives a score s(x,y)s(x, y) to each label sequence y∈Yny \in Y^n. The model is usually learned from training pairs (x,y)(x, y).

Output. A label sequence y^=arg⁡max⁡y∈Yns(x,y)\hat y = \arg\max_{y \in Y^n} s(x, y). There are knk^n candidates.

First-order models. Most methods use a score that splits into local parts:

s(x,y)=∑i=1n+1ψi(x,yi−1,yi),s(x, y) = \sum_{i=1}^{n+1} \psi_i(x, y_{i-1}, y_i),

with a start label y0=⟨s⟩y_0 = \langle s \rangle and an end label yn+1=⟨/s⟩y_{n+1} = \langle /s \rangle. In a hidden Markov model, ψi=log⁡P(yi∣yi−1)+log⁡P(xi∣yi)\psi_i = \log P(y_i \mid y_{i-1}) + \log P(x_i \mid y_i). In a conditional random field or the structured perceptron, ψi=w⋅f(x,i,yi−1,yi)\psi_i = w \cdot f(x, i, y_{i-1}, y_i) for a feature vector ff that may look at the whole input. Models of order mm let ψi\psi_i depend on yi−m,…,yiy_{i-m}, \ldots, y_i.

Measures. For a per-token task such as tagging, the score is the token accuracy. For a span task such as chunking, it is the F score of the spans: precision and recall of the predicted spans against the gold spans, where a span counts only if both of its ends and its label are right (precision and recall).

Variants

  • Decoding versus learning. Decoding finds y^\hat y for a fixed model. Learning chooses the model from data, by counting (HMM), by maximizing the conditional likelihood (CRF), or by mistake-driven updates (perceptron).
  • Most probable sequence versus best labels one by one. Under a probabilistic model, the most probable sequence (Viterbi) and the sequence of the most probable labels at each position (posterior decoding with the forward-backward algorithm) can differ. The first maximizes the chance that the whole sequence is right, the second the expected number of right tokens.
  • Span labeling. Spans can be encoded as token labels with BIO encoding, or labeled directly by a semi-Markov CRF.
  • Constrained labeling. Some label pairs may be forbidden, such as O followed by I-X in BIO. The decoder then gives them a score of −∞-\infty.
  • Higher order. A second-order model scores label triples, as in the trigram HMM tagger.
  • Unsupervised labeling. With no labeled data, the labels are clusters, as in Bayesian HMM tagging.

Examples

  • Part-of-speech tagging: in "the old man the boats", the first guess old/J man/N leaves no verb. The right tags are the/D old/N man/V the/D boats/N: "old" means old people and "man" is a verb. Only the context decides.
  • Chunking with BIO tags: "He/B-NP reckons/B-VP the/B-NP current/I-NP account/I-NP deficit/I-NP".
  • Named entities: "Jim/B-PER bought/O shares/O of/O Acme/B-ORG Corp/I-ORG".
  • Outside language processing: gene finding labels each base of a DNA sequence as coding or not, and word segmentation for languages without spaces can label each character as the start of a word or not.

Known algorithms

AlgorithmTimeSpacePropertiesCode
Connectionist temporal classificationΘ(T (U + K)) worstΘ(T U) extradeterministicexactofflineiterative1 language
Structured perceptronΘ(t n k^2) worstO(n + d) extradeterministicnot exactonlineiterative1 language

Bounds

  • Decoding a first-order model takes O(nk2)O(n k^2) time with Viterbi (a theorem; see the Viterbi algorithm). The input has Θ(nk2)\Theta(n k^2) numbers when every local score ψi(yi−1,yi)\psi_i(y_{i-1}, y_i) is given separately, so this is optimal for that input form.
  • For order mm, the state space has kmk^m states, and the time is O(nkm+1)O(n k^{m+1}).
  • Without the local structure, for a general score over YnY^n, the problem is as hard as maximizing an arbitrary function over knk^n points; models with long-range label interactions are decoded approximately.

Reductions

  • Span finding to sequence labeling: BIO encoding maps each set of non-overlapping labeled spans to one label sequence and back.
  • Sequence labeling to shortest paths: a first-order decoding problem is a longest path in a layered DAG with nn layers of kk nodes, where the edge from (i−1,a)(i - 1, a) to (i,b)(i, b) has weight ψi(a,b)\psi_i(a, b). This is the DAG dynamic programming view of Viterbi.
  • Order mm to order 1: replace each label by the tuple of the last mm labels, which gives kmk^m labels.
  • Sequence labeling to classification: label each token alone with a classifier that sees the context. This drops the interaction between labels, and is exact only when the labels are independent given the input.

Applications

Part-of-speech tagging, chunking, named entity recognition, semantic role labeling with BIO tags over argument spans, word segmentation, slot filling in dialogue systems, and the segmentation of speech, handwriting and biological sequences. Labeled spans are also the input of later steps such as relation extraction and parsing.

References

  1. Lafferty, McCallum and Pereira 2001, Section 1 (the labeling problem and the generative and conditional models for it), Section 2 (label bias), Section 5.3 (part-of-speech tagging results of HMM, MEMM and CRF)
  2. Collins 2002, Section 2 (tagging as the argmax of a linear score over tag sequences, decoded by Viterbi), Section 4 (tagging and NP chunking experiments)
  3. Tjong Kim Sang and Buchholz 2000, chunking as tagging with B-X, I-X and O tags, the data and the F score of chunks

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a contract.yaml