# 原型网络

[原型网络](https://www.edgepedia.org/zh/prototypical-networks)（prototypical network）是一种基于度量的少样本学习方法：它为每个类别学习一个原型，将新样本的学习到的嵌入与各原型逐一比较，从而完成分类；每个原型就是该类别少量带标签支持样本嵌入的均值。它面向少样本分类问题——模型必须仅凭每个新类别的少量样本，泛化到训练集中未曾出现的类别。<sup>[1](https://proceedings.neurips.cc/paper/2017/file/cb8da6767461f2812ae4290eac7cbc42-Paper.pdf)</sup> 该方法于 NIPS 2017 提出，已成为少样本学习文献中最流行、最有效的方法之一，并构成了此后许多方法的核心。<sup>[2](https://proceedings.neurips.cc/paper_files/paper/2021/file/cdfa4c42f465a5a66871587c69fcfa34-Paper.pdf)</sup>

| 关键事实 | 详情 |
|---|---|
| 提出者 | 杰克·斯内尔（Jake Snell）、凯文·斯沃斯基（Kevin Swersky）和理查德·泽梅尔（Richard Zemel），NIPS 2017<sup>[3](https://doi.org/10.48550/arxiv.1703.05175)</sup> |
| 分类规则 | 对到各类原型的负平方欧氏距离取 softmax<sup>[1](https://proceedings.neurips.cc/paper/2017/file/cb8da6767461f2812ae4290eac7cbc42-Paper.pdf)</sup> |
| miniImageNet 准确率 | 49.42 ± 0.78%（5-way 1-shot），68.20 ± 0.66%（5-shot）<sup>[1](https://proceedings.neurips.cc/paper/2017/file/cb8da6767461f2812ae4290eac7cbc42-Paper.pdf)</sup> |
| Omniglot 准确率 | 98.8% / 99.7%（5-way 1/5-shot），96.0% / 98.9%（20-way）<sup>[1](https://proceedings.neurips.cc/paper/2017/file/cb8da6767461f2812ae4290eac7cbc42-Paper.pdf)</sup> |
| 距离选择 | 平方欧氏距离在原始实验中大幅提升了结果<sup>[1](https://proceedings.neurips.cc/paper/2017/file/cb8da6767461f2812ae4290eac7cbc42-Paper.pdf)</sup> |
| 训练方式 | 情景式训练，用 SGD 最小化真实类别的负对数概率<sup>[1](https://proceedings.neurips.cc/paper/2017/file/cb8da6767461f2812ae4290eac7cbc42-Paper.pdf)</sup> |
| 成本 | 原作者称其比他们在 2017 年所比较的元学习算法更简单、更高效<sup>[1](https://proceedings.neurips.cc/paper/2017/file/cb8da6767461f2812ae4290eac7cbc42-Paper.pdf)</sup> |

## 工作原理

由神经网络产生的嵌入函数 \( f_{\phi}: \mathbb{R}^D \to \mathbb{R}^M \) 将输入映射到一个度量空间。对于类别 \( k \)，原型 \( c_{k} \) 是属于该类别的支持点在嵌入空间中的均值向量：

\[ c_{k} = \frac{1}{|S_{k}|} \sum_{i} f_{\phi}(x_{i}) \]

对查询点 \( x \) 的分类，是对到各原型的负距离取 softmax：<sup>[1](https://proceedings.neurips.cc/paper/2017/file/cb8da6767461f2812ae4290eac7cbc42-Paper.pdf)</sup>

\[ p_{\phi}(y = k \mid x) = \frac{\exp(-d(f_{\phi}(x),\, c_{k}))}{\sum_{k'} \exp(-d(f_{\phi}(x),\, c_{k'}))} \]

距离 \( d \) 为平方欧氏距离。这一选择有理论基础：对于[正则布雷格曼散度](https://www.edgepedia.org/zh/bregman-divergence)（Bregman divergence），即定义为 \( d_{\phi}(z, z') = \phi(z) - \phi(z') - (z - z')^{\top} \nabla \phi(z') \) 且 \( \phi \) 可微、为勒让德型（Legendre type）严格凸函数的情形，该算法等价于在支持集上用指数族密度做混合密度估计。因此，距离的选择实际上规定了对嵌入空间中类条件分布的建模假设。<sup>[1](https://proceedings.neurips.cc/paper/2017/file/cb8da6767461f2812ae4290eac7cbc42-Paper.pdf)</sup> 平方欧氏距离在原始实验中大幅提升了结果，作者推测这主要是因为余弦距离不是布雷格曼散度。<sup>[1](https://proceedings.neurips.cc/paper/2017/file/cb8da6767461f2812ae4290eac7cbc42-Paper.pdf)</sup> 一种等价的表述把原型写成类别平均 \( \mu_{j} = (1/M) \sum_{i} h_{\theta}(x_{i}^{s}) \cdot \mathbf{1}\{y_{i}^{s} = j\} \)，并以软最近邻方案 \( p_{\theta}(y = j \mid x) = \mathrm{softmax}(-\|h_{\theta}(x) - \mu_{j}\|^{2}) \) 对查询进行分类。<sup>[4](https://ar5iv.labs.arxiv.org/html/1902.08605)</sup>

## 实施方法

训练是情景式的。每个情景先从训练集中随机抽取一个类别子集，再在每个类别中抽取一部分样本作为支持集，其余样本作为查询。<sup>[1](https://proceedings.neurips.cc/paper/2017/file/cb8da6767461f2812ae4290eac7cbc42-Paper.pdf)</sup> 学习过程通过随机梯度下降在随机采样的情景上最小化真实类别 \( k \) 的负对数概率 \( J(\phi) = -\log p_{\phi}(y = k \mid x) \)。<sup>[1](https://proceedings.neurips.cc/paper/2017/file/cb8da6767461f2812ae4290eac7cbc42-Paper.pdf)</sup>

情景的构成很重要。训练时每个情景使用的类别数（"way"）高于测试时使用的类别数，可能极为有益；而"shot"数则最好在训练与测试之间保持一致。<sup>[1](https://proceedings.neurips.cc/paper/2017/file/cb8da6767461f2812ae4290eac7cbc42-Paper.pdf)</sup>

2021 年的一项 NeurIPS 分析对情景式方案本身提出了质疑：在这一类方法中，情景式学习“对性能有害”，相当于从一批样本中随机丢弃样本，并引入了需要仔细调参的多余超参数。<sup>[2](https://proceedings.neurips.cc/paper_files/paper/2021/file/cdfa4c42f465a5a66871587c69fcfa34-Paper.pdf)</sup> 若不采用情景式学习，这些方法与深度嵌入上的经典邻域成分分析（Neighbourhood Component Analysis, NCA）密切相关，并在 miniImageNet、CIFAR-FS 和 tieredImageNet 上取得了与近期方法相当的准确率。<sup>[2](https://proceedings.neurips.cc/paper_files/paper/2021/file/cdfa4c42f465a5a66871587c69fcfa34-Paper.pdf)</sup>

## 起源

原型网络由杰克·斯内尔、凯文·斯沃斯基和理查德·泽梅尔在《Prototypical Networks for Few-shot Learning》一文中报告，该文于 2017 年发布，发表于《Advances in Neural Information Processing Systems》第 30 卷。<sup>[3](https://doi.org/10.48550/arxiv.1703.05175)</sup><sup> • </sup><sup>[1](https://proceedings.neurips.cc/paper/2017/file/cb8da6767461f2812ae4290eac7cbc42-Paper.pdf)</sup> 其主要前身是奥里[奥尔·维尼亚尔斯](https://www.edgepedia.org/zh/oriol-vinyals)（Oriol Vinyals）及其同事于 2016 年提出的匹配网络（Matching Networks），后者引入了基于情景的训练，并在支持集上使用注意力机制。<sup>[5](https://doi.org/10.48550/arxiv.1606.04080)</sup><sup> • </sup><sup>[6](https://arxiv.org/pdf/2507.09299)</sup> 在单样本学习中，两种方法等价，因为原型就等于单个支持点的嵌入（\( c_{k} = f_{\phi}(x_{k}) \)）；在少样本情形下二者不同，因为使用平方欧氏距离的原型网络产生的是线性分类器，而匹配网络产生的是加权最近邻分类器。<sup>[1](https://proceedings.neurips.cc/paper/2017/file/cb8da6767461f2812ae4290eac7cbc42-Paper.pdf)</sup>

## 变体

若干扩展改动了原型的计算方式或使用方式：

- 半监督原型。一个研讨会版本将该方法扩展为在计算原型时使用无标签样本。<sup>[7](https://meta-learn.github.io/2017/papers/metalearn17_boney.pdf)</sup> 每个类别由带标签与无标签样本的嵌入输入均值表示，并涵盖了主动学习设定。<sup>[8](https://ar5iv.labs.arxiv.org/html/1711.10856)</sup>
- 无限混合原型（Infinite mixture prototypes），由凯尔西·R·艾伦（Kelsey R. Allen）、埃文·谢尔哈默（Evan Shelhamer）、哈努尔·申（Hanul Shin）和乔舒亚·B·滕嫩鲍姆（Joshua B. Tenenbaum）于 2019 年报告，将[深度表示学习](https://www.edgepedia.org/zh/deep-representation-learning)与贝叶斯非参数方法相结合，用一组簇而非单个原型来表示每个类别；他们报告在超类等复杂数据分布上，相对原型网络取得了 10% 到 25% 的绝对准确率提升。<sup>[9](https://doi.org/10.48550/arxiv.1902.04552)</sup><sup> • </sup><sup>[10](http://proceedings.mlr.press/v97/allen19b/allen19b.pdf)</sup>
- ProtoAttend，由塞尔詹·O·阿里克（Sercan O. Arik）和托马斯·菲斯特（Tomas Pfister）于 2019 年报告，加入了基于注意力的原型学习，并具备基于样本的可解释性、置信度估计和分布失配检测能力，可集成到预训练架构中。<sup>[11](https://doi.org/10.48550/arxiv.1902.06292)</sup><sup> • </sup><sup>[12](https://www.jmlr.org/papers/volume21/20-042/20-042.pdf)</sup>
- 组合式原型网络（Compositional Prototypical Networks, CPN），由吕强（Qiang Lyu）和王伟强（Weiqiang Wang）于 2023 年报告，为每个人工标注的属性学习一个可迁移的组件原型，并用可学习的权重生成器融合组合原型与视觉原型。<sup>[13](https://doi.org/10.48550/arxiv.2306.06584)</sup><sup> • </sup><sup>[14](https://ojs.aaai.org/index.php/AAAI/article/view/26082)</sup>
- 代表性加权。2020 年的一项修改按类别代表性对支持样本加权，其动机是观察到同类支持样本在代表性上差异极大。<sup>[15](https://www.sciencedirect.com/science/article/abs/pii/S0167865520302610)</sup>
- DFPN 是 2025 年提出的一种动态融合原型网络，将基于均值的原型与自适应生成的动态原型相融合，并施加 Yeo-Johnson 变换，使特征分布更接近高斯分布。<sup>[16](https://link.springer.com/article/10.1007/s10489-025-06581-4)</sup>
- Proto-CLIP 是一种视觉-语言原型网络，同时提供免训练与微调两种变体，已在少样本基准和真实机器人感知中得到验证。<sup>[17](https://arxiv.org/pdf/2307.03073v3.pdf)</sup>

## 应用

在使用欧氏距离的 miniImageNet 上，原型网络在 5-way 1-shot 下达到 49.42 ± 0.78%，在 5-shot 下达到 68.20 ± 0.66%；相比之下，使用余弦距离的匹配网络为 43.40 ± 0.78% 和 51.09 ± 0.71%，元学习器 LSTM（Meta-Learner LSTM）为 43.44 ± 0.77% 和 60.60 ± 0.71%。<sup>[1](https://proceedings.neurips.cc/paper/2017/file/cb8da6767461f2812ae4290eac7cbc42-Paper.pdf)</sup> 在使用欧氏距离且不做微调的 Omniglot 上，该方法在 5-way 设定下达到 98.8%（1-shot）和 99.7%（5-shot），在 20-way 设定下达到 96.0% 和 98.9%。<sup>[1](https://proceedings.neurips.cc/paper/2017/file/cb8da6767461f2812ae4290eac7cbc42-Paper.pdf)</sup>

标准评估使用 10,000 个测试情景，设定为 5-way、15 个查询、1-shot 或 5-shot，95% 置信区间由跨三个随机种子的 30,000 个情景计算得出。<sup>[2](https://proceedings.neurips.cc/paper_files/paper/2021/file/cdfa4c42f465a5a66871587c69fcfa34-Paper.pdf)</sup> 后来的修正数值更高：一种使用标签传播与特征平移的直推式原型修正方法在 miniImageNet 上报告了 70.31%（1-shot）和 81.89%（5-shot），在 tieredImageNet 上报告了 78.74% 和 86.92%。<sup>[18](https://link.springer.com/chapter/10.1007/978-3-030-58452-8_43)</sup> 除图像分类外，原型网络还用于应用机器学习工作，包括针对自闭症的脑电扫描分析和青光眼分级。<sup>[2](https://proceedings.neurips.cc/paper_files/paper/2021/file/cdfa4c42f465a5a66871587c69fcfa34-Paper.pdf)</sup>

## 局限与替代方案

在规模分布范围狭窄的稀缺数据上训练，往往会产生有偏的原型；已识别出两个影响因素：类内偏差与类间偏差。<sup>[18](https://link.springer.com/chapter/10.1007/978-3-030-58452-8_43)</sup> 对复杂或细粒度类别而言，每类单一原型也是一种局限，因为平均会模糊重要特征，而且原型对每个类别是固定的，不会针对每个查询的上下文自适应；基于度量的方法在 CUB-200 这类细粒度任务上往往表现吃力。<sup>[6](https://arxiv.org/pdf/2507.09299)</sup>

替代方案改变的是比较规则。匹配网络在支持集上产生加权最近邻分类器。<sup>[1](https://proceedings.neurips.cc/paper/2017/file/cb8da6767461f2812ae4290eac7cbc42-Paper.pdf)</sup> 关系网络（Relation Networks）使用与嵌入函数联合优化的可学习距离度量；DeepEMD 由张驰（Chi Zhang）、蔡玉军（Yujun Cai）、林国胜（Guosheng Lin）和[沈春华](https://www.edgepedia.org/zh/chunhua-shen)（Chunhua Shen）于 2020 年提出，采用推土机距离（Earth Mover's Distance）作为比较度量。<sup>[14](https://ojs.aaai.org/index.php/AAAI/article/view/26082)</sup><sup> • </sup><sup>[19](https://doi.org/10.48550/arxiv.2003.06777)</sup> 尽管方法简单，但与残差网络（ResNet）骨干网络结合时，其表现可与更复杂的少样本方法相竞争，而其可学习部分只有骨干嵌入。<sup>[4](https://ar5iv.labs.arxiv.org/html/1902.08605)</sup> 原始论文称原型网络比近期的元学习算法更简单、更高效。<sup>[1](https://proceedings.neurips.cc/paper/2017/file/cb8da6767461f2812ae4290eac7cbc42-Paper.pdf)</sup>

## References

1. [Prototypical Networks for Few-shot Learning (NeurIPS 2017)](https://proceedings.neurips.cc/paper/2017/file/cb8da6767461f2812ae4290eac7cbc42-Paper.pdf)
2. [On Episodes, Prototypical Networks, and Few-Shot Learning (NeurIPS 2021)](https://proceedings.neurips.cc/paper_files/paper/2021/file/cdfa4c42f465a5a66871587c69fcfa34-Paper.pdf)
3. [Snell, Jake, Swersky, Kevin, Zemel, Richard S. (2017). Prototypical Networks for Few-shot Learning. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1703.05175)
4. [Are Few-Shot Learning Benchmarks too Simple? Solving them without Test-Time Labels](https://ar5iv.labs.arxiv.org/html/1902.08605)
5. [Vinyals, Oriol and colleagues (2016). Matching Networks for One Shot Learning. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1606.04080)
6. [ViT-ProtoNet for Few-Shot Image Classification: A Multi-Benchmark (survey sections, 2025)](https://arxiv.org/pdf/2507.09299)
7. [Semi-Supervised Few-Shot Learning with Prototypical Networks](https://meta-learn.github.io/2017/papers/metalearn17_boney.pdf)
8. [Semi-Supervised and Active Few-Shot Learning with Prototypical Networks](https://ar5iv.labs.arxiv.org/html/1711.10856)
9. [Allen, Kelsey R. and colleagues (2019). Infinite Mixture Prototypes for Few-Shot Learning. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1902.04552)
10. [Infinite Mixture Prototypes for Few-Shot Learning (ICML 2019)](http://proceedings.mlr.press/v97/allen19b/allen19b.pdf)
11. [Arik, Sercan O., Pfister, Tomas (2019). ProtoAttend: Attention-Based Prototypical Learning. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1902.06292)
12. [ProtoAttend: Attention-Based Prototypical Learning (JMLR)](https://www.jmlr.org/papers/volume21/20-042/20-042.pdf)
13. [Lyu, Qiang, Wang, Weiqiang (2023). Compositional Prototypical Networks for Few-Shot Classification. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2306.06584)
14. [Compositional Prototypical Networks for Few-Shot Classification (AAAI)](https://ojs.aaai.org/index.php/AAAI/article/view/26082)
15. [Improved prototypical networks for few-shot learning (Pattern Recognition Letters)](https://www.sciencedirect.com/science/article/abs/pii/S0167865520302610)
16. [DFPN: a dynamic fusion prototypical network for few-shot learning (Applied Intelligence, 2025)](https://link.springer.com/article/10.1007/s10489-025-06581-4)
17. [Proto-CLIP: Vision-Language Prototypical Network for Few-Shot Learning](https://arxiv.org/pdf/2307.03073v3.pdf)
18. [Prototype Rectification for Few-Shot Learning (ECCV 2020)](https://link.springer.com/chapter/10.1007/978-3-030-58452-8_43)
19. [Zhang, Chi and colleagues (2020). DeepEMD: Differentiable Earth Mover's Distance for Few-Shot Learning. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2003.06777)

---
*Initially written Sep 29, 2026 · Reviewed: Sep 30, 2026 · Edited: Oct 15, 2026; Oct 21, 2026 · Last review: Sep 30, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Machine learning and neural computation › Machine learning methods › Supervised, unsupervised, and semi-supervised learning › Classification algorithms

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/prototypical-network

English original: https://www.edgepedia.org/prototypical-network
