0. 前言
跟着师兄做知识图谱相关课题,果然知识图谱还是🉐和NLP结合,那就来把,先过一遍NLP。
1. 理解词语
-
词向量
把词映射到空间中,根据夹角、距离和长短等判断词的相似性。 -
Continuous Bag of Words (CBOW)
前后的词预测中间的词 -
Skip-Gram
中间的词预测前后的词 -
损失函数
损失函数通过正采样和负采样设定,tf.nn.nce_loss
抽样选取来传递loss
2. 理解句子
-
句向量
通过模型,得到的机器对于一句话的理解,对于这个理解,也就是向量,使用的方法不止一种。 -
Encoding
得到词向量之后,使用神经网络做复杂乘法运算得到句向量,也就是把多个词空间向量通过神经网络映射到另一个空间做句向量。
Encoding过程类似压缩的过程,将大量复杂的信息,压缩成少量经典的信息,通过这个途径找到信息的精华部分。 -
Decoding
Encoding得到的句向量就是机器对句子的理解,那么可以用另一个神经网络对句向量做各种各样的解码操作。
简而言之,Encoder负责理解上文,Decoder负责将思考怎么样在理解的句子的基础上做任务。 -
Seq2Seq
seq2seq属于encoder-decoder结构的一种,常见的encoder-decoder结构,基本思想就是利用两个RNN,一个RNN作为encoder,另一个RNN作为decoder。encoder负责将输入序列压缩成指定长度的向量,这个向量就可以看成是这个序列的语义,这个过程称为编码,而decoder则负责根据语义向量生成指定的序列,这个过程也称为解码。