⾔語モデルとは
• ⾃然⾔語としての確からしさを計算
– P(I have a dream) > P(a have I dream)
– 従来の翻訳では出⼒⽂の選択に使⽤
– 同時確率を条件付き確率の積で計算
NTT
Encoder-Decoder
RNN Encoder-Decoder
P(I have a dream) > P(a have I dream) > P(fuga spam hoge
:
• RNN
•
P(I have a dream)
= P(I)P(have | I)P(a | I have)P(dream | I have a)
I have a dream
6
N-gramとニューラル⾔語モデル
• N-gram ⾔語モデル︓単語の⽣起は直前N-1単語に依存
– 算出法︓訓練データ中の出現頻度をカウント
• ⽋点1︓N が⼤きいと訓練データに出現しない
• ⽋点2︓単語間の類似性を考慮できない(I と You や He は似た振る舞いだが…)
• ニューラル⾔語モデル︓⽣起確率をニューラルネットで計算
– 算出法︓訓練データを再現するよう学習したモデルを⼊⼒に適⽤
• 無限-gramを⾃然に扱うことが可能
• 埋め込みにより単語間の類似性を考慮可能
7
•
– P(I have a dream) > P(a have I dream)
–
• perplexity
–
– →
–
3
Encoder-Decoder
RNN Encoder-Decoder
P(I have a dream) > P(a have I dream) > P(fuga spam hoge)
:
• RNN
•
P(I have a dream)
= P(I)P(have | I)P(a | I have)P(dream | I have a)
I have a dream
I have a dream
P(I) P(have | I) P(a | I have) P(dream | I have a)
RNN
gdream
= σ(Wge’dream+bg)
P(dream | I have a)
Softmax(s’dream)
sdream=(Whdream+b)
gdream
sdream
s’dream
Model
Penn
LSTM (
Variatio
Variatio
Variatio
Variatio
Variatio
Pointer
Neural
W
LSTM (
Variatio
Variatio
Variatio
Pointer
1-gram 2-gram 3-gram 4-gram
何らかのニューラルネット
I have a
P(I) P(have | I) P(a | I have) P(dream | I have a)
<BOS>
各条件(⼊⼒単語列)
に対し確率を計算
埋め込み表現︓
単語の実数ベクトルによる表現
• ニューラルネットには埋め込み表現を⼊⼒
– 埋め込み表現︓各単語に対応した実数ベクトル
– ベクトル空間上で各単語の特徴を共有
– 学習を通じて似た単語は似た埋め込みに
8
何らかのニューラルネット
I have a
P(I) P(have | I) P(a | I have) P(dream | I have a)
<BOS>
0.83 -1.56 0.37 … -0.42
I
単語を埋め込み表現に変換し,
ニューラルネットに⼊⼒
0.64 -1.46 0.03 … 0.28
似た単語=似た埋め込み
0.78 -1.22 0.15 … 1.25
You:
He:
データに基づく⼿法は
データ量が多いほど良い
• 統計的⼿法はデータが増えると質が向上
– データを⽣成している真の分布に近づく
– N-gram⾔語モデルの質はデータ量に対数⽐例 [Brants+ 07]
• ニューラルも訓練データが⼤きいほど性能向上
– 翻訳の訓練に使⽤する対訳⽂数を変えると……
11
Because 30 years
ago, I'm from New
Jersey, and I was six,
and I lived there in my
parents' house in a
town called Livingston,
and this was my
childhood bedroom.
30年前 私は
ジャージー出⾝で
6歳でした 両親の
家にはLiventとい
う町に住んでいま
した これは ⼦ど
もの寝室でした
30 年前 私は
ニュージャージー
出⾝で6歳でした
両親の住むリビン
グトンという町に
住んでいました こ
れは⼦供の頃の寝
室です
およそ30年前
スズズズズズズ
ズズで 私の頃
です
翻訳元の英⽂
1万 10万 20万
余談︓⾃動⽣成したデータも有⽤
• 機械翻訳したデータも機械翻訳の学習に有⽤
• ⼈⼯的にノイズを⼊れたデータも学習に有⽤
– ノイズ︓単語を消す,似た単語に置き換える,…
– どのようなノイズが効率的か︖ [Takase & Kiyono 21]
• 詳しくはNLPコロキウム︓https://youtu.be/jleVcNSKylw
13
Alice was beginning to
get very tired of sitting
by her sister on the
bank, and of having
nothing to do …
川べりで姉の隣に座っ
ていたアリスは、けれ
ども、何もすることが
ないので、とても退屈
になってきて……
機械翻訳
英 ← ⽇翻訳の
学習に利⽤
川べりで__の__座っ
ていた____は、けれ
ども、何も___ことが
ない____とても____
に____きて……
ノイズを⼊れる
(単語を消す)
英 ← ⽇翻訳の
学習に利⽤
⾔語モデルの訓練データは構築が容易
• ⾔語モデル︓⾃然⾔語としての確からしさを計算
– 同時確率を条件付き確率の積で計算
• ⾔語モデルの学習︓各⽂脈(単語列)の次に出現する単語を予測
• 任意の(⾃然⾔語の)⽂書=⾔語モデルの訓練データ
– Wikipediaの⽂書がそのまま(追加でタグ付けなどなしに)使える︕
15
Encoder-Decoder
RNN Encoder-Decoder
P(I have a dream) > P(a have I dream) > P(fuga spam hoge
:
• RNN
•
P(I have a dream)
= P(I)P(have | I)P(a | I have)P(dream | I have a)
I have a dream
何らかのニューラルネット
I have a
I have a dream
<BOS>
I have a
dream that
one day …
余談(2/3)︓近年の事前学習モデル
19
何らかのニューラルネット
I have a
I have a dream
<BOS>
何らかのニューラルネット
MASK MASK a
I have
<BOS>
マスクド⾔語モデル(BERT系)
⼊⼒の⼀部をマスクし,その単語を予測
⼊⼒系列 X について次を最⼤化
マスクする単語を
ランダムに選択
マスクされた
単語を予測
⾔語モデル(GPT系)
与えられた⽂脈に対し次の単語を予測
⼊⼒系列 X について次を最⼤化
k-1から1つ前までの
単語を⽂脈とする
⽂脈の次の
単語を予測
• 学習⽅法で⼤別
– 構造は主に Transformer [Vaswani+ 17]
余談(3/3)︓⼤規模データでの学習の凄み
• 訓練データや学習パラメータが増えると性能向上
• Zero-shot でも良い性能(の場合も)[Brown+ 20]
– Zero-shot: 応⽤タスクで学習せずに解く
20
翻訳での
通常の学習
ウンベルト・エー
コの新作,『バウ
ドリーノ』は農⺠
の⼦が……
Baudolino, a new
novel by Umberto
Eco, is the story of
a peasant boy ……
対訳⽂で学習
Where is my cat?
私の猫はどこですか︖
ウンベルト・エー
コの新作,『バウ
ドリーノ』は農⺠
の⼦が……
Baudolino, a new
novel by Umberto
Eco, is the story of
a peasant boy ……
⼤量の⽂書で
⾔語モデルを学習
English to Japanese:
Where is my cat?
私の猫はどこですか︖
⾔語モデル
による
Zero-shot
翻訳
蒸留(Distillation)
• 学習済みモデルの出⼒を⼩規模モデルで再現 [Hinton+ 14]
– ⾔語モデルの学習を例に
• 系列変換タスク⽤の⼿法は次スライドで
26
Baudolino, a new
novel by Umberto
Eco, is the story of
a peasant boy ……
元となるモデル
(教師モデル)
の学習
⼩さなモデル
(⽣徒モデル)
の学習
Baudolino, a new
novel by Umberto
Eco, is the story of
a peasant boy ……
Baudolino, a new
Baudolino, a new
novel
⽂脈を⼊⼒し,
次の単語を予測
Baudolino, a new
novel 教師モデルの
出⼒を再現する
ように学習
通常の学習
(次の単語
を予測)
系列変換タスクでの蒸留 [Kim+, 16]
• 教師モデルの⽣成した系列で⽣徒モデルを学習
– 経験的に性能が良く,実装も楽
27
1. 通常の訓練データで
教師モデルを学習
ウンベルト・エー
コの新作,『バウ
ドリーノ』は農⺠
の⼦が……
Baudolino, a new
novel by Umberto
Eco, is the story of
a peasant boy ……
『バウドリーノ』
(ウンベルト・
エーコの新作)は
農⺠の⼦が…
Baudolino, a new
novel by Umberto
Eco, is the story of
a peasant boy ……
2. 教師モデルで
訓練データを再⽣成
Baudolino, a new
novel by Umberto
Eco, is the story of
a peasant boy ……
『バウドリーノ』
(ウンベルト・
エーコの新作)は
農⺠の⼦が…
3. 教師モデルの
⽣成した訓練データで
⽣徒モデルを学習
ランダムベクトル mw の構築
• M 個のランダムベクトルを組み合わせる
• 組み合わせが完全に衝突することはほぼない
– 確率は 1 - exp(-V2 / 2(cM))
– 例えば翻訳(c = 64, M = 8, V = 37K)では 1.0 × 10-6 で衝突
34
ランダム⾏列
,… + …
+
各単語に対してランダムに列ベクトルを割り当て,組み合わせる
mw
Do
c M
ランダムベクトルの組み合わせで mw を構築
Do × c × M < De × V
余談︓共有によるパラメータ節約
• 翻訳などでは語彙数次元のベクトルを出⼒
– 語彙数に対する確率分布を出⼒
41
何らかの(M層)ニューラルネット
I have a
P(I) P(have | I) P(a | I have) P(dream | I have a)
<BOS>
0.83 -1.56 0.37 … -0.42
I
V
De
0.83
…
-0.42
埋め込み表現の⾏列から
単語に対応する埋め込みを抽出
出⼒⾏列(De × V )
×
出⼒⾏列で語彙数次元のベクトルに変換
⾏列の形は同じ
→ 同⼀の⾏列を使⽤可能
→ 共有するとパラメータの⼤幅な節約に
本研究の実験では共有している
(既存研究は共有していない︖)
Self-attention の軽量化
• Self-attention︓⼊⼒⻑の 2乗の計算量
• 計算対象を限定して計算量削減 [Child+ 19]
– Strided,Fixed の 2種を提案
• Self-attention の軽量な代替を探す
– CNN でも同等の性能が達成可能 [Tay+ 21]
– ⼊⼒間の相互作⽤があれば同等の性能が達成可能︖ [Liu+ 21]
52
x1x2x3x4x5
通常のアテンション
全単語間に対し計算
x
5
x
4
x
3
x
2
x
1
x1x2x3x4x5
x
5
x
4
x
3
x
2
x
1
Strided アテンション
直前の N 単語に対し計算
(図では N = 3)
x1x2x3x4x5
x
5
x
4
x
3
x
2
x
1
Fixed アテンション
N 区間の単語に対し計算
(図では N = 3)
学習を⾏わずにパラメータを削除
• ある指標で各パラメータの寄与率(スコア)を計算
– 訓練データで1度だけ計算し,勾配を元にスコア計算
[Lee+ 19, Wang+ 20]
– パラメータの値のみを元にスコア計算 [Tanaka+ 20]
55
preference is. In particular, both SNIP and GraSP aggressively prune
ith the most trainable parameters, evident by the sharp peaks in Fig. 2.
we hypothesize that gradient-based scores averaged within a layer are
layer size. We examine this hypothesis by constructing a theoretical
networks. We first define a general class of gradient-based scores, prove
scores, and then use this law to prove that our hypothesis of inverse
r size and average layer score holds exactly.
-based scores. Synaptic saliency is a class of score metrics that can be
product
S(✓) =
@R
@✓
✓, (1)
ion of the output y of a feed-forward network parameterized by ✓. When
esulting synaptic saliency metric is equivalent (modulo sign) to @L
@✓ ✓,
tonization [1], one of the first network pruning algorithms. The resulting
o @L
@✓ ✓ the score used in SNIP [13], H @L
@✓ ✓ the score used in
core used in the pruning after training algorithm Taylor-FO [28]. When
ynaptic saliency metric is closely related to diag(H)✓ ✓, the score used
]. This general class of score metrics, while not encompassing, exposes
sed scores used for pruning.
スコアの⼀般的な形式,
[Lee+ 19, Wang+ 20]は として
訓練データの損失を利⽤
what the root cause for this preference is. In particular, both SNIP and Gr
he largest layer, the layer with the most trainable parameters, evident by th
Based on this observation, we hypothesize that gradient-based scores aver
nversely proportional to the layer size. We examine this hypothesis by co
ramework grounded in flow networks. We first define a general class of grad
conservation law for these scores, and then use this law to prove that ou
proportionality between layer size and average layer score holds exactly.
A general class of gradient-based scores. Synaptic saliency is a class of s
xpressed as the Hadamard product
S(✓) =
@R
@✓
✓,
where R is a scalar loss function of the output y of a feed-forward network pa
R is the training loss L, the resulting synaptic saliency metric is equivalent (m
he score metric used in Skeletonization [1], one of the first network pruning a
metric is also closely related to @L
@✓ ✓ the score used in SNIP [13], H @
@
GraSP, and @L
@✓ ✓
2
the score used in the pruning after training algorithm
R = h@L
@y , yi, the resulting synaptic saliency metric is closely related to diag(
the essential ingredients for a pruning algorithm to avoid layer-collapse
l Critical Compression? We prove the following theorem in Appendix 9.
ive, conservative scoring achieves Maximal Critical Compression. If a
bal-masking, assigns positive scores that respect layer-wise conservation
al score for the parameters pruned at any iteration, is strictly less than
for an entire layer, whenever possible, then the algorithm satisfies the
ion axiom.
ow Pruning (SynFlow) algorithm. Theorem 3 directly motivates the
algorithm, SynFlow, that provably reaches Maximal Critical Compression.
ve score evaluation discourages algorithms that involve backpropagation
ead motivates the development of an efficient data-independent scoring
ity and conservation motivates the construction of a loss function that
ency scores. We combine these insights to introduce a new loss function
tor and |✓[l]
| is the element-wise absolute value of parameters in the lth
RSF = 1T
L
Y
l=1
|✓[l]
|
!
1 (2)
aptic saliency scores (@RSF
@✓ ✓) we term Synaptic Flow. For a simple,
. f(x) = W[N]
. . . W[1]
x), we can factor the Synaptic Flow score for a
[l]
"
|
N
Y
[k]
#
[l]
"l 1
Y
[k]
#
[Tanaka+ 20] でのスコア計算に⽤いる値
パラメータの値のみから求まる
(直観的にはパラメータの絶対値)
軽量なネットワーク早期発⾒の実験結果
• パラメータを削除しても性能維持が可能
– 経験的な上限値に到達できているのか︖
56
図は Pruning neural networks without any data by iteratively conserving synaptic flow より引⽤
We empirically benchmark the performance of our algorithm, SynFlow (red), against the baselines
random pruning and magnitude pruning, as well as the state-of-the-art algorithms SNIP [13] and
GraSP [14]. In Fig. 6, we test the five algorithms on 12 distinct combinations of modern architec-
tures (VGG-11, VGG-16, ResNet-18, WideResNet-18) and datasets (CIFAR-10, CIFAR-100, Tiny
ImageNet) over an exponential sweep of compression ratios (10↵
for ↵ = [0, 0.25, . . . , 3.75, 4]).
See Appendix 13 for more details and hyperparameters of the experiments. Consistently, SynFlow
outperforms the other algorithms in the high compression regime (101.5
< ⇢) and demonstrates more
stability, as indicated by its tight intervals. SynFlow is also quite competitive in the low compression
regime (⇢ < 101.5
). Although SNIP and GraSP can partially outperform SynFlow in this regime,
both methods suffer from layer-collapse as indicated by their sharp drops in accuracy.
Compression ratio
Top-1
accuracy
Compression ratio Compression ratio Compression ratio
Top-1
accuracy
Top-1
accuracy
SynFlow
SNIP GraSP
Magnitude
Random
VGG-11 VGG-16 ResNet-18 WideResNet-18
CIFAR-10
Tiny
ImageNet
CIFAR-100
Figure 6: SynFlow consistently outperforms other pruning methods in high compression
参考⽂献
• Takase+ 19: Positional Encoding to Control Output Sequence Length
• Takase & Kiyono 21: Rethinking Perturbations in Encoder-Decoders for Fast Training
• Takase & Kobayashi 20: All Word Embeddings from One Embedding
• Takase & Kiyono 21: Lessons on Parameter Sharing across Layers in Transformers
• Brants+ 07: Large Language Models in Machine Translation
• Peters+ 18: Deep contextualized word representations
• Mikolov+ 13: Distributed Representations of Words and Phrases and their Compositionality
• Devlin+ 19: BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding
• Vaswani+ 17: Attention Is All You Need
• Brown+ 20: Language Models are Few-Shot Learners
• Hinton+ 14: Distilling the Knowledge in a Neural Network
• Kim+ 17: Sequence-Level Knowledge Distillation
• Frankle+ 19: The Lottery Ticket Hypothesis: Finding Sparse, Trainable Neural Networks
• Child+ 19: Generating Long Sequences with Sparse Transformers
• Kitaev+ 20: Reformer: The Efficient Transformer
• Wang+ 20: Linformer: Self-Attention with Linear Complexity
• Mehta+ 20: DeFINE: DEep Factorized INput Token Embeddings for Neural Sequence Modeling
• Lan+ 20: ALBERT: A Lite BERT for Self-supervised Learning of Language Representations
• Dehghani+ 19: Universal Transformers
• Child+ 19: Generating Long Sequences with Sparse Transformers
• Tay+ 21: Are Pre-trained Convolutions Better than Pre-trained Transformers?
• Liu+ 21: Pay Attention to MLPs
• Tanaka+ 20: Pruning neural networks without any data by iteratively conserving synaptic flow
59