Skip to content

Commit

Permalink
refactor: added new paper
Browse files Browse the repository at this point in the history
  • Loading branch information
PommesPeter committed Sep 1, 2023
1 parent 40bdefb commit 72ba683
Show file tree
Hide file tree
Showing 87 changed files with 213 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
2. 学习神经网络分类器的概念
3. 能够顺场地看一些 word embedding 的论文,例如 Google word2vec 论文、GLoVe 论文等

## Review

上节课我们建立了如何构建 word vector 的模型,并且推导出如何求解和优化词向量模型,但这只是最简单的算法,这个算法能够比较好的学习单词之间的相似性和词义的方向,更好地预测周围的单词。

:::info Bag of Word Model
Expand All @@ -16,4 +18,96 @@ Bag of Word,也就是 NLP 当中的词袋模型。其实我们的词向量本

:::

word2vec 其实是将意思相近的单词在高维的向量空间当中彼此靠近,将相似的单词分组。
word2vec 其实是将意思相近的单词在高维的向量空间当中彼此靠近,将相似的单词分组。

![image-20221206111247762](src/02.Neural_Classifiers/image-20221206111247762.png)

通过 $U$ 和 $V$ 的点乘,经过 softmax 后得到相应单词的概率。而词袋模型是对每个位置的单词都做同样的 prediction 的操作,我们最终的目标是对于每个单词出现的预测的概率最大。

## Word2Vec Optimization

构建目标函数之后需要求解其最优概率,去找到目标函数的最值,所以使用**梯度下降**进行优化。

![image-20221206152922620](src/02.Neural_Classifiers/image-20221206152922620.png)

梯度下降的核心思想是使用梯度来更新自变量,比较因变量之间的差距,通过不断更新自变量从而找到使得其函数达到最值的自变量的点。所以优化方式如下:
for a matrix:
$$
\theta^{new}=\theta^{old}-\alpha\nabla_\theta J(\theta) \\
$$

for a single parameter:
$$
\theta_j^{new}=\theta_j^{old}-\alpha\frac{\partial}{\partial\theta_j^{old}}J(\theta)
$$

但使用上面的方式会产生巨大的计算量,使得求得最值需要耗费长久的时间,所以提出 Stochastic Gradient Descent (SGD) 来优化,使用一批数据优化梯度下降的效率。

但是直接对 word vectors 使用梯度下降会产生一个问题,上下文间隔比较大的 word vector 可能概率值是很小的,所以就导致所计算的梯度矩阵是稀疏的(Sparse),从数学的角度上是合理的,但是从系统应用角度上这是不符合要求。

产生如下的稀疏矩阵:
$$
\nabla_{\theta}J_t(\theta)=\begin{bmatrix}
0 \\
\vdots \\
\nabla_{v_{like}} \\
\vdots \\
0 \\
\nabla_{u_I} \\
\vdots \\
\nabla_{u_{learning}} \\
\vdots
\end{bmatrix}\in \mathbb{R}^{2dV}
$$


所以提出了如下解决方案:

- We hope: 只更新真正出现在 word vectors 里面的参数
- Solution:
1. 只更新整个 embedding matrices U 和 V 中的确实存在有单词的那几行
2. 给 word vectors 记录 Hash 值

## Other Word2vec Algorithm

> 为什么需要两个向量?→ 更容易优化。(但可以实现每个单词一个向量的算法)
对于 Word2vec 模型而言,还有一些变种的算法:

1. Skip-grams (SG)

根据 center word 预测 context words

2. Continuous Bag of Words

从 context words 预测 center words

提高训练效率的算法:

1. Negative Sampling (naive softmax methods)

### Skip-Gram Model with Negative Sampling

因为使用传统的 softmax 方法的计算量非常大,因为要遍历每一个单词。 所以提出了 Negative Sampling 来优化计算。Negative Sampling 的核心思想是:训练一个 true pair (center word and a word in its context window) 与多个 noise pairs (the center word paired with a random word) 的二元逻辑回归模型。

:::info

This method is from paper called “Distributed Representations of Words and Phrases and their Compositionality” (Mikolov et al. 2013)

:::

:::tip Main Idea



:::

最终的目标函数如下:
$$
J(\theta)=\frac{1}{T}\sum_{t=1}^TJ_t(\theta) \\
\sigma(x)=\frac{1}{1+e^{-x}} \\
J_t(\theta)=\log\sigma(u_o^Tv_c)+\sum_{i=1}^k\mathbb{E}_{j\sim P(w)}[\log\sigma(-u_j^Tv_c)]
$$
sigmoid function will become your good friends!

通过最大化两个向量同时成立的概率最大,而 noise words 的概率最小,从而达到最优解。
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
title: Attention is All You Need
tags:
- Attention
---

# Attention is All You Need

## Abstract

现在主流的序列翻译模型(序列到序列的生成模型)都是基于循环神经网络或者卷积神经网络来做的,也就是包含了 encoder 和 decoder。现阶段最好的模型也是通过注意力机制将 encoder 和 decoder 连接起来。所以我们提出了一种仅用注意力机制的简单结构,完全不使用 CNN 和 RNN。我们的架构在其他领域也非常适用。(使用机器翻译领域作为验证)

## Introduction

循环语言模型和 encoder-decoder 模型是当时使用频率较高的两种解决方案。输出结构化信息比较多的情况下会使用 encoder-decoder 架构来解决这类问题(比较通用)。提出了两种模型的问题:

1. 对于语言模型的解决方案通常会使用 RNN 进行学习,第 $t$ 个词的状态由前面的 第 $t-1$ 个词的状态得到。但这个过程是串行的,难以并行地进行运算,性能较差;并且对于早期的状态信息可能会在训练后期丢失(记忆)。
2. encoder-decoder 也是有类似的问题,结构化的信息较多的情况下彼此之间的具有强相关的关系,难以解耦,导致学习的过程比较粗糙,不利于收敛。

将上述的两种结构进行优化,不使用 RNN,而是用 attention 的方式替代,解决无法并行的问题

## Background

传统的 seq2seq 任务中,

## Conclusion

第一个仅用注意力机制实现序列转换模型,将 encoder-decoder 架构中的循环层替换成多头自注意力。对于翻译任务 Transformer 的训练速度也比循环层或卷积层快。收敛速度快。

我们的模型可以应用其他任务上,在任何基于 attention 的模型都是适用的。Transformer 可以应对不同的数据类型的输入都是适用的,例如图像、音频、视频。
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
title: Grounded Language-Image Pre-training
tags:
- VLMs
---

# Grounded Language-Image Pre-training

## Abstract

学习对象级、语言感知和语义丰富的视觉表示。GLIP 将目标检测和 phrase grounding 统一起来进行预训练。好处在于:

1. 它允许 GLIP 从检测和接地数据中学习以改进任务并引导良好的接地模型;
2. GLIP 可以通过自我训练的方式生成接地框来利用海量的图像-文本对,使学习的表示语义丰富。

学习的表征对各种对象级识别任务具有很强的零样本和少样本可迁移性,适合用于处理 zero-shot 和 few-shot 任务。实验结果也表明我们效果最好。

## Motivation

提高模型的 zero-shot 和 few-shot 能力,利用目前的 pre-trained 大模型来实现。

## Method how to use?

![Alt text](./src/01.Grounded_Language-Image_Pre-training/image.png)

目标检测任务中的对每个区域进行分类的任务转换成将每个区域对齐到文本 prompt 中的 c 个短语,将视觉检测定义为 grounding task。输入一些 image-text pair,将其融合后使得图像上的物体和文本描述中的 prompt 对应的单词对齐来完成分类的任务。(带检测模块的 CLIP)

1. 定义好新的范式以及如何利用 prompt 作为特征信息的一部分。

2. 设计好对应的 image encoder 和 text encoder。本文使用的 image encoder 为 DyHead (Dynamic Head: Unifying Object Detection Heads with Attentions),使用的 text encoder 为 BERT。

3. 除此之外还要设计一个 cross-modality multi-head attention module (X-MHA)。每个头部通过关注另一个模态来计算一个模态的上下文向量。

4. 最后再准备大量数据进行 pre-training 的训练。

5. 迁移到其他 benchmark 进行验证训练。

## Heuristic Thinking

`GLIP 统一了 phrase grounding 和目标检测任务,因为目标检测可以被视为上下文无关的 phrase grounding,而 phrase grounding 可以被视为上下文化的目标检测任务。`
是否能够利用 phrase grounding 增强其视觉的语义丰富度?(增强 context)

是否可以通过 prompt 提示出 visual feature (ROI feature, union feature, etc.) 中的关系呢,通过设计 prompt?

之前的工作中已经有用 glove 使用其 phrase feature 来提高 zero-shot 的能力。是否可以说明 nlp 当中的模型天生具备比较强的 zero-shot 学习能力呢?
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ tags:

## Model

![image-20221015154638586](src/05.RelTR-Relation-Transformer-for-Scene-Graph-Generation/image-20221015154638586.png)
![image-20221015154638586](src/04.RelTR-Relation-Transformer-for-Scene-Graph-Generation/image-20221015154638586.png)

整体结构如图所示,经过 CNN Backbone 提取 object 的 positional encoding 特征,经过 Feature Encoder 和 Entity Decoder 得到 entity 的特征表示。通过 Triplet Decoder 直接得出 triplet,不用预测 predicate。

Expand Down Expand Up @@ -108,7 +108,7 @@ Q_o=Att_{DEA}^{(obj)}(Q_o + E_t,Q_e, Q_e)
$$
$Att_{DEA}^{(sub)}$ 和 $Att_{DEA}^{(obj)}$ 是 subject 和 object 分支中的解耦的 DEA 模块。DEA 的输出由一个前馈网络处理,然后是一个具有残差连接的归一化层。前馈网络(FFN)由两个具有ReLU激活的线性变换层组成。

![image-20221017174810250](src/05.RelTR-Relation-Transformer-for-Scene-Graph-Generation/image-20221017174810250.png)
![image-20221017174810250](src/04.RelTR-Relation-Transformer-for-Scene-Graph-Generation/image-20221017174810250.png)

### Set Prediction Loss for Triplet Detection

Expand Down Expand Up @@ -140,7 +140,7 @@ c_{tri}=c_m(\hat y_{sub}, y_{sub})+c_m(\hat y_{obj}, y_{obj})+c_m(\hat y_{prd},
$$
给定 triplet 代价矩阵 $C_{t𝑟𝑖}$,执行匈牙利算法进行二部匹配,并将每个 GT triplets 分配给一个预测的结果。然而, `<background-no relation-background>` 这个关系被分配给所有与 GT triplet 不匹配的预测结果。经过多次训练,RelTR 可能以四种可能的方式输出 triplet proposal,如图 4 所示。将 Proposal A 分配给 GT 和 `<background-no relation-background>` 分配给 Proposal B 是两个明确的情况。对于 Proposal C,由于对象预测较差,不应将 `<background>`分配给受试者。此外,`<backround>` 不应该被分配给 Proposal D 的主题和对象,因为有一个更好的 Proposal A。

![image-20221018121358004](src/05.RelTR-Relation-Transformer-for-Scene-Graph-Generation/image-20221018121358004.png)
![image-20221018121358004](src/04.RelTR-Relation-Transformer-for-Scene-Graph-Generation/image-20221018121358004.png)

为了解决这个问题,我们集成一个基于 IoU 分配策略设置预测损失:对于预测出来的 triplet,如果预测 subject 或 object 标签是正确的,和预测的 box 和 GT box 大于或等于阈值 $𝑇$,损失函数不计算损失的 subject 或 object。triplet 检测的集合预测损失的公式为:
$$
Expand All @@ -157,7 +157,7 @@ $$

不同于将 $N$ 个 entity 组成 $N(N−1)$ 主体-对象对的 two-stage 方法不同,我们的方法同时检测 subject 和 object,同时预测固定数量的 triplets。这导致我们的方法忽略了主体和对象不能是同一个实体的约束。造成的结果是我们的模型有时输出一种 triplets,其中 subject 和 object 是同一个实体,带有一个歧义的谓词(例如见图 5)。在后处理中,如果 subject 和 object 是相同的实体(由标签和边界框的IoU决定),则该 triplets 将被删除。

![image-20221017185635894](src/05.RelTR-Relation-Transformer-for-Scene-Graph-Generation/image-20221017185635894.png)
![image-20221017185635894](src/04.RelTR-Relation-Transformer-for-Scene-Graph-Generation/image-20221017185635894.png)

## Experiments

Expand All @@ -183,31 +183,31 @@ triplet 解码器层数和 entity 解码器层数设置为相同。在我们的

- 网络层数

![image-20221018132229843](src/05.RelTR-Relation-Transformer-for-Scene-Graph-Generation/image-20221018132229843.png)
![image-20221018132229843](src/04.RelTR-Relation-Transformer-for-Scene-Graph-Generation/image-20221018132229843.png)

- 模块有效性

![image-20221018132239795](src/05.RelTR-Relation-Transformer-for-Scene-Graph-Generation/image-20221018132239795.png)
![image-20221018132239795](src/04.RelTR-Relation-Transformer-for-Scene-Graph-Generation/image-20221018132239795.png)

- 集合预测 loss 的阈值

![image-20221018133806838](src/05.RelTR-Relation-Transformer-for-Scene-Graph-Generation/image-20221018133806838.png)
![image-20221018133806838](src/04.RelTR-Relation-Transformer-for-Scene-Graph-Generation/image-20221018133806838.png)

### Analyisis on Subject and Object Queries

与在 NMS 之后输出N对象建议,然后标记 $N(N−1)$ 谓词的 two-stage 方法不同,RelTR 通过 $N_t$ 与图像交互的 subject 和 object queries 直接预测 $N_t$ 对 triplets。我们使用不同的 $N_t$ 在 VG 数据集上训练该模型。图 9 显示,随着耦合的 subject 和 object 查询的数量线性增加,模型的参数线性增加,而推理速度线性降低。然而,性能呈非线性变化,当 $N_t= 200$ 时,获得最佳性能。太多的查询会生成许多不正确的 triplet proposal 会取代 recall list 中的正确的 proposal。

![image-20221018133813846](src/05.RelTR-Relation-Transformer-for-Scene-Graph-Generation/image-20221018133813846.png)
![image-20221018133813846](src/04.RelTR-Relation-Transformer-for-Scene-Graph-Generation/image-20221018133813846.png)

为了探索 RelTR 如何通过 coupled subject 和 object queries 来推断 triplets,我们从 VG 测试集的 5000 张图像的随机样本中收集预测。我们对 200 个耦合查询中的 10 个的预测可视化。图 10 显示了 subject 和 object 的空间和类别分布,以及 10 个耦合的主题和对象查询的 5000 个预测中前 5 个谓词的类分布。它证明了不同的耦合查询从训练数据中学习不同的模式,并在推理时注意不同区域中不同类别的 triplets。

![image-20221018133944395](src/05.RelTR-Relation-Transformer-for-Scene-Graph-Generation/image-20221018133944395.png)
![image-20221018133944395](src/04.RelTR-Relation-Transformer-for-Scene-Graph-Generation/image-20221018133944395.png)

> 为什么拿出了三种颜色分成了这几个大类?
根据图 11 所示,has 有关的 queries 分布更加平滑。这表明,所有的查询都能够预测高频关系。对于 body 和 tail 中的谓词,有一些查询特别擅长检测它们。例如,21% 的带有谓词 `wears` 的 triplet 被 Query 115 预测,而有一半的带有 `mounted on` 的 triplet 被 Query 107 和 105 预测。

![image-20221018134421486](src/05.RelTR-Relation-Transformer-for-Scene-Graph-Generation/image-20221018134421486.png)
![image-20221018134421486](src/04.RelTR-Relation-Transformer-for-Scene-Graph-Generation/image-20221018134421486.png)

### Qulitative Results

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
title: State-aware Compositional Learning towards Unbiased Training for Scene Graph Generation
tags:
- PseudoLabels
- SceneGraphGeneration
---

# State-aware Compositional Learning towards Unbiased Training for Scene Graph Generation

## Motivation

1. 对于 SGG 会产生 biased prediction 的现象探究还不够
2. 发掘真正影响 SGG 的因素

## Introduction

模型不能过多地依赖 object identity feature,否则就会产生更大的 biased prediction。主要把 object class feature 分解成表示其类别和其状态( relation 的内在特征)

## Methods

解耦的目的是?能够预测出相似类别的物体,能够建模出更加具体的 relation。

## Conclusions

Visual Feature 对 SGG 模型的影响不大,去除 Visual Feature 后 SGG 模型的 performance 反而提升。 原因如下:
- visual feature 包含太多冗余信息
- object identity embedding 也不是影响 SGG model 的影响因素,对指标没有改变。
- object identity feature 是影响 SGG model 的 关键因素。
2 changes: 1 addition & 1 deletion docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const config = {
position: 'left'
},
{
to: '/docs/DeepLearning/PaperReading/Cascade-R-CNN-Delving-into-High-Quality-Object-Detection',
to: '/docs/DeepLearning/PaperReading/场景图生成/Resistance-Training-using-Prior-Bias-toward-Unbiase-Scene-Graph-Generation.md"',
activeBasePath: '/docs/PaperReading',
label: 'PaperLogs',
position: 'left'
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
"write-heading-ids": "docusaurus write-heading-ids"
},
"dependencies": {
"@docusaurus/core": "2.0.0-beta.15",
"@docusaurus/preset-classic": "2.0.0-beta.15",
"@docusaurus/theme-live-codeblock": "^2.0.0-beta.15",
"@docusaurus/theme-search-algolia": "^2.0.0-beta.15",
"@docusaurus/core": "2.4.1",
"@docusaurus/preset-classic": "2.4.1",
"@docusaurus/theme-live-codeblock": "^2.4.1",
"@docusaurus/theme-search-algolia": "^2.4.1",
"@fortawesome/fontawesome-svg-core": "^1.3.0",
"@fortawesome/free-brands-svg-icons": "^6.0.0",
"@fortawesome/free-regular-svg-icons": "^6.0.0",
Expand Down

0 comments on commit 72ba683

Please sign in to comment.