# BiLSTM-CRF 模型

BiLSTM-CRF 模型是自然语言处理中的一种神经序列标注方法，它先用双向长短期记忆网络对句子进行编码，再通过条件随机场（CRF）层为每个词元分配一个标签。该模型用于命名实体识别（NER）、词性（POS）标注和组块。

| 关键事实 | 内容 |
|---|---|
| 任务 | 命名实体识别、词性标注、组块<sup>[1](https://doi.org/10.4230/oasics.slate.2021.8)</sup> |
| 原始基准结果（黄、徐和俞，使用 Senna 词嵌入） | 词性标注准确率 97.55，CoNLL-2000 组块 F1 94.46，CoNLL-2003 命名实体识别 F1 88.83（使用地名词典时为 90.10）<sup>[1](https://doi.org/10.4230/oasics.slate.2021.8)</sup> |
| 典型训练设置 | 随机梯度下降，学习率 0.1，隐藏层大小 300，批次内句子总长度不超过 100，不到 10 轮、数小时内完成<sup>[1](https://doi.org/10.4230/oasics.slate.2021.8)</sup> |
| 后来的 CoNLL-2003 基线 | F1 90.22，解码速度 3,889 词/秒<sup>[2](https://ar5iv.labs.arxiv.org/html/1612.02706)</sup> |
| 为何需要 CRF 层 | 逐词 softmax 只对每个词做局部判断，可能输出不合法的标签序列；CRF 则学习标签之间的转移约束<sup>[3](https://aclanthology.org/N16-1030.pdf)</sup><sup> • </sup><sup>[4](https://www.nature.com/articles/s41598-024-58334-x)</sup> |
| 主要弱点 | CRF 从左到右的推理无法并行解码，限制了速度<sup>[5](https://aclanthology.org/C18-1327.pdf)</sup> |

## 工作原理

该模型由两个堆叠的组件构成。底层组件是双向 LSTM：两个参数各自独立的 LSTM 实例，一个正向读取词元序列，一个反向读取，各自维护一个隐藏状态，汇总其方向上迄今所见过的词元。每个位置上的两个隐藏状态被拼接起来，\( h_{t} = [\overrightarrow{h_{t}}; \overleftarrow{h_{t}}] \in \mathbb{R}^{m} \)，因此每个词元都由其左侧和右侧上下文共同表示。<sup>[6](https://link.springer.com/article/10.1186/s12911-019-0767-2)</sup> 随后一个线性层将该向量映射为每个标签一个分数，形成发射分数矩阵。<sup>[7](https://www.mindspore.cn/tutorials/application/en/r2.0.0-alpha/nlp/sequence_labeling.html)</sup>

顶层组件是 CRF 层。其参数构成一个转移矩阵 \( A \)，维度为 \( (k+2) \times (k+2) \)，对应 \( k \) 个标签加上起始和结束状态，其中 \( A_{ij} \) 是从标签 \( i \) 转移到标签 \( j \) 的分数。<sup>[6](https://link.springer.com/article/10.1186/s12911-019-0767-2)</sup> 解码时用 Viterbi 算法求解 \( y^{*} = \arg\max_{y'} \text{score}(X, y') \)，同时返回最优分数和每个词元的标签路径。<sup>[6](https://link.springer.com/article/10.1186/s12911-019-0767-2)</sup><sup> • </sup><sup>[7](https://www.mindspore.cn/tutorials/application/en/r2.0.0-alpha/nlp/sequence_labeling.html)</sup>

需要 CRF 层，是因为普通 softmax 对每个词独立打标签。这种局部输出缺乏对预测标签的全局视角<sup>[3](https://aclanthology.org/N16-1030.pdf)</sup>，可能产生不合法的序列，例如 BIO 格式中的“O, I-Disease, I-Disease”——I 标签必须跟在 B 标签之后；CRF 则自动学习输出标签之间的这些依赖关系。<sup>[4](https://www.nature.com/articles/s41598-024-58334-x)</sup>

## 实现方法

实际应用的流程按以下顺序进行：

1. **嵌入层。** 每个词元被映射为一个词嵌入，通常使用预训练嵌入（Senna 或 skip-n-gram——一种考虑词序的 word2vec 变体），并在训练中微调。<sup>[1](https://doi.org/10.4230/oasics.slate.2021.8)</sup><sup> • </sup><sup>[3](https://aclanthology.org/N16-1030.pdf)</sup> 许多变体还加入字符级表示（见变体一节）。
2. **BiLSTM 编码。** 嵌入序列通过正向和反向 LSTM，其输出按词元拼接。
3. **CRF 打分。** 一个线性层将每个词元向量投影为 \( k \) 个标签分数；CRF 层持有转移矩阵 \( A \)。<sup>[6](https://link.springer.com/article/10.1186/s12911-019-0767-2)</sup>
4. **训练。** 训练参数以最大化给定词语时观测标签序列的对数似然。<sup>[3](https://aclanthology.org/N16-1030.pdf)</sup> 损失为 \( \text{Loss} = -\log P(y \mid x) = \log \sum_{y' \in Y} \exp(\text{Score}(x, y')) - \text{Score}(x, y) \)，其中第一项称为归一化项，第二项称为分数项。<sup>[7](https://www.mindspore.cn/tutorials/application/en/r2.0.0-alpha/nlp/sequence_labeling.html)</sup> 每个批次运行正向和反向 LSTM 前向、后向传播，再加上 CRF 层的前向、后向传播，以计算网络输出和状态转移边的梯度，然后更新 \( [A]_{i,j} \) 和 BiLSTM 参数 \( \theta \)。<sup>[1](https://doi.org/10.4230/oasics.slate.2021.8)</sup>
5. **解码。** 对发射分数和转移分数做 Viterbi 推理，得到最终标签序列。<sup>[7](https://www.mindspore.cn/tutorials/application/en/r2.0.0-alpha/nlp/sequence_labeling.html)</sup>

原论文参考超参数：随机梯度下降，学习率 0.1，隐藏层大小 300（性能对该选择不敏感），批次内句子总长度不超过 100；三个任务均在不到 10 轮内收敛，通常不到数小时。<sup>[1](https://doi.org/10.4230/oasics.slate.2021.8)</sup>

## 起源

该方法由黄、徐和俞（2015）在 arXiv 上发表的《Bidirectional LSTM-CRF Models for Sequence Tagging》中提出，文中称这是首次将双向 LSTM-CRF（BI-LSTM-CRF）模型应用于自然语言处理基准序列标注数据集，并提出了带 CRF 层的 LSTM-CRF 和 BI-LSTM-CRF 两种架构。<sup>[1](https://doi.org/10.4230/oasics.slate.2021.8)</sup> 字符级 LSTM 变体由 Lample 及其同事（2016）在 arXiv 上发表的《Neural Architectures for Named Entity Recognition》中提出<sup>[8](https://doi.org/10.48550/arxiv.1603.01360)</sup>，CNN 字符变体由 Ma 和 Hovy（2016）在 arXiv 上发表的《End-to-end Sequence Labeling via Bi-directional LSTM-CNNs-CRF》中提出。<sup>[9](https://doi.org/10.48550/arxiv.1603.01354)</sup> 没有已发表的来源记录这些团队之间存在优先权争议；有记录的优先权主张只有黄、徐和俞自己的“首次应用”声明。<sup>[1](https://doi.org/10.4230/oasics.slate.2021.8)</sup>

## 变体

**字符级编码。** Lample 及其同事在训练中学习字符级特征，而非手工设计前缀和后缀信息，他们在字符嵌入序列上运行双向 LSTM，每个字符嵌入为 25 维，生成 50 维的字符表示，并与词嵌入拼接。<sup>[3](https://aclanthology.org/N16-1030.pdf)</sup> Ma 和 Hovy 的变体用基于字符的 CNN 替代了该字符 LSTM。<sup>[9](https://doi.org/10.48550/arxiv.1603.01354)</sup> 一项 2025 年的复现测量了 CoNLL-2003 上的差异：普通 BiLSTM-CRF 90.10 F1，CNN-BiLSTM-CRF 90.94，BiLSTM-CNN-CRF 91.18，而原始报告为 91.21。<sup>[10](https://arxiv.org/html/2510.10936)</sup>

**预训练语言模型混合。** 在架构中加入 ELMo 嵌入通常可将 F1 提升约 1 至 5 个百分点，但 ELMo 表示的计算成本较高。<sup>[11](https://github.com/UKPLab/emnlp2017-bilstm-cnn-crf)</sup> 后来的混合模型将 BERT 或 ALBERT 嵌入送入 BiLSTM-CRF 堆栈。<sup>[12](https://link.springer.com/article/10.1007/s11042-025-20970-4)</sup><sup> • </sup><sup>[13](https://www.nature.com/articles/s41598-025-04036-x)</sup>

**注意力变体。** 在 BiLSTM 输出之上插入注意力层，即得到用于中文临床命名实体识别的 Attention-BiLSTM-CRF 模型。<sup>[6](https://link.springer.com/article/10.1186/s12911-019-0767-2)</sup>

## 应用

在 CoNLL-2003 命名实体识别上，普通 BiLSTM-CRF 的报告 F1 随嵌入和实现而异：原论文中，使用 Senna 嵌入为 88.83，不使用为 84.26（同等条件下 Conv-CRF 为 81.47）<sup>[1](https://doi.org/10.4230/oasics.slate.2021.8)</sup>；后来的基线为 90.22<sup>[2](https://ar5iv.labs.arxiv.org/html/1612.02706)</sup>；2025 年复现为 90.10。<sup>[10](https://arxiv.org/html/2510.10936)</sup> 原论文还报告了词性标注准确率 97.55 和 CoNLL-2000 组块 F1 94.46。<sup>[1](https://doi.org/10.4230/oasics.slate.2021.8)</sup>

在中文电子病历命名实体识别中，BiLSTM-CRF 达到 90.15% F1，Attention-BiLSTM-CRF 达到 90.82%，均高于竞争方法的最佳结果 89.26%。<sup>[6](https://link.springer.com/article/10.1186/s12911-019-0767-2)</sup> 该架构仍是基于 BERT、ALBERT 和 XLM-RoBERTa 等预训练编码器构建的混合系统的组成部分。<sup>[12](https://link.springer.com/article/10.1007/s11042-025-20970-4)</sup><sup> • </sup><sup>[13](https://www.nature.com/articles/s41598-025-04036-x)</sup><sup> • </sup><sup>[14](https://journal.kci.go.kr/ksavs/archive/articleView?artiId=ART003277346)</sup>

## 局限与替代方案

**解码速度。** CRF 推理层严重限制解码速度，因为其从左到右的推理过程无法并行解码。<sup>[5](https://aclanthology.org/C18-1327.pdf)</sup> 将长度相同的句子分组可使实现比原始系统快数倍<sup>[11](https://github.com/UKPLab/emnlp2017-bilstm-cnn-crf)</sup>，非结构化替代方案则以精度换速度：Mention2Vec 模型快一个数量级（在 OntoNotes 上为 4,949 词/秒对 495 词/秒），但 F1 为 89.37，而 BiLSTM-CRF 为 90.77，原因似乎是全结构化模型更有效地利用了提及类型之间的强相关性。<sup>[2](https://ar5iv.labs.arxiv.org/html/1612.02706)</sup>

**任务适配与数据条件。** CRF 推理算法在命名实体识别和组块上有效，但在词性标注上没有优势。<sup>[5](https://aclanthology.org/C18-1327.pdf)</sup> 该模型对外部嵌入的依赖比 Conv-CRF 小：随机嵌入与 Senna 嵌入的差距在词性标注、组块和命名实体识别上分别为 0.12%、0.33% 和 4.57%，而 Conv-CRF 为 0.92%、3.99% 和 7.20%。<sup>[1](https://doi.org/10.4230/oasics.slate.2021.8)</sup>

**未登录词。** 字符 LSTM 或 CNN 表示对训练词表外和基准词表外性能的提升最大，表明神经字符表示的主要贡献在于消歧未登录词。<sup>[5](https://aclanthology.org/C18-1327.pdf)</sup>

**长序列与跨上下文模式。** 计算复杂度随序列长度增加，受 LSTM 限制，该模型对超长序列处理不佳；它还需要仔细调参，若不微调可能难以迁移到新领域。<sup>[10](https://arxiv.org/html/2510.10936)</sup> BiLSTM 在对每个词的跨上下文模式建模上存在形式化的“XOR 局限”，自注意力或 Cross-BiLSTM 可以弥补；在 OntoNotes 5.0 和 WNUT 2017 上，加入自注意力相比 BiLSTM（-CRF）基线带来了明显且一致的提升，在某些多词元实体提及上最高提升 8.7%。<sup>[15](https://ojs.aaai.org/index.php/AAAI/article/view/6338)</sup>

**边界与词表。** 传统 BERT-BiLSTM-CRF 模型因缺乏专业词表，在命名实体边界检测不准确和实体过度碎片化方面存在困难。<sup>[16](https://journal.hep.com.cn/mgea/EN/10.1002/mgea.70001)</sup>

## References

1. [Huang, Zhiheng, Xu, Wei, Yu, Kai (2015). Bidirectional LSTM-CRF Models for Sequence Tagging. arXiv (Cornell University).](https://doi.org/10.4230/oasics.slate.2021.8)
2. [Entity Identification as Multitasking](https://ar5iv.labs.arxiv.org/html/1612.02706)
3. [Neural Architectures for Named Entity Recognition (Lample et al., 2016)](https://aclanthology.org/N16-1030.pdf)
4. [BioBBC: a multi-feature model that enhances the detection of biomedical entities | Scientific Reports](https://www.nature.com/articles/s41598-024-58334-x)
5. [Design Challenges and Misconceptions in Neural Sequence Labeling](https://aclanthology.org/C18-1327.pdf)
6. [A hybrid approach for named entity recognition in Chinese electronic medical record](https://link.springer.com/article/10.1186/s12911-019-0767-2)
7. [MindSpore LSTM+CRF Sequence Labeling tutorial](https://www.mindspore.cn/tutorials/application/en/r2.0.0-alpha/nlp/sequence_labeling.html)
8. [Lample, Guillaume and colleagues (2016). Neural Architectures for Named Entity Recognition. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1603.01360)
9. [Ma, Xuezhe, Hovy, Eduard (2016). End-to-end Sequence Labeling via Bi-directional LSTM-CNNs-CRF. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1603.01354)
10. [End-to-end Sequence Labeling via Bi-directional LSTM-CNNs-CRF: A Reproducibility Study](https://arxiv.org/html/2510.10936)
11. [UKPLab/emnlp2017-bilstm-cnn-crf](https://github.com/UKPLab/emnlp2017-bilstm-cnn-crf)
12. [ALBERT-BiLSTM-CRF with pointer network based model for named entity recognition](https://link.springer.com/article/10.1007/s11042-025-20970-4)
13. [A diffusion enhanced CRF and BiLSTM framework for accurate entity recognition](https://www.nature.com/articles/s41598-025-04036-x)
14. [Performance and Stability Analysis of a Fine-Tuned BERT-BiLSTM-CRF NER Model for Automated Information Extraction in Openly Licensed Works](https://journal.kci.go.kr/ksavs/archive/articleView?artiId=ART003277346)
15. [Why Attention? Analyze BiLSTM Deficiency and Its Remedies in the Case of NER](https://ojs.aaai.org/index.php/AAAI/article/view/6338)
16. [Enhancing named entity recognition with a novel BERT-BiLSTM-CRF-RC joint training model for biomedical materials database](https://journal.hep.com.cn/mgea/EN/10.1002/mgea.70001)

---
*Initially written Sep 29, 2026 · Reviewed: Sep 30, 2026 · Edited: Sep 30, 2026 · Last review: Sep 30, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Language and vision AI › Natural language processing › NLP tasks and methods

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/bilstm-crf-model

English original: https://www.edgepedia.org/bilstm-crf-model
