这是关于在监督学习任务中面对有限标注数据时该如何处理的第二部分。这次我们将引入一定量的人工标注工作,但受预算限制,因此我们需要明智地选择哪些样本进行标注。
符号说明
| 符号 | 含义 |
|---|---|
| $K$ | 唯一类别标签的数量。 |
| $(\mathbf{x}^l, y) \sim \mathcal{X}, y \in \{0, 1\}^K$ | 已标注数据集。$y$ 是真实标签的独热表示。 |
| $\mathbf{u} \sim \mathcal{U}$ | 未标注数据集。 |
| $\mathcal{D} = \mathcal{X} \cup \mathcal{U}$ | 整个数据集,包括已标注和未标注的样本。 |
| $\mathbf{x}$ | 任意样本,可以是已标注或未标注的。 |
| $\mathbf{x}_i$ | 第 $i$ 个样本。 |
| $U(\mathbf{x})$ | 用于主动学习选择的评分函数。 |
| $P_\theta(y \vert \mathbf{x})$ | 由 $\theta$ 参数化的 softmax 分类器。 |
| $\hat{y} = \arg\max_{y \in \mathcal{Y}} P_\theta(y \vert \mathbf{x})$ | 分类器最有信心的预测结果。 |
| $B$ | 标注预算(可标注的最大样本数量)。 |
| $b$ | 批次大小。 |
什么是主动学习?
给定一个未标注数据集 $\mathcal{U}$ 和固定的标注成本 $B$,主动学习旨在从 $\mathcal{U}$ 中选择一个包含 $B$ 个样本的子集进行标注,使得这些样本能够最大程度地提升模型性能。这是一种有效的学习方法,尤其适用于数据标注困难且成本高昂的场景,例如医学影像。这篇 2010 年的经典综述论文列出了许多关键概念。虽然某些传统方法可能不适用于深度学习,但本文的讨论主要聚焦于深度神经网络模型和批量训练模式。
为简化讨论,我们假设以下所有章节中的任务都是一个 $K$ 类分类问题。参数为 $\theta$ 的模型输出一个关于候选标签的概率分布,该分布可能经过校准也可能未经过校准,记为 $P_\theta(y \vert \mathbf{x})$,而最可能的预测结果是 $\hat{y} = \arg\max_{y \in \mathcal{Y}} P_\theta(y \vert \mathbf{x})$。
采集函数
确定接下来最值得标注的样本的过程被称为“采样策略”或“查询策略”。采样过程中的评分函数被称为“采集函数”,记作 $U(\mathbf{x})$。得分较高的数据点如果被标注,预计能为模型训练带来更高价值。
以下是几种基本的采样策略。
不确定性采样
不确定性采样会选择模型预测最不确定的样本。对于单个模型,不确定性可以通过预测概率来估计,不过一个常见的批评是,深度学习模型的预测往往未经校准,与真实不确定性的相关性不佳。事实上,深度学习模型常常过于自信。
- 最低置信度得分,也称为变异比率:$U(\mathbf{x}) = 1 - P_\theta(\hat{y} \vert \mathbf{x})$。
- 间隔得分:$U(\mathbf{x}) = P_\theta(\hat{y}_1 \vert \mathbf{x}) - P_\theta(\hat{y}_2 \vert \mathbf{x})$,其中 $\hat{y}_1$ 和 $\hat{y}_2$ 分别是可能性最高和次高的预测标签。
- 熵:$U(\mathbf{x}) = \mathcal{H}(P_\theta(y \vert \mathbf{x})) = - \sum_{y \in \mathcal{Y}} P_\theta(y \vert \mathbf{x}) \log P_\theta(y \vert \mathbf{x})$。
另一种量化不确定性的方法是依赖一个专家模型委员会,称为查询委员会(QBC)。QBC 基于一组意见来衡量不确定性,因此保持委员会成员之间的分歧程度至关重要。假设委员会池中有 $C$ 个模型,每个模型的参数分别为 $\theta_1, \dots, \theta_C$。
- 投票者熵:$U(\mathbf{x}) = \mathcal{H}(\frac{V(y)}{C})$,其中 $V(y)$ 统计委员会对标签 $y$ 的投票数量。
- 共识熵:$U(\mathbf{x}) = \mathcal{H}(P_\mathcal{C})$,其中 $P_\mathcal{C}$ 是委员会预测的平均值。
- KL 散度:$U(\mathbf{x}) = \frac{1}{C} \sum_{c=1}^C D_\text{KL} (P_{\theta_c} | P_\mathcal{C})$
多样性采样
多样性采样旨在找到一组能够良好代表整体数据分布的样本。多样性之所以重要,是因为模型需要能在现实世界中的任何数据上表现良好,而不仅仅是在一个狭窄的子集上。选出的样本应能代表底层分布。常见的方法通常依赖于量化样本之间的相似性。
期望模型变化
期望模型变化指的是一个样本对模型训练所产生的影响。这种影响可以体现在模型权重上,也可以体现在训练损失的改善上。后续章节将回顾几项关于如何衡量选定数据样本所引发模型影响的研究工作。
混合策略
上述许多方法并非互斥。混合采样策略会同时考量数据点的不同属性,将多种采样偏好整合到同一方案中。我们通常希望选出既具有不确定性又具有高度代表性的样本。
深度采集函数
衡量不确定性
模型不确定性通常分为两类(Der Kiureghian & Ditlevsen 2009, Kendall & Gal 2017):
- 偶然不确定性是由数据中的噪声(例如传感器数据、测量过程中的噪声)引入的,它可能依赖于输入,也可能与输入无关。由于缺少关于真实标签的信息,这种不确定性通常被认为是不可约减的。
- 认知不确定性指的是模型参数本身的不确定性,因此我们不知道模型是否能够最好地解释数据。从理论上讲,这种不确定性可以通过获取更多数据来降低。
集成与近似集成
在机器学习中,使用集成方法来提升模型性能有着悠久的传统。当模型之间存在显著多样性时,集成方法有望产生更好的结果。这一集成理论已被许多机器学习算法所证实;例如,AdaBoost 通过聚合多个弱学习器,其表现可以媲美甚至超越单个强学习器。自助法通过多次重采样进行集成,以实现对指标更准确的估计。随机森林或 GBM 也是集成方法有效性的良好例证。
为了获得更好的不确定性估计,直觉上可以聚合一组独立训练的模型。然而,训练单个深度神经网络模型已经成本高昂,更不用说训练多个了。在强化学习中,Bootstrapped DQN(Osband 等人,2016)配备了多个价值头,并依靠一组 Q 值近似之间的不确定性来指导强化学习中的探索。
在主动学习中,一种更常见的方法是使用 dropout 来“模拟”概率高斯过程(Gal & Ghahramani 2016)。因此,我们集成从同一模型收集的多个样本,但在前向传播过程中应用了不同的 dropout 掩码,以估计模型不确定性(认知不确定性)。这个过程被称为 MC dropout(蒙特卡洛 dropout),其中 dropout 应用于每个权重层之前,已被证明在数学上等价于概率深度高斯过程的近似(Gal & Ghahramani 2016)。这个简单的想法已被证明对小型数据集的分类有效,并广泛应用于需要高效模型不确定性估计的场景。
DBAL(深度贝叶斯主动学习;Gal 等人,2017)使用 MC dropout 来近似贝叶斯神经网络,从而学习模型权重的分布。在他们的实验中,MC dropout 的表现优于随机基线和平均标准差(Mean STD),与变异比率和熵测量的表现相似。
Beluch 等人(2018)将基于集成的方法与 MC dropout 进行了比较,发现朴素集成(即分别独立训练多个模型)与变异比率的组合比其他方法能产生校准更好的预测。然而,朴素集成成本非常高,因此他们探索了几种更便宜的替代方案:
- 快照集成:使用循环学习率调度来训练一个隐式集成,使其收敛到不同的局部最小值。
- 多样性鼓励集成(DEE):使用一个经过少量 epoch 训练的基础网络作为 $n$ 个不同网络的初始化,每个网络都通过 dropout 训练以鼓励多样性。
- 分头方法:一个基础模型拥有多个头,每个头对应一个分类器。
遗憾的是,上述所有廉价的隐式集成选项的表现都不如朴素集成。考虑到计算资源的限制,MC dropout 仍然是一个相当不错且经济的选择。自然地,人们也尝试将集成与 MC dropout 结合(Pop & Fulop 2018),通过随机集成来获得额外的性能提升。
参数空间中的不确定性
反向传播贝叶斯(Blundell 等人,2015)直接测量神经网络中的权重不确定性。该方法维护权重 $\mathbf{w}$ 上的概率分布,该分布被建模为变分分布 $q(\mathbf{w} \vert \theta)$,因为真实后验 $p(\mathbf{w} \vert \mathcal{D})$ 无法直接处理。其损失函数是最小化 $q(\mathbf{w} \vert \theta)$ 与 $p(\mathbf{w} \vert \mathcal{D})$ 之间的 KL 散度,
$$ \begin{aligned} \mathcal{L}(\theta) &= \text{KL}[q(\mathbf{w}\vert\theta) \| p(\mathbf{w} \vert \mathcal{D})] \\ &= \int q(\mathbf{w}\vert\theta) \log \frac{q(\mathbf{w}\vert\theta)}{p(\mathbf{w}) p(\mathcal{D}\vert \mathbf{w})} d\mathbf{w} \\ &= \text{KL}[q(\mathbf{w}\vert\theta) \| p(w)] - \mathbb{E}_{q(\mathbf{w}\vert\theta)} [\log p(\mathcal{D} \vert \mathbf{w})] \\ &\approx \log q(\mathbf{w} \vert \theta) - \log p(\mathbf{w}) p(\mathcal{D}\vert \mathbf{w}) & \text{;蒙特卡洛采样;}q(\mathbf{w} \vert \theta)\text{ 与 }p(\mathbf{w})\text{ 接近。} \end{aligned} $$
变分分布 $q$ 通常是一个具有对角协方差的高斯分布,每个权重从 $\mathcal{N}(\mu_i, \sigma_i^2)$ 中采样。为确保 $\sigma_i$ 的非负性,它通过 softplus 进一步参数化,即 $\sigma_i = \log(1 + \exp(\rho_i))$,其中变分参数为 $\theta = \{\mu_i , \rho_i\}^d_{i=1}$。
反向传播贝叶斯的过程可以总结如下:
- 采样 $\epsilon \sim \mathcal{N}(0, I)$
- 令 $\mathbf{w} = \mu + \log(1+ \exp(\rho)) \circ \epsilon$
- 令 $\theta = (\mu, \rho)$
- 令 $f(\mathbf{w}, \theta) = \log q(\mathbf{w} \vert \theta) - \log p(\mathbf{w})p(\mathcal{D}\vert \mathbf{w})$
- 计算 $f(\mathbf{w}, \theta)$ 关于 $\mu$ 和 $\rho$ 的梯度,然后更新 $\theta$。
- 不确定性通过在推理过程中采样不同的模型权重来衡量。
损失预测
损失目标引导着模型训练。较低的损失值表明模型能够做出良好且准确的预测。Yoo & Kweon (2019) 设计了一个损失预测模块,用于预测未标注输入的损失值,以此评估模型在给定数据上的预测质量。如果损失预测模块对某些数据样本的预测结果不确定(即损失值高),则选择这些样本。该损失预测模块是一个带有 dropout 的简单 MLP,它接收多个中间层特征作为输入,并在全局平均池化后将这些特征拼接起来。
令 $\hat{l}$ 为损失预测模块的输出,$l$ 为真实损失。在训练损失预测模块时,简单的 MSE 损失 $=(l - \hat{l})^2$ 并非一个好的选择,因为随着模型学习表现更好,损失会随时间降低。一个好的学习目标应独立于目标损失的尺度变化。因此,他们转而依赖样本对的比较。在每个大小为 $b$ 的批次内,存在 $b/2$ 对样本 $(\mathbf{x}_i, \mathbf{x}_j)$,损失预测模型需要正确预测哪个样本的损失更大。
$$ \begin{aligned} \mathcal{L}_\text{loss}(\mathbf{x}_i, \mathbf{x}_j) &= \max\big( 0, -\mathbb{1}(l(\mathbf{x}_i), l(\mathbf{x}_j)) \cdot (\hat{l}(\mathbf{x}_i) - \hat{l}(\mathbf{x}_j)) + \epsilon \big) \\ \text{其中 } \mathbb{1}(l_i, l_j) &= \begin{cases} +1 & \text{如果 }l_i > l_j \\ -1 & \text{其他情况} \end{cases} \end{aligned} $$
其中 $\epsilon$ 是一个预定义的正边距常数。
在三个视觉任务的实验中,基于损失预测的主动学习选择表现优于随机基线、基于熵的获取方法和核心集方法。
对抗性设置
Sinha 等人(2019)提出了一种类似 GAN 的设置,名为 VAAL(变分对抗主动学习),其中训练一个判别器来区分未标注数据和已标注数据。有趣的是,在 VAAL 中,主动学习的采集标准并不依赖于任务性能。
- $\beta$-VAE 分别针对已标注数据和未标注数据学习一个潜在特征空间 $\mathbf{z}^l \cup \mathbf{z}^u$,旨在欺骗判别器 $D(.)$,使其认为所有数据点都来自已标注池;
- 判别器 $D(.)$ 基于潜在表示 $\mathbf{z}$ 预测一个样本是已标注(1)还是未标注(0)。VAAL 选择判别器得分较低的未标注样本,这表明这些样本与之前已标注的样本有足够大的差异。
VAAL 中 VAE 表示学习的损失包含两部分:重建部分(最小化给定样本的 ELBO)和对抗部分(已标注数据和未标注数据来自同一概率分布 $q_\phi$):
$$ \begin{aligned} \mathcal{L}_\text{VAE} &= \lambda_1 \mathcal{L}^\text{rec}_\text{VAE} + \lambda_2 \mathcal{L}^\text{adv}_\text{VAE} \\ \mathcal{L}^\text{rec}_\text{VAE} &= \mathbb{E}[\log p_\theta(\mathbf{x}^l \vert \mathbf{z}^l)] - \beta \text{KL}(q_\phi(\mathbf{z}^l \vert \mathbf{x}^l) \| p(\mathbf{\tilde{z}})) + \mathbb{E}[\log p_\theta(\mathbf{u} \vert \mathbf{z}^u)] - \beta \text{KL}(q_\phi(\mathbf{z}^u \vert \mathbf{u}) \| p(\mathbf{\tilde{z}})) \\ \mathcal{L}^\text{adv}_\text{VAE} &= - \mathbb{E}[\log D(q_\phi (\mathbf{z}^l \vert \mathbf{x}^l))] - \mathbb{E}[\log D(q_\phi(\mathbf{z}^u \vert \mathbf{u}))] \end{aligned} $$
其中 $p(\mathbf{\tilde{z}})$ 是一个作为预定义先验的单位高斯分布,$\beta$ 是拉格朗日参数。
判别器损失为:
$$ \mathcal{L}_D = -\mathbb{E}[\log D(q_\phi (\mathbf{z}^l \vert \mathbf{x}^l))] - \mathbb{E}[\log (1 - D(q_\phi (\mathbf{z}^u \vert \mathbf{u})))] $$
消融研究表明,联合训练 VAE 和判别器至关重要。其结果对初始标注池的偏差、不同的标注预算以及有噪声的 oracle 均具有鲁棒性。
MAL(极小极大主动学习;Ebrahimi 等人,2021)是 VAAL 的扩展。MAL 框架由一个最小化熵的特征编码网络 $F$ 后接一个最大化熵的分类器 $C$ 组成。这种极小极大设置缩小了标注数据与未标注数据之间的分布差距。
特征编码器 $F$ 将样本编码为 $\ell_2$ 归一化的 $d$ 维潜在向量。假设有 $K$ 个类别,分类器 $C$ 由参数 $\mathbf{W} \in \mathbb{R}^{d \times K}$ 定义。
(1)首先,通过简单的交叉熵损失在标注样本上训练 $F$ 和 $C$,以获得良好的分类结果,
$$ \mathcal{L}_\text{CE} = -\mathbb{E}_{(\mathbf{x}^l, y) \sim \mathcal{X}} \sum_{k=1}^K \mathbb{1}[k=y] \log\Big( \sigma(\frac{1}{T} \frac{\mathbf{W}^\top F\big(\mathbf{x}^l)}{\|F(\mathbf{x}^l)\|}\big) \Big) $$
(2)在未标注样本上训练时,MAL 依赖于一个极小极大博弈设置
$$ \begin{aligned} \mathcal{L}_\text{Ent} &= -\sum^K_{k=1} p(y=k \vert \mathbf{u}) \log p(y=k\vert \mathbf{u}) \\ \theta^*_F, \theta^*_C &= \min_F\max_C \mathcal{L}_\text{Ent} \\ \theta_F &\gets \theta_F - \alpha_1 \nabla \mathcal{L}_\text{Ent} \\ \theta_C &\gets \theta_C + \alpha_2 \nabla \mathcal{L}_\text{Ent} \end{aligned} $$
其中,
- 首先,最小化 $F$ 中的熵,促使具有相似预测标签的未标注样本拥有相似的特征。
- 对抗性地最大化 $C$ 中的熵,则会使预测遵循更均匀的类别分布。(我的理解是,由于未标注样本的真实标签未知,我们不应在此阶段优化分类器以最大化预测标签。)
判别器的训练方式与 VAAL 中相同。
MAL 中的采样策略同时考虑了多样性和不确定性:
- 多样性:$D$ 的分数表示一个样本与先前见过的示例的相似程度。分数越接近 0,越有利于选择不熟悉的数据点。
- 不确定性:使用由 $C$ 获得的熵。熵值越高,表明模型尚无法做出有把握的预测。
实验在图像分类和分割任务上,将 MAL 与随机、熵、核心集、BALD 和 VAAL 等基线方法进行了比较。结果看起来相当强劲。
CAL(对比主动学习;Margatina et al. 2021)旨在选择对比样本。如果两个具有不同标签的数据点在网络表示 $\Phi(.)$ 上相似,它们在 CAL 中被视为对比样本。给定一对对比样本 $(\mathbf{x}_i, \mathbf{x}_j)$,它们应满足
$$ d(\Phi(\mathbf{x}_i), \Phi(\mathbf{x}_j)) < \epsilon \quad\text{且}\quad \text{KL}(p(y\vert \mathbf{x}_i) \| p(y\vert \mathbf{x}_j)) \rightarrow \infty $$
给定一个未标注样本 $\mathbf{x}$,CAL 执行以下过程:
- 在已标注样本 $\{(\mathbf{x}^l_i, y_i\}_{i=1}^M \subset \mathcal{X}$ 中,选择模型特征空间里距离最近的 $k$ 个邻居。
- 计算 $\mathbf{x}$ 与 $\{\mathbf{x}^l\}$ 中每个样本的模型输出概率之间的 KL 散度。$\mathbf{x}$ 的对比分数是这些 KL 散度值的平均值:$s(\mathbf{x}) = \frac{1}{M} \sum_{i=1}^M \text{KL}(p(y \vert \mathbf{x}^l_i | p(y \vert \mathbf{x}))$。
- 具有高对比分数的样本会被选中用于主动学习。
在多种分类任务上,CAL 的实验结果看起来与熵基线方法相似。
衡量代表性
核心集方法
核心集是计算几何中的一个概念,指代一个能够近似更大点集形状的小型点集。这种近似可以通过某种几何度量来刻画。在主动学习中,我们期望在核心集上训练的模型能够与在整个数据集上训练的模型表现相当。
Sener 和 Savarese(2018)将主动学习视为一个核心集选择问题。假设在训练过程中总共可以访问 $N$ 个样本。在主动学习过程中,每个时间步 $t$ 都会有一小部分数据点被标注,记为 $\mathcal{S}^{(t)}$。学习目标的上界可以写成如下形式,其中核心集损失被定义为标注样本上的平均经验损失与包含未标注样本的整个数据集上的损失之间的差值。
$$ \begin{aligned} \mathbb{E}_{(\mathbf{x}, y) \sim p} [\mathcal{L}(\mathbf{x}, y)] \leq& \bigg\vert \mathbb{E}_{(\mathbf{x}, y) \sim p} [\mathcal{L}(\mathbf{x}, y)] - \frac{1}{N} \sum_{i=1}^N \mathcal{L}(\mathbf{x}_i, y_i) \bigg\vert & \text{;泛化误差}\\ +& \frac{1}{\vert \mathcal{S}^{(t)} \vert} \sum_{j=1}^{\vert \mathcal{S}^{(t)} \vert} \mathcal{L}(\mathbf{x}^l_j, y_j) & \text{;训练误差}\\ +& \bigg\vert \frac{1}{N} \sum_{i=1}^N \mathcal{L}(\mathbf{x}_i, y_i) - \frac{1}{\vert \mathcal{S}^{(t)} \vert} \sum_{j=1}^{\vert \mathcal{S}^{(t)} \vert} \mathcal{L}(\mathbf{x}^l_j, y_j) \bigg\vert & \text{;核心集误差} \end{aligned} $$
那么主动学习问题可以重新定义为:
$$ \min_{\mathcal{S}^{(t+1)} : \vert \mathcal{S}^{(t+1)} \vert \leq b} \bigg\vert \frac{1}{N}\sum_{i=1}^N \mathcal{L}(\mathbf{x}_i, y_i) - \frac{1}{\vert \mathcal{S}^{(t)} \cup \mathcal{S}^{(t+1)} \vert} \sum_{j=1}^{\vert \mathcal{S}^{(t)} \cup \mathcal{S}^{(t+1)} \vert} \mathcal{L}(\mathbf{x}^l_j, y_j) \bigg\vert $$
这等价于 $k$-中心问题:选择 $b$ 个中心点,使得数据点与其最近中心点之间的最大距离最小化。该问题是 NP 难问题。近似解依赖于贪心算法。
当类别数量较少时,该方法在图像分类任务上表现良好。当类别数量增长到很大或数据维度增加时(“维度灾难”),核心集方法的效果会变差(Sinha 等人,2019)。
由于核心集选择成本高昂,Coleman 等人(2020 年)尝试使用一个较弱的模型(例如,架构更小、更弱,未完全训练),并发现经验上,使用较弱模型作为代理可以显著缩短每次重复的数据选择周期(即训练模型和选择样本),而不会对最终误差造成太大影响。他们的方法被称为 SVP(通过代理进行选择)。
多样化的梯度嵌入
BADGE(基于多样化梯度嵌入的批量主动学习;Ash 等人,2020 年)在梯度空间中同时追踪模型的不确定性和数据的多样性。不确定性通过相对于网络最后一层的梯度幅度来衡量,而多样性则通过一组在梯度空间中分布的多样化样本来捕捉。
- 不确定性。给定一个未标注样本 $\mathbf{x}$,BADGE 首先计算预测值 $\hat{y}$ 以及损失函数在 $(\mathbf{x}, \hat{y})$ 上相对于最后一层参数的梯度 $g_\mathbf{x}$。他们观察到,$g_\mathbf{x}$ 的范数可以保守地估计该样本对模型学习的影响,而高置信度的样本往往具有较小幅度的梯度嵌入。
- 多样性。给定许多样本的梯度嵌入 $g_\mathbf{x}$,BADGE 运行 $k$-means++ 算法来相应地采样数据点。
衡量训练效果
量化模型变化
Settles 等人(2008 年)引入了一种主动学习查询策略,名为 EGL(期望梯度长度)。其动机是找到那些如果其标签已知,就能引发模型最大更新的样本。
设 $\nabla \mathcal{L}(\theta)$ 为损失函数相对于模型参数的梯度。具体来说,给定一个未标注样本 $\mathbf{x}_i$,我们需要计算假设标签为 $y \in \mathcal{Y}$ 时的梯度 $\nabla \mathcal{L}^{(y)}(\theta)$。由于真实标签 $y_i$ 未知,EGL 依赖当前模型的信念来计算期望的梯度变化:
$$ \text{EGL}(\mathbf{x}_i) = \sum_{y_i \in \mathcal{Y}} p(y=y_i \vert \mathbf{x}) \|\nabla \mathcal{L}^{(y_i)}(\theta)\| $$
BALD(基于分歧的贝叶斯主动学习;Houlsby 等人,2011)旨在识别那些能使模型权重信息增益最大化的样本,这等价于使期望后验熵的减少量最大化。
$$ \begin{aligned} I[\boldsymbol{\theta}, y \vert x,\mathcal{D}] &= H(\boldsymbol{\theta} \vert \mathcal{D}) - \mathbb{E}_{y \sim p(y \vert \boldsymbol{x}, \mathcal{D})} \big[ H(\boldsymbol{\theta} \vert y, \boldsymbol{x}, \mathcal{D}) \big] & \text{;期望后验熵的减少量}\\ &= H(y \vert \boldsymbol{x}, \mathcal{D}) - \mathbb{E}_{\boldsymbol{\theta} \sim p(\boldsymbol{\theta} \vert \mathcal{D})} \big[ H(y \vert \boldsymbol{x}, \mathcal{\theta}) \big] \end{aligned} $$
其底层解释是“寻找这样的 $\mathbf{x}$:模型在边际上对 $y$ 最不确定(高 $H(y \vert \mathbf{x}, \mathcal{D})$),但参数的各个具体设定却对 $y$ 很有把握(低 $H(y \vert \mathbf{x}, \boldsymbol{\theta})$)”。换句话说,每个单独的后验采样都很有把握,但采样的集合却持有不同的意见。
BALD 最初是针对单个样本提出的,Kirsch 等人(2019)将其扩展为支持批量模式。
遗忘事件
为了探究神经网络是否倾向于遗忘先前学到的信息,Mariya Toneva 等人(2019)设计了一项实验:他们在训练过程中跟踪模型对每个样本的预测,并统计每个样本从分类正确变为错误,或从错误变为正确的转换次数。然后,样本可以据此进行分类:
- 可遗忘(冗余)样本:如果其类别标签在训练轮次之间发生变化。
- 不可遗忘样本:如果其类别标签分配在整个训练轮次中保持一致。这些样本一旦被学习,就再也不会被遗忘。
他们发现存在大量不可遗忘的样本,这些样本一旦被学习就再也不会被遗忘。带有噪声标签的样本或具有“不常见”特征(视觉上难以分类)的样本,属于最容易被遗忘的样本。实验经验性地验证了,可以安全地移除不可遗忘的样本,而不会影响模型性能。
在实现中,遗忘事件仅当某个样本包含在当前训练批次中时才被计数;也就是说,他们计算的是同一示例在后续小批次中多次出现时的遗忘情况。每个样本的遗忘事件数量在不同随机种子下相当稳定,且容易被遗忘的样本往往在训练后期才首次被学习。研究还发现,遗忘事件在整个训练期间以及不同架构之间具有可迁移性。
如果我们假设模型在训练过程中改变预测是模型不确定性的一个指标,那么遗忘事件可以作为主动学习获取的信号。然而,对于未标注样本,其真实标签是未知的。Bengar 等人(2021)为此提出了一种名为标签分散度的新指标。让我们观察整个训练过程:设 $c^*$ 是输入 $\mathbf{x}$ 最常被预测的标签,标签分散度衡量的是模型未将该样本预测为 $c^*$ 的训练步骤占比:
$$ \text{Dispersion}(\mathbf{x}) = 1 - \frac{f_\mathbf{x}}{T} \text{ 其中 } f_\mathbf{x} = \sum_{t=1}^T \mathbb{1}[\hat{y}_t = c^*], c^* = \arg\max_{c=1,\dots,C}\sum_{t=1}^T \mathbb{1}[\hat{y}_t = c] $$
在他们的实现中,分散度在每个训练周期(epoch)计算一次。如果模型始终对同一样本赋予相同标签,则标签分散度较低;但如果预测结果频繁变化,则分散度较高。标签分散度与网络不确定性相关,如下图所示:
混合策略
在批量模式下运行主动学习时,控制批次内的多样性非常重要。建议性标注(SA;Yang 等人,2017)是一种两步式混合策略,旨在同时选择高不确定性且高代表性的已标注样本。它利用基于已标注数据训练的模型集成所获得的不确定性,并结合核心集(core-sets)来选择具有代表性的数据样本。
- 首先,SA 从高不确定性得分的图像中选出前 $K$ 张,构成候选池 $\mathcal{S}_c \subseteq \mathcal{S}_U$。不确定性通过多个采用自助法训练的模型之间的分歧程度来衡量。
- 下一步是找出代表性最高的子集 $\mathcal{S}_a \subseteq \mathcal{S}_c$。两个输入的特征向量之间的余弦相似度近似反映了它们的相似程度。$\mathcal{S}_a$ 对 $\mathcal{S}_U$ 的代表性,体现了 $\mathcal{S}_a$ 能在多大程度上代表 $\mathcal{S}_u$ 中的所有样本,其定义如下:
$$ F(\mathcal{S}_a, \mathcal{S}_u) = \sum_{\mathbf{x}_j \in \mathcal{S}_u} f(\mathcal{S}_a, \mathbf{x}_j) = \sum_{\mathbf{x}_j \in \mathcal{S}_u} \max_{\mathbf{x}_i \in \mathcal{S}_a} \text{sim}(\mathbf{x}_i, \mathbf{x}_j) $$
在 $\mathcal{S}_c$ 中选取包含 $k$ 个数据点的子集 $\mathcal{S}_a \subseteq \mathcal{S}_c$,使其最大化 $F(\mathcal{S}_a, \mathcal{S}_u)$,这是最大集合覆盖问题的一个泛化版本。该问题属于 NP 难问题,其最佳的多项式时间近似算法是一种简单的贪心方法。
- 初始状态下,$\mathcal{S}_a = \emptyset$,且 $F(\mathcal{S}_a, \mathcal{S}_u) = 0$。
- 然后,迭代地将 $\mathcal{S}_c$ 中能使 $F(\mathcal{S}_a \cup I_i, \mathcal{S}_u)$ 相对于 $\mathcal{S}_a$ 最大化的 $\mathbf{x}_i$ 加入,直到 $\mathcal{S}_s$ 包含 $k$ 张图像。
Zhdanov (2019) 运行了与 SA 类似的流程,但在第二步中,它依赖 $k$-means 而非核心集,其中候选池的大小根据批次大小进行配置。给定批次大小 $b$ 和一个常数 $beta$(介于 10 到 50 之间),其步骤如下:
- 在已标注数据上训练一个分类器;
- 衡量每个未标注示例的信息量(例如,使用不确定性指标);
- 预筛选出信息量最高的前 $\beta b \geq b$ 个示例;
- 将 $\beta b$ 个示例聚类成 $B$ 个簇;
- 为本轮主动学习选出距离各簇中心最近的 $b$ 个不同示例。
主动学习可以进一步与半监督学习相结合,以节省预算。CEAL(成本效益主动学习;Yang 等人,2017)并行执行两项操作:
- 通过主动学习筛选出不确定性高的样本,并为其获取标注;
- 选择预测置信度最高的样本,并为其分配伪标签。置信度预测通过判断预测熵是否低于阈值 $\delta$ 来确定。随着模型性能随时间提升,阈值 $\delta$ 也会随时间衰减。
引用
引用格式:
Weng, Lilian. (2022年2月). 数据不足时的学习方法(第二部分):主动学习. Lil’Log. https://lilianweng.github.io/posts/2022-02-20-active-learning/.
或
@article{weng2022active,
title = "Learning with not Enough Data Part 2: Active Learning",
author = "Weng, Lilian",
journal = "lilianweng.github.io",
year = "2022",
month = "Feb",
url = "https://lilianweng.github.io/posts/2022-02-20-active-learning/"
}
参考文献
[1] Burr Settles. 主动学习文献综述. 威斯康星大学麦迪逊分校, 52(55-66):11, 2010.
[3] Yang 等人. “面向深度图像分类的成本效益主动学习” TCSVT 2016.
[4] Yarin Gal 等人. “将 Dropout 作为贝叶斯近似:在深度学习中表示模型不确定性.” ICML 2016.
[5] Blundell 等人. “神经网络中的权重不确定性(Bayes-by-Backprop)” ICML 2015.
[6] Settles 等人. “多实例主动学习.” NIPS 2007.
[7] Houlsby 等人. 面向分类与偏好学习的贝叶斯主动学习." arXiv 预印本 arXiv:1112.5745 (2020).
[8] Kirsch 等人. “BatchBALD:面向深度贝叶斯主动学习的高效且多样化的批量获取.” NeurIPS 2019.
[9] Beluch 等人. “集成方法在图像分类主动学习中的威力.” CVPR 2018.
[10] Sener 与 Savarese. “面向卷积神经网络的主动学习:一种核心集方法.” ICLR 2018.
[11] Yoo, Donggeun 与 Kweon, In So. “为主动学习而学习损失.” CVPR 2019.
[12] Margatina 等人. “通过获取对比样本进行主动学习.” EMNLP 2021.
[13] Sinha 等人. “变分对抗主动学习” ICCV 2019
[14] Ebrahimi 等人. “最小最大主动学习” arXiv 预印本 arXiv:2012.10467 (2021).
[15] Toneva, Mariya 等人. “深度神经网络学习过程中样本遗忘的实证研究.” ICLR 2019.
[16] Bengar, Javad Zolfaghari 等人. “当深度学习者改变主意时:面向主动学习的学习动态.” CAIP 2021.
[18] Zhdanov, Fedor. “多样化小批量主动学习” arXiv 预印本 arXiv:1901.05954 (2019).
This is part 2 of what to do when facing a limited amount of labeled data for supervised learning tasks. This time we will get some amount of human labeling work involved, but within a budget limit, and therefore we need to be smart when selecting which samples to label.
Notations
| Symbol | Meaning |
|---|---|
| $K$ | Number of unique class labels. |
| $(\mathbf{x}^l, y) \sim \mathcal{X}, y \in \{0, 1\}^K$ | Labeled dataset. $y$ is a one-hot representation of the true label. |
| $\mathbf{u} \sim \mathcal{U}$ | Unlabeled dataset. |
| $\mathcal{D} = \mathcal{X} \cup \mathcal{U}$ | The entire dataset, including both labeled and unlabeled examples. |
| $\mathbf{x}$ | Any sample which can be either labeled or unlabeled. |
| $\mathbf{x}_i$ | The $i$-th sample. |
| $U(\mathbf{x})$ | Scoring function for active learning selection. |
| $P_\theta(y \vert \mathbf{x})$ | A softmax classifier parameterized by $\theta$. |
| $\hat{y} = \arg\max_{y \in \mathcal{Y}} P_\theta(y \vert \mathbf{x})$ | The most confident prediction by the classifier. |
| $B$ | Labeling budget (the maximum number of samples to label). |
| $b$ | Batch size. |
What is Active Learning?
Given an unlabeled dataset $\mathcal{U}$ and a fixed amount of labeling cost $B$, active learning aims to select a subset of $B$ examples from $\mathcal{U}$ to be labeled such that they can result in maximized improvement in model performance. This is an effective way of learning especially when data labeling is difficult and costly, e.g. medical images. This classical survey paper in 2010 lists many key concepts. While some conventional approaches may not apply to deep learning, discussion in this post mainly focuses on deep neural models and training in batch mode.
To simplify the discussion, we assume that the task is a $K$-class classification problem in all the following sections. The model with parameters $\theta$ outputs a probability distribution over the label candidates, which may or may not be calibrated, $P_\theta(y \vert \mathbf{x})$ and the most likely prediction is $\hat{y} = \arg\max_{y \in \mathcal{Y}} P_\theta(y \vert \mathbf{x})$.
Acquisition Function
The process of identifying the most valuable examples to label next is referred to as “sampling strategy” or “query strategy”. The scoring function in the sampling process is named “acquisition function”, denoted as $U(\mathbf{x})$. Data points with higher scores are expected to produce higher value for model training if they get labeled.
Here is a list of basic sampling strategies.
Uncertainty Sampling
Uncertainty sampling selects examples for which the model produces most uncertain predictions. Given a single model, uncertainty can be estimated by the predicted probabilities, although one common complaint is that deep learning model predictions are often not calibrated and not correlated with true uncertainty well. In fact, deep learning models are often overconfident.
- Least confident score, also known as variation ratio: $U(\mathbf{x}) = 1 - P_\theta(\hat{y} \vert \mathbf{x})$.
- Margin score: $U(\mathbf{x}) = P_\theta(\hat{y}_1 \vert \mathbf{x}) - P_\theta(\hat{y}_2 \vert \mathbf{x})$, where $\hat{y}_1$ and $\hat{y}_2$ are the most likely and the second likely predicted labels.
- Entropy: $U(\mathbf{x}) = \mathcal{H}(P_\theta(y \vert \mathbf{x})) = - \sum_{y \in \mathcal{Y}} P_\theta(y \vert \mathbf{x}) \log P_\theta(y \vert \mathbf{x})$.
Another way to quantify uncertainty is to rely on a committee of expert models, known as Query-By-Committee (QBC). QBC measures uncertainty based on a pool of opinions and thus it is critical to keep a level of disagreement among committee members. Given $C$ models in the committee pool, each parameterized by $\theta_1, \dots, \theta_C$.
- Voter entropy: $U(\mathbf{x}) = \mathcal{H}(\frac{V(y)}{C})$, where $V(y)$ counts the number of votes from the committee on the label $y$.
- Consensus entropy: $U(\mathbf{x}) = \mathcal{H}(P_\mathcal{C})$, where $P_\mathcal{C}$ is the prediction averaging across the committee.
- KL divergence: $U(\mathbf{x}) = \frac{1}{C} \sum_{c=1}^C D_\text{KL} (P_{\theta_c} | P_\mathcal{C})$
Diversity Sampling
Diversity sampling intend to find a collection of samples that can well represent the entire data distribution. Diversity is important because the model is expected to work well on any data in the wild, just not on a narrow subset. Selected samples should be representative of the underlying distribution. Common approaches often rely on quantifying the similarity between samples.
Expected Model Change
Expected model change refers to the impact that a sample brings onto the model training. The impact can be the influence on the model weights or the improvement over the training loss. A later section reviews several works on how to measure model impact triggered by selected data samples.
Hybrid Strategy
Many methods above are not mutually exclusive. A hybrid sampling strategy values different attributes of data points, combining different sampling preferences into one. Often we want to select uncertain but also highly representative samples.
Deep Acquisition Function
Measuring Uncertainty
The model uncertainty is commonly categorized into two buckets (Der Kiureghian & Ditlevsen 2009, Kendall & Gal 2017):
- Aleatoric uncertainty is introduced by noise in the data (e.g. sensor data, noise in the measurement process) and it can be input-dependent or input-independent. It is generally considered as irreducible since there is missing information about the ground truth.
- Epistemic uncertainty refers to the uncertainty within the model parameters and therefore we do not know whether the model can best explain the data. This type of uncertainty is theoretically reducible given more data
Ensemble and Approximated Ensemble
There is a long tradition in machine learning of using ensembles to improve model performance. When there is a significant diversity among models, ensembles are expected to yield better results. This ensemble theory is proved to be correct by many ML algorithms; for example, AdaBoost aggregates many weak learners to perform similar or even better than a single strong learner. Bootstrapping ensembles multiple trials of resampling to achieve more accurate estimation of metrics. Random forests or GBM is also a good example for the effectiveness of ensembling.
To get better uncertainty estimation, it is intuitive to aggregate a collection of independently trained models. However, it is expensive to train a single deep neural network model, let alone many of them. In reinforcement learning, Bootstrapped DQN (Osband, et al. 2016) is equipped with multiple value heads and relies on the uncertainty among an ensemble of Q value approximation to guide exploration in RL.
In active learning, a commoner approach is to use dropout to “simulate” a probabilistic Gaussian process (Gal & Ghahramani 2016). We thus ensemble multiple samples collected from the same model but with different dropout masks applied during the forward pass to estimate the model uncertainty (epistemic uncertainty). The process is named MC dropout (Monte Carlo dropout), where dropout is applied before every weight layer, is approved to be mathematically equivalent to an approximation to the probabilistic deep Gaussian process (Gal & Ghahramani 2016). This simple idea has been shown to be effective for classification with small datasets and widely adopted in scenarios when efficient model uncertainty estimation is needed.
DBAL (Deep Bayesian active learning; Gal et al. 2017) approximates Bayesian neural networks with MC dropout such that it learns a distribution over model weights. In their experiment, MC dropout performed better than random baseline and mean standard deviation (Mean STD), similarly to variation ratios and entropy measurement.
Beluch et al. (2018) compared ensemble-based models with MC dropout and found that the combination of naive ensemble (i.e. train multiple models separately and independently) and variation ratio yields better calibrated predictions than others. However, naive ensembles are very expensive, so they explored a few alternative cheaper options:
- Snapshot ensemble: Use a cyclic learning rate schedule to train an implicit ensemble such that it converges to different local minima.
- Diversity encouraging ensemble (DEE): Use a base network trained for a small number of epochs as initialization for $n$ different networks, each trained with dropout to encourage diversity.
- Split head approach: One base model has multiple heads, each corresponding to one classifier.
Unfortunately all the cheap implicit ensemble options above perform worse than naive ensembles. Considering the limit on computational resources, MC dropout is still a pretty good and economical choice. Naturally, people also try to combine ensemble and MC dropout (Pop & Fulop 2018) to get a bit of additional performance gain by stochastic ensemble.
Uncertainty in Parameter Space
Bayes-by-backprop (Blundell et al. 2015) measures weight uncertainty in neural networks directly. The method maintains a probability distribution over the weights $\mathbf{w}$, which is modeled as a variational distribution $q(\mathbf{w} \vert \theta)$ since the true posterior $p(\mathbf{w} \vert \mathcal{D})$ is not tractable directly. The loss is to minimize the KL divergence between $q(\mathbf{w} \vert \theta)$ and $p(\mathbf{w} \vert \mathcal{D})$,
$$ \begin{aligned} \mathcal{L}(\theta) &= \text{KL}[q(\mathbf{w}\vert\theta) \| p(\mathbf{w} \vert \mathcal{D})] \\ &= \int q(\mathbf{w}\vert\theta) \log \frac{q(\mathbf{w}\vert\theta)}{p(\mathbf{w}) p(\mathcal{D}\vert \mathbf{w})} d\mathbf{w} \\ &= \text{KL}[q(\mathbf{w}\vert\theta) \| p(w)] - \mathbb{E}_{q(\mathbf{w}\vert\theta)} [\log p(\mathcal{D} \vert \mathbf{w})] \\ &\approx \log q(\mathbf{w} \vert \theta) - \log p(\mathbf{w}) p(\mathcal{D}\vert \mathbf{w}) & \text{; monte carlo sampling; }q(\mathbf{w} \vert \theta)\text{ & }p(\mathbf{w})\text{ are close.} \end{aligned} $$
The variational distribution $q$ is typically a Gaussian with diagonal covariance and each weight is sampled from $\mathcal{N}(\mu_i, \sigma_i^2)$. To ensure non-negativity of $\sigma_i$, it is further parameterized via softplus, $\sigma_i = \log(1 + \exp(\rho_i))$ where the variational parameters are $\theta = \{\mu_i , \rho_i\}^d_{i=1}$.
The process of Bayes-by-backprop can be summarized as:
- Sample $\epsilon \sim \mathcal{N}(0, I)$
- Let $\mathbf{w} = \mu + \log(1+ \exp(\rho)) \circ \epsilon$
- Let $\theta = (\mu, \rho)$
- Let $f(\mathbf{w}, \theta) = \log q(\mathbf{w} \vert \theta) - \log p(\mathbf{w})p(\mathcal{D}\vert \mathbf{w})$
- Calculate the gradient of $f(\mathbf{w}, \theta)$ w.r.t. to $\mu$ and $\rho$ and then update $\theta$.
- Uncertainty is measured by sampling different model weights during inference.
Loss Prediction
The loss objective guides model training. A low loss value indicates that a model can make good and accurate predictions. Yoo & Kweon (2019) designed a loss prediction module to predict the loss value for unlabeled inputs, as an estimation of how good a model prediction is on the given data. Data samples are selected if the loss prediction module makes uncertain predictions (high loss value) for them. The loss prediction module is a simple MLP with dropout, that takes several intermediate layer features as inputs and concatenates them after a global average pooling.
Let $\hat{l}$ be the output of the loss prediction module and $l$ be the true loss. When training the loss prediction module, a simple MSE loss $=(l - \hat{l})^2$ is not a good choice, because the loss decreases in time as the model learns to behave better. A good learning objective should be independent of the scale changes of the target loss. They instead rely on the comparison of sample pairs. Within each batch of size $b$, there are $b/2$ pairs of samples $(\mathbf{x}_i, \mathbf{x}_j)$ and the loss prediction model is expected to correctly predict which sample has a larger loss.
$$ \begin{aligned} \mathcal{L}_\text{loss}(\mathbf{x}_i, \mathbf{x}_j) &= \max\big( 0, -\mathbb{1}(l(\mathbf{x}_i), l(\mathbf{x}_j)) \cdot (\hat{l}(\mathbf{x}_i) - \hat{l}(\mathbf{x}_j)) + \epsilon \big) \\ \text{where } \mathbb{1}(l_i, l_j) &= \begin{cases} +1 & \text{if }l_i > l_j \\ -1 & \text{otherwise} \end{cases} \end{aligned} $$
where $\epsilon$ is a predefined positive margin constant.
In experiments on three vision tasks, active learning selection based on the loss prediction performs better than random baseline, entropy based acquisition and core-set.
Adversarial Setup
Sinha et al. (2019) proposed a GAN-like setup, named VAAL (Variational Adversarial Active Learning), where a discriminator is trained to distinguish unlabeled data from labeled data. Interestingly, active learning acquisition criteria does not depend on the task performance in VAAL.
- The $\beta$-VAE learns a latent feature space $\mathbf{z}^l \cup \mathbf{z}^u$, for labeled and unlabeled data respectively, aiming to trick the discriminator $D(.)$ that all the data points are from the labeled pool;
- The discriminator $D(.)$ predicts whether a sample is labeled (1) or not (0) based on a latent representation $\mathbf{z}$. VAAL selects unlabeled samples with low discriminator scores, which indicates that those samples are sufficiently different from previously labeled ones.
The loss for VAE representation learning in VAAL contains both a reconstruction part (minimizing the ELBO of given samples) and an adversarial part (labeled and unlabeled data is drawn from the same probability distribution $q_\phi$):
$$ \begin{aligned} \mathcal{L}_\text{VAE} &= \lambda_1 \mathcal{L}^\text{rec}_\text{VAE} + \lambda_2 \mathcal{L}^\text{adv}_\text{VAE} \\ \mathcal{L}^\text{rec}_\text{VAE} &= \mathbb{E}[\log p_\theta(\mathbf{x}^l \vert \mathbf{z}^l)] - \beta \text{KL}(q_\phi(\mathbf{z}^l \vert \mathbf{x}^l) \| p(\mathbf{\tilde{z}})) + \mathbb{E}[\log p_\theta(\mathbf{u} \vert \mathbf{z}^u)] - \beta \text{KL}(q_\phi(\mathbf{z}^u \vert \mathbf{u}) \| p(\mathbf{\tilde{z}})) \\ \mathcal{L}^\text{adv}_\text{VAE} &= - \mathbb{E}[\log D(q_\phi (\mathbf{z}^l \vert \mathbf{x}^l))] - \mathbb{E}[\log D(q_\phi(\mathbf{z}^u \vert \mathbf{u}))] \end{aligned} $$
where $p(\mathbf{\tilde{z}})$ is a unit Gaussian as a predefined prior and $\beta$ is the Lagrangian parameter.
The discriminator loss is:
$$ \mathcal{L}_D = -\mathbb{E}[\log D(q_\phi (\mathbf{z}^l \vert \mathbf{x}^l))] - \mathbb{E}[\log (1 - D(q_\phi (\mathbf{z}^u \vert \mathbf{u})))] $$
Ablation studies showed that jointly training VAE and discriminator is critical. Their results are robust to the biased initial labeled pool, different labeling budgets and noisy oracle.
MAL (Minimax Active Learning; Ebrahimiet al. 2021) is an extension of VAAL. The MAL framework consists of an entropy minimizing feature encoding network $F$ followed by an entropy maximizing classifier $C$. This minimax setup reduces the distribution gap between labeled and unlabeled data.
A feature encoder $F$ encodes a sample into a $\ell_2$-normalized $d$-dimensional latent vector. Assuming there are $K$ classes, a classifier $C$ is parameterized by $\mathbf{W} \in \mathbb{R}^{d \times K}$.
(1) First $F$ and $C$ are trained on labeled samples by a simple cross entropy loss to achieve good classification results,
$$ \mathcal{L}_\text{CE} = -\mathbb{E}_{(\mathbf{x}^l, y) \sim \mathcal{X}} \sum_{k=1}^K \mathbb{1}[k=y] \log\Big( \sigma(\frac{1}{T} \frac{\mathbf{W}^\top F\big(\mathbf{x}^l)}{\|F(\mathbf{x}^l)\|}\big) \Big) $$
(2) When training on the unlabeled examples, MAL relies on a minimax game setup
$$ \begin{aligned} \mathcal{L}_\text{Ent} &= -\sum^K_{k=1} p(y=k \vert \mathbf{u}) \log p(y=k\vert \mathbf{u}) \\ \theta^*_F, \theta^*_C &= \min_F\max_C \mathcal{L}_\text{Ent} \\ \theta_F &\gets \theta_F - \alpha_1 \nabla \mathcal{L}_\text{Ent} \\ \theta_C &\gets \theta_C + \alpha_2 \nabla \mathcal{L}_\text{Ent} \end{aligned} $$
where,
- First, minimizing the entropy in $F$ encourages unlabeled samples associated with similar predicted labels to have similar features.
- Maximizing the entropy in $C$ adversarially makes the prediction to follow a more uniform class distribution. (My understanding here is that because the true label of an unlabeled sample is unknown, we should not optimize the classifier to maximize the predicted labels just yet.)
The discriminator is trained in the same way as in VAAL.
Sampling strategy in MAL considers both diversity and uncertainty:
- Diversity: the score of $D$ indicates how similar a sample is to previously seen examples. A score closer to 0 is better to select unfamiliar data points.
- Uncertainty: use the entropy obtained by $C$. A higher entropy score indicates that the model cannot make a confident prediction yet.
The experiments compared MAL to random, entropy, core-set, BALD and VAAL baselines, on image classification and segmentation tasks. The results look pretty strong.
CAL (Contrastive Active Learning; Margatina et al. 2021) intends to select contrastive examples. If two data points with different labels share similar network representations $\Phi(.)$, they are considered as contrastive examples in CAL. Given a pair of contrastive examples $(\mathbf{x}_i, \mathbf{x}_j)$, they should
$$ d(\Phi(\mathbf{x}_i), \Phi(\mathbf{x}_j)) < \epsilon \quad\text{and}\quad \text{KL}(p(y\vert \mathbf{x}_i) \| p(y\vert \mathbf{x}_j)) \rightarrow \infty $$
Given an unlabeled sample $\mathbf{x}$, CAL runs the following process:
- Select the top $k$ nearest neighbors in the model feature space among the labeled samples, $\{(\mathbf{x}^l_i, y_i\}_{i=1}^M \subset \mathcal{X}$.
- Compute the KL divergence between the model output probabilities of $\mathbf{x}$ and each in $\{\mathbf{x}^l\}$. The contrastive score of $\mathbf{x}$ is the average of these KL divergence values: $s(\mathbf{x}) = \frac{1}{M} \sum_{i=1}^M \text{KL}(p(y \vert \mathbf{x}^l_i | p(y \vert \mathbf{x}))$.
- Samples with high contrastive scores are selected for active learning.
On a variety of classification tasks, the experiment results of CAL look similar to the entropy baseline.
Measuring Representativeness
Core-sets Approach
A core-set is a concept in computational geometry, referring to a small set of points that approximates the shape of a larger point set. Approximation can be captured by some geometric measure. In the active learning, we expect a model that is trained over the core-set to behave comparably with the model on the entire data points.
Sener & Savarese (2018) treats active learning as a core-set selection problem. Let’s say, there are $N$ samples in total accessible during training. During active learning, a small set of data points get labeled at every time step $t$, denoted as $\mathcal{S}^{(t)}$. The upper bound of the learning objective can be written as follows, where the core-set loss is defined as the difference between average empirical loss over the labeled samples and the loss over the entire dataset including unlabelled ones.
$$ \begin{aligned} \mathbb{E}_{(\mathbf{x}, y) \sim p} [\mathcal{L}(\mathbf{x}, y)] \leq& \bigg\vert \mathbb{E}_{(\mathbf{x}, y) \sim p} [\mathcal{L}(\mathbf{x}, y)] - \frac{1}{N} \sum_{i=1}^N \mathcal{L}(\mathbf{x}_i, y_i) \bigg\vert & \text{; Generalization error}\\ +& \frac{1}{\vert \mathcal{S}^{(t)} \vert} \sum_{j=1}^{\vert \mathcal{S}^{(t)} \vert} \mathcal{L}(\mathbf{x}^l_j, y_j) & \text{; Training error}\\ +& \bigg\vert \frac{1}{N} \sum_{i=1}^N \mathcal{L}(\mathbf{x}_i, y_i) - \frac{1}{\vert \mathcal{S}^{(t)} \vert} \sum_{j=1}^{\vert \mathcal{S}^{(t)} \vert} \mathcal{L}(\mathbf{x}^l_j, y_j) \bigg\vert & \text{; Core-set error} \end{aligned} $$
Then the active learning problem can be redefined as:
$$ \min_{\mathcal{S}^{(t+1)} : \vert \mathcal{S}^{(t+1)} \vert \leq b} \bigg\vert \frac{1}{N}\sum_{i=1}^N \mathcal{L}(\mathbf{x}_i, y_i) - \frac{1}{\vert \mathcal{S}^{(t)} \cup \mathcal{S}^{(t+1)} \vert} \sum_{j=1}^{\vert \mathcal{S}^{(t)} \cup \mathcal{S}^{(t+1)} \vert} \mathcal{L}(\mathbf{x}^l_j, y_j) \bigg\vert $$
It is equivalent to the $k$-Center problem: choose $b$ center points such that the largest distance between a data point and its nearest center is minimized. This problem is NP-hard. An approximate solution depends on the greedy algorithm.
It works well on image classification tasks when there is a small number of classes. When the number of classes grows to be large or the data dimensionality increases (“curse of dimensionality”), the core-set method becomes less effective (Sinha et al. 2019).
Because the core-set selection is expensive, Coleman et al. (2020) experimented with a weaker model (e.g. smaller, weaker architecture, not fully trained) and found that empirically using a weaker model as a proxy can significantly shorten each repeated data selection cycle of training models and selecting samples, without hurting the final error much. Their method is referred to as SVP (Selection via Proxy).
Diverse Gradient Embedding
BADGE (Batch Active learning by Diverse Gradient Embeddings; Ash et al. 2020) tracks both model uncertainty and data diversity in the gradient space. Uncertainty is measured by the gradient magnitude w.r.t. the final layer of the network and diversity is captured by a diverse set of samples that span in the gradient space.
- Uncertainty. Given an unlabeled sample $\mathbf{x}$, BADGE first computes the prediction $\hat{y}$ and the gradient $g_\mathbf{x}$ of the loss on $(\mathbf{x}, \hat{y})$ w.r.t. the last layer’s parameters. They observed that the norm of $g_\mathbf{x}$ conservatively estimates the example’s influence on the model learning and high-confidence samples tend to have gradient embeddings of small magnitude.
- Diversity. Given many gradient embeddings of many samples, $g_\mathbf{x}$, BADGE runs $k$-means++ to sample data points accordingly.
Measuring Training Effects
Quantify Model Changes
Settles et al. (2008) introduced an active learning query strategy, named EGL (Expected Gradient Length). The motivation is to find samples that can trigger the greatest update on the model if their labels are known.
Let $\nabla \mathcal{L}(\theta)$ be the gradient of the loss function with respect to the model parameters. Specifically, given an unlabeled sample $\mathbf{x}_i$, we need to calculate the gradient assuming the label is $y \in \mathcal{Y}$, $\nabla \mathcal{L}^{(y)}(\theta)$. Because the true label $y_i$ is unknown, EGL relies on the current model belief to compute the expected gradient change:
$$ \text{EGL}(\mathbf{x}_i) = \sum_{y_i \in \mathcal{Y}} p(y=y_i \vert \mathbf{x}) \|\nabla \mathcal{L}^{(y_i)}(\theta)\| $$
BALD (Bayesian Active Learning by Disagreement; Houlsby et al. 2011) aims to identify samples to maximize the information gain about the model weights, that is equivalent to maximize the decrease in expected posterior entropy.
$$ \begin{aligned} I[\boldsymbol{\theta}, y \vert x,\mathcal{D}] &= H(\boldsymbol{\theta} \vert \mathcal{D}) - \mathbb{E}_{y \sim p(y \vert \boldsymbol{x}, \mathcal{D})} \big[ H(\boldsymbol{\theta} \vert y, \boldsymbol{x}, \mathcal{D}) \big] & \text{; Decrease in expected posterior entropy}\\ &= H(y \vert \boldsymbol{x}, \mathcal{D}) - \mathbb{E}_{\boldsymbol{\theta} \sim p(\boldsymbol{\theta} \vert \mathcal{D})} \big[ H(y \vert \boldsymbol{x}, \mathcal{\theta}) \big] \end{aligned} $$
The underlying interpretation is to “seek $\mathbf{x}$ for which the model is marginally most uncertain about $y$ (high $H(y \vert \mathbf{x}, \mathcal{D})$), but for which individual settings of the parameters are confident (low $H(y \vert \mathbf{x}, \boldsymbol{\theta})$).” In other words, each individual posterior draw is confident but a collection of draws carry diverse opinions.
BALD was originally proposed for an individual sample and Kirsch et al. (2019) extended it to work in batch mode.
Forgetting Events
To investigate whether neural networks have a tendency to forget previously learned information, Mariya Toneva et al. (2019) designed an experiment: They track the model prediction for each sample during the training process and count the transitions for each sample from being classified correctly to incorrectly or vice-versa. Then samples can be categorized accordingly,
- Forgettable (redundant) samples: If the class label changes across training epochs.
- Unforgettable samples: If the class label assignment is consistent across training epochs. Those samples are never forgotten once learned.
They found that there are a large number of unforgettable examples that are never forgotten once learnt. Examples with noisy labels or images with “uncommon” features (visually complicated to classify) are among the most forgotten examples. The experiments empirically validated that unforgettable examples can be safely removed without compromising model performance.
In the implementation, the forgetting event is only counted when a sample is included in the current training batch; that is, they compute forgetting across presentations of the same example in subsequent mini-batches. The number of forgetting events per sample is quite stable across different seeds and forgettable examples have a small tendency to be first-time learned later in the training. The forgetting events are also found to be transferable throughout the training period and between architectures.
Forgetting events can be used as a signal for active learning acquisition if we hypothesize a model changing predictions during training is an indicator of model uncertainty. However, ground truth is unknown for unlabeled samples. Bengar et al. (2021) proposed a new metric called label dispersion for such a purpose. Let’s see across the training time, $c^*$ is the most commonly predicted label for the input $\mathbf{x}$ and the label dispersion measures the fraction of training steps when the model does not assign $c^**$ to this sample:
$$ \text{Dispersion}(\mathbf{x}) = 1 - \frac{f_\mathbf{x}}{T} \text{ where } f_\mathbf{x} = \sum_{t=1}^T \mathbb{1}[\hat{y}_t = c^*], c^* = \arg\max_{c=1,\dots,C}\sum_{t=1}^T \mathbb{1}[\hat{y}_t = c] $$
In their implementation, dispersion is computed at every epoch. Label dispersion is low if the model consistently assigns the same label to the same sample but high if the prediction changes often. Label dispersion is correlated with network uncertainty, as shown in
Hybrid
When running active learning in batch mode, it is important to control diversity within a batch. Suggestive Annotation (SA; Yang et al. 2017) is a two-step hybrid strategy, aiming to select both high uncertainty & highly representative labeled samples. It uses uncertainty obtained from an ensemble of models trained on the labeled data and core-sets for choosing representative data samples.
- First, SA selects top $K$ images with high uncertainty scores to form a candidate pool $\mathcal{S}_c \subseteq \mathcal{S}_U$. The uncertainty is measured as disagreement between multiple models training with bootstrapping.
- The next step is to find a subset $\mathcal{S}_a \subseteq \mathcal{S}_c$ with highest representativeness. The cosine similarity between feature vectors of two inputs approximates how similar they are. The representativeness of $\mathcal{S}_a$ for $\mathcal{S}_U$ reflects how well $\mathcal{S}_a$ can represent all the samples in $\mathcal{S}_u$, defined as:
$$ F(\mathcal{S}_a, \mathcal{S}_u) = \sum_{\mathbf{x}_j \in \mathcal{S}_u} f(\mathcal{S}_a, \mathbf{x}_j) = \sum_{\mathbf{x}_j \in \mathcal{S}_u} \max_{\mathbf{x}_i \in \mathcal{S}_a} \text{sim}(\mathbf{x}_i, \mathbf{x}_j) $$
Formulating $\mathcal{S}_a \subseteq \mathcal{S}_c$ with $k$ data points that maximizes $F(\mathcal{S}_a, \mathcal{S}_u)$ is a generalized version of the maximum set cover problem. It is NP-hard and its best possible polynomial time approximation algorithm is a simple greedy method.
- Initially, $\mathcal{S}_a = \emptyset$ and $F(\mathcal{S}_a, \mathcal{S}_u) = 0$.
- Then, iteratively add $\mathbf{x}_i \in \mathcal{S}_c$ that maximizes $F(\mathcal{S}_a \cup I_i, \mathcal{S}_u)$ over $\mathcal{S}_a$, until $\mathcal{S}_s$ contains $k$ images.
Zhdanov (2019) runs a similar process as SA, but at step 2, it relies on $k$-means instead of core-set, where the size of the candidate pool is configured relative to the batch size. Given batch size $b$ and a constant $beta$ (between 10 and 50), it follows these steps:
- Train a classifier on the labeled data;
- Measure informativeness of every unlabeled example (e.g. using uncertainty metrics);
- Prefilter top $\beta b \geq b$ most informative examples;
- Cluster $\beta b$ examples into $B$ clusters;
- Select $b$ different examples closest to the cluster centers for this round of active learning.
Active learning can be further combined with semi-supervised learning to save the budget. CEAL (Cost-Effective Active Learning; Yang et al. 2017) runs two things in parallel:
- Select uncertain samples via active learning and get them labeled;
- Select samples with the most confident prediction and assign them pseudo labels. The confidence prediction is judged by whether the prediction entropy is below a threshold $\delta$. As the model is getting better in time, the threshold $\delta$ decays in time as well.
Citation
Cited as:
Weng, Lilian. (Feb 2022). Learning with not enough data part 2: active learning. Lil’Log. https://lilianweng.github.io/posts/2022-02-20-active-learning/.
Or
@article{weng2022active,
title = "Learning with not Enough Data Part 2: Active Learning",
author = "Weng, Lilian",
journal = "lilianweng.github.io",
year = "2022",
month = "Feb",
url = "https://lilianweng.github.io/posts/2022-02-20-active-learning/"
}
References
[1] Burr Settles. Active learning literature survey. University of Wisconsin, Madison, 52(55-66):11, 2010.
[3] Yang et al. “Cost-effective active learning for deep image classification” TCSVT 2016.
[4] Yarin Gal et al. “Dropout as a Bayesian Approximation: representing model uncertainty in deep learning.” ICML 2016.
[5] Blundell et al. “Weight uncertainty in neural networks (Bayes-by-Backprop)” ICML 2015.
[6] Settles et al. “Multiple-Instance Active Learning.” NIPS 2007.
[7] Houlsby et al. Bayesian Active Learning for Classification and Preference Learning." arXiv preprint arXiv:1112.5745 (2020).
[8] Kirsch et al. “BatchBALD: Efficient and Diverse Batch Acquisition for Deep Bayesian Active Learning.” NeurIPS 2019.
[9] Beluch et al. “The power of ensembles for active learning in image classification.” CVPR 2018.
[10] Sener & Savarese. “Active learning for convolutional neural networks: A core-set approach.” ICLR 2018.
[11] Donggeun Yoo & In So Kweon. “Learning Loss for Active Learning.” CVPR 2019.
[12] Margatina et al. “Active Learning by Acquiring Contrastive Examples.” EMNLP 2021.
[13] Sinha et al. “Variational Adversarial Active Learning” ICCV 2019
[14] Ebrahimiet al. “Minmax Active Learning” arXiv preprint arXiv:2012.10467 (2021).
[15] Mariya Toneva et al. “An empirical study of example forgetting during deep neural network learning.” ICLR 2019.
[16] Javad Zolfaghari Bengar et al. “When Deep Learners Change Their Mind: Learning Dynamics for Active Learning.” CAIP 2021.
[18] Fedor Zhdanov. “Diverse mini-batch Active Learning” arXiv preprint arXiv:1901.05954 (2019).