Bryce1010 / DeepLearning-Project

7 stars 5 forks source link

NLP 自然语言处理 #23

Closed Bryce1010 closed 3 years ago

Bryce1010 commented 4 years ago

http://speech.ee.ntu.edu.tw/~tlkagk/courses_DLHLP20.html

Bryce1010 commented 4 years ago

image

Bryce1010 commented 4 years ago

Introduction and Fine-Tune

What is pre-train model ?

Pretrain Model

image

image

Smaller model

How to fine-tune ?

NLP tasks
image 展开描述这么多组合

如何fine-tune模型呢?
有两种常见做法, 一种是fix feature extractor; 另一种是non-fix;
image image

但是这样fine-tune的模型往往会非常巨大, 那就变成富人玩的游戏, 穷人怎么分一杯羹?
image 我们固定住模型, 添加adaptor, 只要学习adaptor的参数.

Adaptor举例
image Adaptor结果 image

Pretrain 的魔力
image

How to pre-train?

Bryce1010 commented 4 years ago

根据输出的类型不同, 李宏毅老师将NLP任务分为两种:
第一种是sequence to class 第二种是 sequence to sequence
那怎么解决multi-sequence的问题?
第一种是采用multi-model 每一个model训练一个sequence, 然后合并起来;
第二种是, 将mutli-sequence合并成一个sequence, 中间采用特殊符号分隔;
image

Part-of-Speech (POS) Tagging

对句子中每个词的词性做tagging, 动词, 名词, 形容词
image

Word Segmentation

比如中文来说 ,需要对句子断句;

Coreference Resolution 指代消解

比如人名代称, he she it 等

Summarization

指摘要

Machine Translation

input: sequence
output: sequence

Grammar error correction

input: sequence output: sequence

Sentiment Classification

input: sequence
output: class

Stance Detection

立场检测 input: two sequence
output: class

Veracity Prediction

真实性评估

NLI (Natural Language Inference)

image

Question Answering

Natural Language Understanding (NLU)

GLUE

Bryce1010 commented 4 years ago

Transformer

[youtube]

self Attention

[paper]

image self attention 的每一个token或者输入都生成三个向量:Q, K, V.
Q的作用是匹配其他的输入,K的作用是被Q匹配,吃入两个向量得到一个attention;V是用来与attention做矩阵相乘后提取的特征。

image 然后拿每一个query q都跟key k做attention; 其中d表示q和k的维度大小,表示一个小的正则化。

image 然后通过softmax生成attention map

image 得到了attention map后,乘上V然后累加起来,就能得到输出
这是一种position independent的考虑方式,不同于RNN 与时间序列相关是一种position relative。

image 算出第二个输出 b1, b2, b3, b4是并行输出的,所以可以用matrix来计算,而且matrix在GPU中很容易加速。
所以接下来看一下self attentition的矩阵形式
image image image image 最终形式如下:
image

multi-head self-attention

image multi-head就是每一个输入对应了多个Q, K, V向量;然后每一个head都是相互独立计算的,计算过程跟上面介绍的一致。

Positional Encoding

在self-attention中没有位置信息,论文中的做法是:
对每一个输入xi,可以加上一个位置向量,这个位置向量可以是one-hot向量。
image

seq2seq with attention

image

transformer

image