RoPE

RoPE 相对于正余弦位置编码和可学习位置编码,更能够表达相对位置信息,便于模型捕捉序列中元素之间的关系,还便于模型泛化到更长的序列,支持超长文本推理。

Bilateral LSTM

有些时候预测可能需要由前面若干输入和后面若干输入共同决定,这样会更加准确。因此提出了双向循环神经网络,网络结构如下图。可以看到 Forward 层和 Backward 层共同连接着输出层,其中包含了 6 个共享权值 w1-w6。

CS224N Lecture 9: Pretraining

在过去的实践中,我们处理文本会先进行分词,然后把一个个 token 转换为其对应的 idx 索引,在用它去进行词嵌入。但这样的做法有一个问题,在测试集中我们遇到没见过的词语就把他用 <UNK> 来替换,这样会丢失大量的信息。

CS224N Lecture 8: Self-Attention and Transformers

从单条文本来看,矩阵 $x=Ew_t$ 形状为 [SeqLen, EmbeddingSize]。

1. 用权重矩阵 Q,K,V 转换词向量

qi=Qxiki=Kxivi=Vxi \begin{align} q_i &= Qx_i \\ k_i &= Kx_i \\ v_i &= Vx_i \end{align}

为了提高计算效率,可以把 Q,K,V 合并为一个大矩阵和 x 相乘,然后再把各个部分取出来,类似 BiLSTM 中四个门控计算合并到一个 [4*H, B] 的大矩阵,然后再通过 .chunk 分开。

CS224N Lecture 5: Recurrent Neural Networks

  1. LM可以通过一句话的前n个词,计算出下一个词是某个词的概率。
P(xt+1xt,...,x1) P(x^{t+1}|x^{t},...,x^1)
  1. LM可以计算出某句话出现的概率
P(x1,...,xt)=P(x1)P(x2x1)... P(x^1,...,x^{t})=P(x^1) \cdot P(x^2|x^1) \cdot ...

N-gram 指的是一堆连续的词,而 N 指的是这一堆词的个数。一个 N-gram 的 LM 就可以根据前 N-1 个词,预测出第 N 个词的概率。

CS224N Lecture 6: Sequence to Sequence Models

RNN 在进行反向传播,计算第 j 步的损失对前面的一步梯度的时候,需要运用链式法则:

Jjhi=Jjhjhjhi=Jjhjhjhj1hi+1hi=Jjhji<tjhtht1 \begin{aligned} \frac{\partial J^j}{\partial h^i} &= \frac{\partial J^j}{\partial h^j} \cdot \frac{\partial h^j}{\partial h^i} \\ &= \frac{\partial J^j}{\partial h^j} \cdot \frac{\partial h^j}{\partial h^{j-1}} \cdot \ldots \cdot \frac{\partial h^{i+1}}{\partial h^i} \\ &= \frac{\partial J^j}{\partial h^j} \cdot \prod_{i<t\le j} \frac{\partial h^t}{\partial h^{t-1}} \end{aligned}

根据 RNN 的公式$h_t=tanh(Wx \cdot x_t + W_h \cdot h_{t-1} + b_h)$,将激活函数忽略可以得到,$h_t$对$h_{t-1}$的偏导就是 W,所以我们可以近似得到:

CS224N Assignment 1

Write a method to work out the distinct words (word types) that occur in the corpus.

You can use for loops to process the input corpus (a list of list of strings), but try using Python list comprehensions (which are generally faster). In particular, this may be useful to flatten a list of lists. If you’re not familiar with Python list comprehensions in general, here’s more information.

CS224N Lecture 4: Dependency Parsing

传统的传统句法(如短语结构语法)认为句子是由短语组成的层级结构。以I saw a cat under the table为例子

  • table是名词
  • the table 组成名词短语
  • under 是介词
  • under the table 组成介词短语
  • a cat under the table 又组成一个名词短语…..

依存语法的出发点不同,它提出了一个非常重要的假设: