ArticleslgStudy

computer science

Conditional random field

Conditional random field is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Conditional random field rather than just read about it. In short: In pattern recognition and machine learning, conditional random field (CRF) is a class of statistical modeling methods often used for structured prediction. Unlike a classifier which predicts a label for a single sample without considering neighboring samples, a CRF can take context into account.

Key takeaways

  • Conditional random field belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Conditional random field to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Conditional random field from memory before moving on to harder problems.

Reference excerpt

In pattern recognition and machine learning, conditional random field (CRF) is a class of statistical modeling methods often used for structured prediction. Unlike a classifier which predicts a label for a single sample without considering neighboring samples, a CRF can take context into account. To do so, the predictions are modeled as a graphical model, which represents the presence of dependencies between the predictions. The kind of graph used depends on the application. For example, in natural language processing, linear chain CRFs are popular, for which each prediction is dependent only on its immediate neighbors. In image processing, the graph typically connects locations to nearby and/or similar locations to enforce that they receive similar predictions. Other examples where CRFs are used are: labeling or parsing of sequential data for natural language processing or biological sequences, part-of-speech tagging, shallow parsing, named entity recognition, gene finding, peptide critical functional region finding, and object recognition and image segmentation in computer vision.

Description CRFs are a type of discriminative undirected probabilistic graphical model. Lafferty, McCallum and Pereira define a CRF on observations 𝑿 and random variables 𝒀 as follows:

Let G=(V,E) be a graph such that 𝒀=(𝒀v)v∈V, so that 𝒀 is indexed by the vertices of G. Then (𝑿,𝒀) is a conditional random field when each random variable 𝒀v, conditioned on 𝑿, obeys the Markov property with respect to the graph; that is, its probability is dependent only on its neighbours in G and not its past states: P(𝒀v|𝑿,{𝒀w:w≠v})=P(𝒀v|𝑿,{𝒀w:w∼v}), where 𝑤∼v means that w and v are neighbors in G.

What this means is that a CRF is an undirected graphical model whose nodes can be divided into exactly two disjoint sets 𝑿 and 𝒀, the observed and output variables, respectively; the conditional distribution p(𝒀|𝑿) is then modeled.

Inference For general graphs, the problem of exact inference in CRFs is intractable. The inference problem for a CRF is basically the same as for an MRF and the same arguments hold. However, there exist special cases for which exact inference is feasible:

If the graph is a chain or a tree, message passing algorithms yield exact solutions. The algorithms used in these cases are analogous to the forward-backward and Viterbi algorithm for the case of HMMs. If the CRF only contains pair-wise potentials and the energy is submodular, combinatorial max-flow min-cut algorithms yield exact solutions. If exact inference is impossible, several algorithms can be used to obtain approximate solutions. These include:

Loopy belief propagation Alpha expansion Mean field inference Linear programming relaxations

Parameter learning Learning the parameters θ is usually done by maximum likelihood learning for p(Yi|Xi;θ). If all nodes have exponential family distributions and all nodes are observed during training, this optimization is convex. It can be solved for example using gradient descent algorithms, or quasi-Newton methods such as the L-BFGS algorithm. On the other hand, if some variables are unobserved, the inference problem has to be solved for these variables. Exact inference is intractable in general graphs, so approximations have to be used.

Examples In sequence modeling, the graph of interest is usually a chain graph. An input sequence of observed variables X represents a sequence of observations and Y represents a hidden (or unknown) state variable that needs to be inferred given the observations. The Yi are structured to form a chain, with an edge between each Yi−1 and Yi. As well as having a simple interpretation of the Yi as "labels" for each element in the input sequence, this layout admits efficient algorithms for:

model training, learning the conditional distributions between the Yi and feature functions from some corpus of training data. decoding, determining the probability of a given label sequence Y given X. inference, determining the most likely label sequence Y given X. The conditional dependency of each Yi on X is defined through a fixed set of feature functions of the form f(i,Yi−1,Yi,X), which can be thought of as measurements on the input sequence that partially determine the likelihood of each possible value for Yi. The model assigns each feature a numerical weight and combines them to determine the probability of a certain value for Yi. Linear-chain CRFs have many of the same applications as conceptually simpler hidden Markov models (HMMs), but relax certain assumptions about the input and output sequence distributions. An HMM can loosely be understood as a CRF with very specific feature functions that use constant probabilities to model state transitions and emissions. Conversely, a CRF can loosely be understood as a generalization of an HMM that makes the constant transition probabilities into arbitrary functions that vary across the positions in the sequence of hidden states, depending on the input sequence. Notably, in contrast to HMMs, CRFs can contain any number of feature functions, the feature functions can inspect the entire input sequence X at any point during inference, and the range of the feature functions need not have a probabilistic interpretation.

Variants

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Conditional random field

Start with the simplest possible case. Write down what Conditional random field claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Conditional random field before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Conditional random field ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Conditional random field

In research
Conditional random field appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Conditional random field in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Conditional random field is common in secondary-school and first-year university syllabi. It links to neighbouring topics Graphical models, Machine learning, so understanding it makes those chapters shorter.
In everyday life
Look for Conditional random field outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Conditional random field” →

How to study Conditional random field in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Conditional random field means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Conditional random field out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Conditional random field in simple terms?

In pattern recognition and machine learning, conditional random field (CRF) is a class of statistical modeling methods often used for structured prediction. Unlike a classifier which predicts a label for a single sample without considering neighboring samples, a CRF can take context into account.

Why does Conditional random field matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Conditional random field?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Conditional random field.

Tags

  • Graphical models
  • Machine learning

Keep exploring