A Conditional Random Field (CRF) is a discriminative undirected probabilistic graphical model that computes the conditional probability P(Y|X) of an entire label sequence Y given an observation sequence X. Unlike generative models such as Hidden Markov Models, a CRF directly models the decision boundary between labels without expending modeling capacity on the joint distribution of the observations, making it highly effective for sequence labeling tasks like NER and part-of-speech tagging.
Glossary
Conditional Random Fields (CRF)

What is Conditional Random Fields (CRF)?
A discriminative probabilistic model for structured prediction that models the conditional probability of a label sequence given an observation sequence, widely used as a decoding layer in Named Entity Recognition.
In a linear-chain CRF, the model defines a log-linear score over the entire sequence using feature functions that capture transition dependencies between adjacent labels and emission scores from the underlying encoder. During inference, the Viterbi algorithm efficiently decodes the globally optimal label path, preventing illegal transitions such as an I-ORG tag following an O tag. This structural constraint is the primary advantage of a CRF over independent token-level softmax classifiers.
Key Features of Conditional Random Fields
Core architectural properties and operational mechanisms that make Conditional Random Fields a foundational decoding layer for sequence labeling tasks like Named Entity Recognition.
Discriminative Modeling
Unlike generative models (e.g., Hidden Markov Models) that model the joint probability P(X, Y), CRFs directly model the conditional probability P(Y|X) of a label sequence given an observation sequence. This eliminates the need to model complex dependencies in the input features, allowing the model to focus exclusively on the decision boundary. By conditioning on the entire observation sequence, a CRF can incorporate overlapping, non-independent features of the input without violating statistical assumptions.
Linear-Chain Structure
The most common CRF architecture for NER is the linear-chain CRF, which models a first-order Markov dependency between adjacent output labels. This structure defines an undirected graphical model where each label Yi is connected to the observation sequence X and to its immediate neighbors Yi-1 and Yi+1. This captures transition constraints—for example, an I-ORG tag cannot follow a B-PER tag—enforcing valid BIO label sequences during decoding.
Global Normalization
A defining characteristic of CRFs is that they compute a global partition function Z(X) that sums over all possible label sequences. This ensures the model produces a properly normalized probability distribution over entire sequences, not just local decisions. Unlike Maximum Entropy Markov Models (MEMMs), which normalize per-state and suffer from the label bias problem, CRFs avoid favoring states with fewer outgoing transitions, leading to more robust sequence-level predictions.
Feature Engineering Flexibility
CRFs can incorporate arbitrary, overlapping feature functions without independence assumptions. Feature templates can capture:
- Token-level features: word identity, prefixes/suffixes, capitalization patterns, part-of-speech tags
- Contextual features: surrounding word windows, conjunctions of multiple attributes
- Label transition features: co-occurrence patterns between adjacent labels This flexibility made CRFs the dominant NER approach before deep learning, and they remain powerful when combined with neural feature extractors.
Viterbi Decoding
At inference time, CRFs use the Viterbi algorithm—a dynamic programming method—to find the single most probable label sequence. The algorithm recursively computes the maximum score path to each state at each position, storing backpointers to reconstruct the optimal sequence. This guarantees a globally optimal solution in O(T × S²) time, where T is sequence length and S is the number of states, ensuring that predicted label sequences respect learned transition constraints.
Log-Likelihood Training
CRFs are trained by maximizing the conditional log-likelihood of the correct label sequence given the observations. The gradient involves the difference between the empirical feature counts from the training data and the expected feature counts under the current model distribution. Computing these expectations requires running the forward-backward algorithm to calculate marginal probabilities over all possible label paths, making training computationally intensive but statistically principled.
Frequently Asked Questions
Clear, technically precise answers to the most common questions about the probabilistic graphical models that power structured prediction in modern NLP pipelines.
A Conditional Random Field (CRF) is a discriminative probabilistic graphical model designed for structured prediction that models the conditional probability P(Y|X) of an entire label sequence Y given an observation sequence X. Unlike generative models such as Hidden Markov Models (HMMs) that model the joint distribution P(X,Y), a CRF directly models the decision boundary between label sequences. In sequence labeling tasks like Named Entity Recognition (NER), a linear-chain CRF defines a log-linear model over cliques of adjacent labels, computing the unnormalized score of a label sequence as the sum of emission scores (how well a token fits a label) and transition scores (how likely one label follows another). The partition function normalizes these scores over all possible label sequences, and during inference, the Viterbi algorithm efficiently finds the optimal path. This global normalization is the key mechanism that prevents label bias, a weakness of locally normalized models like Maximum Entropy Markov Models (MEMMs).
CRF vs. Other Sequence Decoding Methods
A comparison of Conditional Random Fields against alternative decoding architectures used for sequence labeling in Named Entity Recognition pipelines.
| Feature | Linear-Chain CRF | Softmax (Token-Level) | Global Pointer |
|---|---|---|---|
Modeling Approach | Discriminative graphical model; models conditional probability of entire label sequence given observation sequence | Independent per-token classification; no explicit sequence-level dependencies | Multiplicative attention scoring all start-end token pairs; direct span enumeration |
Label Dependency Modeling | |||
Global Sequence Normalization | |||
Decoding Algorithm | Viterbi decoding (dynamic programming) | Argmax per token (greedy) | Thresholded span scoring with hand-crafted or learned thresholds |
Invalid Sequence Prevention | Learns transition constraints (e.g., I-ORG cannot follow B-PER) | Natively avoids invalid spans by scoring only valid start-end pairs | |
Training Objective | Maximum conditional log-likelihood of the correct label sequence | Cross-entropy loss per token | Binary cross-entropy over all possible spans (class imbalance handled via loss weighting) |
Inference Speed | Slower; Viterbi has O(T·N²) complexity where T is sequence length and N is label count | Fastest; O(T·N) complexity | Moderate; O(T²·N) complexity due to scoring all span pairs |
Typical NER F1 on CoNLL-2003 | 93.5% (with BERT encoder) | 92.8% (with BERT encoder) | 93.1% (with BERT encoder) |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Understanding Conditional Random Fields requires familiarity with the sequence labeling ecosystem and the probabilistic graphical models they interact with. These concepts form the backbone of modern structured prediction.
BIO Tagging Scheme
A token-level annotation format where each token is tagged as Beginning, Inside, or Outside of a named entity span. This transforms NER into a sequence labeling problem solvable by CRFs.
- B-PER: First token of a person entity
- I-PER: Subsequent tokens of a person entity
- O: Token outside any entity
- Enables CRFs to model transitions between entity boundaries
Semi-Markov CRF
A segment-level extension of the linear-chain CRF that directly models the probability of entire entity spans rather than individual tokens. This allows the model to naturally incorporate segment-level features.
- Handles variable-length segments natively
- Avoids label bias by scoring segments as a whole
- More computationally expensive but captures richer features
Label Smoothing
A regularization technique that softens hard one-hot training targets by assigning a small probability mass to incorrect classes. This prevents the CRF from becoming overconfident on noisy training data.
- Replaces 0/1 targets with smoothed distributions
- Improves calibration of output probabilities
- Reduces overfitting in low-data regimes
Global Pointer
A modern NER architecture that uses multiplicative attention to directly score all possible start-end token pairs, bypassing the need for a CRF decoding layer entirely.
- Scores spans via bilinear interaction: s(i,j) = q_i^T * k_j
- Handles nested entities naturally
- Competitive with CRF-based models on flat NER benchmarks
Mention-Level F1 Score
The primary evaluation metric for NER systems that computes the harmonic mean of precision and recall. A prediction is correct only if both the entity's span boundaries and type classification match the ground truth exactly.
- Strict exact-match criterion
- Penalizes both boundary errors and type confusion
- Standard metric from the CoNLL-2003 shared task

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us