一个神经机器翻译作业:CS 224n- Assignment #4- NMT with RNNs

NLP小学生

大家都知道斯坦福大学有很多高质量公开课,其中一个比较有名的是 CS224n: Natural Language Processing with Deep Learning ,做NLP的小伙伴基本都听说过。这门课不仅课件好,作业也很好,认真做一遍会有很大收获。

本文带大家做一遍这门课的第4个作业——实现一个NMT系统。这个作业可以说是几乎综合了这门课之前的知识点,包括:

  • Attention机制
  • 深度学习和pytorch

NMT除了综合之前所学,还为之后的学习打下了基础。掌握NMT后,再看问答、Transformer、BERT、语言生成等就会得心应手。因此,这个作业是一个承上启下的项目,很有价值。

本文分3部分,先是对模型进行一个公式化的描述和解析相应实现,然后解析模型训练的代码,最后解析预测相关的代码。项目代码见 cs224n_assignment4_solutions 。

本节描述的是训练阶段的模型,训练跟预测时模型的表现略有不同,不同之处在于,训练的时候解码器每次解码用的都是真实译句的词,同时还要计算预测下一个词时的损失;二预测的时候解码器每次解码用的是解码器生成的词,不需要计算损失。

1.1 生成一个序列的词向量

深度学习模型中流淌的是数字组成的张量。对于一个句子,要先把词映射成一个唯一的id,再将id变成词向量。

也就是输入一个句子,输出 \mathbf{x}_{1}, \ldots, \mathbf{x}_{m}\left(\mathbf{x}_{i} \in \mathbb{R}^{e \times 1}\right) 。

先将一个batch的句子做成id张量:

再将id张量转成embedding张量:

1.2 双向LSTM的Encoder

输入一个序列的词向量,生成一个序列的隐状态,以及Decoder的初始隐状态和初始内置状态。

\begin{array}{l} i_{t}=\sigma\left(W_{i i} x_{t}+b_{i i}+W_{h i} h_{t-1}+b_{h i}\right) \\ f_{t}=\sigma\left(W_{i f} x_{t}+b_{i f}+W_{h f} h_{t-1}+b_{h f}\right) \\ g_{t}=\tanh \left(W_{i g} x_{t}+b_{i g}+W_{h g} h_{t-1}+b_{h g}\right) \\ o_{t}=\sigma\left(W_{i o} x_{t}+b_{i o}+W_{h o} h_{t-1}+b_{h o}\right) \\ c_{t}=f_{t} \odot c_{t-1}+i_{t} \odot g_{t} \ h_{t}=o_{t} \odot \tanh \left(c_{t}\right) \end{array}

隐状态和内置状态计算方式:

\begin{aligned} &\mathbf{h}_{i}^{\mathrm{enc}}=[\overleftarrow{\mathbf{h}_{i}^{\mathrm{enc}}} ; \overrightarrow{\mathbf{h}_{i}^{\mathrm{enc}}}] \text { where } \mathbf{h}_{i}^{\mathrm{enc}} \in \mathbb{R}^{2 h \times 1}, \overleftarrow{\mathbf{h}_{i}^{\mathrm{enc}}}, \overrightarrow{\mathbf{h}_{i}^{\mathrm{enc}}} \in \mathbb{R}^{h \times 1} \quad 1 \leq i \leq m\\ &\mathbf{c}_{i}^{\mathrm{enc}}=[\overleftarrow{\mathbf{c}_{i}^{\mathrm{enc}}} ; \overrightarrow{\mathbf{c}_{i}^{\mathrm{enc}}}] \text { where } \mathbf{c}_{i}^{\mathrm{enc}} \in \mathbb{R}^{2 h \times 1}, \overleftarrow{\mathbf{c}_{i}^{\mathrm{enc}}}, \overrightarrow{\mathbf{c}_{i}^{\mathrm{enc}}} \in \mathbb{R}^{h \times 1} \quad 1 \leq i \leq m \end{aligned}

enc_hiddens 就是一个序列的 \mathbf{h}_{i}^{\mathrm{enc}} ,shape是 (src_len, b, h*2) 。

last_hidden 的shape是 (2,b,h) , last_hidden[0] 是 \overrightarrow{\mathbf{h}_{m}^{\mathrm{enc}}} , last_hidden[1] 是 \overleftarrow{\mathbf{h}_{1}^{\mathrm{enc}}} 。也可能反过来,总之一个是正向LSTM的最后一个隐状态,一个是反向LSTM的最后一个隐状态。

last_cell 的shape是 (2,b,h) ,类似 last_hidden 。

decoder的初始隐状态和内置状态的计算方式:

\begin{aligned} &\mathbf{h}_{0}^{\mathrm{dec}}=\mathbf{W}{h}[\overleftarrow{\mathbf{h}_{1}^{\mathrm{enc}}} ; \overrightarrow{\mathbf{h}_{m}^{\mathrm{enc}}}] \text { where } \mathbf{h}_{0}^{\mathrm{dec}} \in \mathbb{R}^{h \times 1}, \mathbf{W}{h} \in \mathbb{R}^{h \times 2 h}\\ &\mathbf{c}_{0}^{\mathrm{dec}}=\mathbf{W}{c}[\overleftarrow{\mathbf{c}_{1}^{\mathrm{enc}}} ; \overrightarrow{\mathbf{c}_{m}^{\mathrm{enc}}}] \text { where } \mathbf{c}_{0}^{\mathrm{dec}} \in \mathbb{R}^{h \times 1}, \mathbf{W}{c} \in \mathbb{R}^{h \times 2 h} \end{aligned}

解码是按时刻依次进行的,所以Encoder用的是 torch.LSTM ,而Decoder只能用 LSTMCell 。对于时刻 t ,进行一次下面的操作:

\mathbf{h}_{t}^{\mathrm{dec}}, \mathbf{c}_{t}^{\mathrm{dec}}=\operatorname{Decoder}\left(\overline{\mathbf{y}_{t}}, \mathbf{h}_{t-1}^{\mathrm{dec}}, \mathbf{c}_{t-1}^{\mathrm{dec}}\right) \quad \text { where } \mathbf{h}_{t}^{\mathrm{dec}} \in \mathbb{R}^{h \times 1}, \mathbf{c}_{t}^{\mathrm{dec}} \in \mathbb{R}^{h \times 1}

其中 \overline{\mathbf{y}_{t}} = [\mathbf{y}_t;\mathbf{o}_{t-1}] 。 \mathbf{y}_t \in \mathbb{R}^{e\times 1} 是译文的词向量, \mathbf{o}_{t-1} \in \mathbb{R}^{h \times 1} 是前一时刻的combined-output vector,combined-output vector是用于映射词表概率分布的向量表示,稍后解释。

得到 \mathbf{h}_{t}^{\mathrm{dec}} 后, 把它当做query,keys和values是 enc_hiddens , 计算attention向量:

\begin{array}{c} \mathbf{e}_{t, i}=\left(\mathbf{h}_{t}^{\mathrm{dec}}\right)^{T} \mathbf{W}_{\mathrm{att} \mathrm{Proj}} \mathbf{h}_{i}^{\mathrm{enc}} \text { where } \mathbf{e}_{t} \in \mathbb{R}^{m \times 1}, \mathbf{W}_{\mathrm{attProj}} \in \mathbb{R}^{h \times 2 h} \\ \alpha_{t}=\operatorname{softmax}\left(\mathbf{e}_{t}\right) \text { where } \alpha_{t} \in \mathbb{R}^{m \times 1} \\ \mathbf{a}_{t}=\sum_{i=1}^{m} \alpha_{t, i} \mathbf{h}_{i}^{\mathrm{enc}} \text { where } \mathbf{a}_{t} \in \mathbb{R}^{2 h \times 1} \end{array}

然后计算combined-output vector:

\begin{aligned} \mathbf{u}_{t}=&\left[\mathbf{a}_{t} ; \mathbf{h}_{t}^{\mathrm{dec}}\right] \text { where } \mathbf{u}_{t} \in \mathbb{R}^{3 h \times 1} \\ \mathbf{v}_{t}&=\mathbf{W}_{u} \mathbf{u}_{t} \text { where } \mathbf{v}_{t} \in \mathbb{R}^{h \times 1}, \mathbf{W}_{u} \in \mathbb{R}^{h \times 3 h} \\ \mathbf{o}_{t}&=\operatorname{dropout}\left(\tanh \left(\mathbf{v}_{t}\right)\right) \text { where } \mathbf{o}_{t} \in \mathbb{R}^{h \times 1} \end{aligned}

对每个时刻计算一次combined-output vector,需要对Y循环:

每个时刻的combined-output vector都可以计算一次概率分布,其意义是下个时刻词的概率分布, 然后跟下个时刻的target word的独热向量做交叉熵,就得到的损失。

\mathbf{P}_{t}=\operatorname{softmax}\left(\mathbf{W}_{\text {vocab }} \mathbf{o}_{t}\right) \text { where } \mathbf{P}_{t} \in \mathbb{R}^{V_{t} \times 1}, \mathbf{W}_{\text {vocab }} \in \mathbb{R}^{V_{t} \times h}

其中 V_t 是目标语言的词表大小。

J_{t}(\theta)=\text { CrossEntropy}\left(\mathbf{P}_{t}, \mathbf{g}_{t}\right)

g_t 是 t 时刻的目标词的独热向量, t 时刻的目标词就是下一个词,即第 t+1 个词。交叉熵需要求和,涉及独热向量的交叉熵实际上计算完之后只剩一项,就是目标词的负对数概率。

生成一个batch的数据:

本节所有代码都在 nmt_model.beam_search 函数下。

预测方法是 光束搜索 。

  • 解码需要 \mathbf{y}_t, \mathbf{o}_{t-1},\mathbf{h}^{\mathrm{dec}}_{t-1},\mathbf{c}^{\mathrm{dec}}_{t-1} ,以及encoder的输出 \mathbf{h}^{\mathrm{enc}}
  • 生成1时刻的 \mathbf{y}_1 = <s>, 生成0时刻的 \mathbf{o}_0 , 生成0时刻的 \mathbf{h}^{\mathrm{dec}}_{0},\mathbf{c}^{\mathrm{dec}}_{0} 。
  • 生成 \mathrm{vocab\_size} 个路径
  • 选择5个最高概率的路径,如果有达到 </s> 或解码次数达到阈值的路径,停止该路径的扩展。
  • 对于每个可以扩展的路径,再拓展一个词表的概率分布,得到 5 \times \mathrm{vocab\_size} 个路径。

生成 \mathbf{h}^{\mathrm{enc}}, \mathbf{o}_0,\mathbf{y}_1, \mathbf{h}^{\mathrm{dec}}_{t-1},\mathbf{c}^{\mathrm{dec}}_{t-1} 的代码如下:

向前扩展一步之decoder.step:

向前扩展一步之计算概率分布:

选择新的最高对数概率和的路径:

更新相关变量,为下一次 decode.step() 做准备:

附录:用到的torch类和函数

这个项目用到了很多常用的类和函数,不完全统计如下:

  • Embedding Layer。 https:// pytorch.org/docs/stable /nn.html#torch.nn.Embedding
  • LSTM。 https:// pytorch.org/docs/stable /nn.html#torch.nn.LSTM
  • LSTM Cell。 https:// pytorch.org/docs/stable /nn.html#torch.nn.LSTMCell
  • Linear Layer。 https:// pytorch.org/docs/stable /nn.html#torch.nn.Linear
  • Dropout Layer。 https:// pytorch.org/docs/stable /nn.html#torch.nn.Dropout
  • pack_padded_sequence。 https:// pytorch.org/docs/stable /nn.html#torch.nn.utils.rnn.pack_padded_sequence
  • pad_packed_sequence。 https:// pytorch.org/docs/stable /nn.html#torch.nn.utils.rnn.pad_packed_sequence
  • Permute。 https:// pytorch.org/docs/stable /tensors.html#torch.Tensor.permute
  • Concatenation。 https:// pytorch.org/docs/stable /torch.html#torch.cat
  • Zeros Tensor。 https:// pytorch.org/docs/stable /torch.html#torch.zeros
  • Tensor Splitting (iteration)。 https:// pytorch.org/docs/stable /torch.html#torch.split
  • Tensor Dimension Squeezing。 https:// pytorch.org/docs/stable /torch.html#torch.squeeze
  • Tensor Concatenation。 https:// pytorch.org/docs/stable /torch.html#torch.cat
  • Tensor Stacking。 https:// pytorch.org/docs/stable /torch.html#torch.stack
  • Batch Multiplication。 https:// pytorch.org/docs/stable /torch.html#torch.bmm
  • Tensor Unsqueeze。 https:// pytorch.org/docs/stable /torch.html#torch.unsqueeze
  • Tensor Squeeze。 https:// pytorch.org/docs/stable /torch.html#torch.squeeze
  • Softmax。 https:// pytorch.org/docs/stable /nn.html#torch.nn.functional.softmax
  • Tensor View。 https:// pytorch.org/docs/stable /tensors.html#torch.Tensor.view
  • Tanh。 https:// pytorch.org/docs/stable /torch.html#torch.tan

NLP & Friends

NLP & Friends

Stanford University

Stanford engineering, s tanford e ngineering e verywhere, cs224n - natural language processing, course is inactive, stanford center for professional development.

  • Stanford Home
  • Maps & Directions
  • Search Stanford
  • Emergency Info
  • Terms of Use
  • Non-Discrimination
  • Accessibility

© Stanford University, Stanford, California 94305

Assignment #2: TensorFlow, Neural Dependency Parsing, and RNN Language Modeling

Due Date: 2/9 (Thu) 11:59 PM PST. Hard deadline: 2/12 (Sun) 11:59 PM PST with 3 late days. Assignments turned in past this date will be penalized (see the grading page ).

In this assignment you will learn the fundamentals of TensorFlow, use TensorFlow to implemented a feed-forward neural network for transition-based dependency parsing, and delve into backpropagation through time by computing the gradients for a recurrent neural network language model.

Note: Please be sure you have Python 2.7.x installed on your system. The following instructions should work on Mac or Linux. If you have any trouble getting set up, please come to office hours and the TAs will be happy to help.

Get the code : Download the starter code here and the assignment handout here .

Python package requirements: The core requirements for this assignment are

If you have a recent linux (Ubuntu 14.04 and later) install or Mac OS X, the default TensorFlow installation directions will work well for you. If not, we recommed that you work on the corn clusters . TensorFlow is already installed for the system default python on corn.

Submitting your work

Do not code outside of the "# YOUR CODE HERE" blocks, modify the list of imports, change function names, etc. (tuning parameters is fine). Make sure your code runs before submitting. Crashing due to undefined variables, missing imports, hard-coded dimensions, and bad indentation will lead to significant deductions.

For the written component, please upload a PDF file of your solutions to Gradescope. When asked to map question parts to your PDF, please map the parts accordingly as courtesy to your TAs. This is crucial so that we can provide accurate feedback. If a question has no written component (completely programming), map it on the same page as the previous section or next section.

See Piazza for instructions for submitting your code.

This assignment requires you to submit a number of files, which are listed in the assignment handout under "deliverables" for each section. Please be sure to use the provided code snippets in the notebook to generate these files, and follow the instructions below to submit a .zip file and your writeup PDF.

Submission Logistics

  • Copy Part 1.1 code to part11probing.py
  • Run the sanity checker collectSubmission.py
  • Upload <your-sunet-id>.zip to Box
  • Upload your writeup PDF to Scoryst

Step 1: In order to evaluate Part 1.1 (Probing Neuron Responses), we ask that you copy-and-paste your code - minus the print statements - for 1.1(a), 1.1(b), and 1.1(c) from the part1-NER.ipynb notebook into the respective functions part_a() , part_b() , and part_c() in the template file part11probing.py which you can download here. Put this file in your assignment directory.

Step 2: We've written a sanity checker script that will run a few very basic tests to make sure your output and code are in the correct format. Please note that this script does not verify correctness or guarantee that all output is in the correct format. It only checks for a few cases of malformatted output and does not run gradient checks ! The script will also check for all the files you need to submit, and will prepare a .zip file for submission. This script should work on all platforms (Mac, Linux, Windows).

Download collectSubmission.py here , and put it in your assignment directory. Then run as: python collectSubmission.py

The script will warn you if files are missing or tests fail; you may opt to continue and it will still prepare the .zip, but you do so at your own risk.

Step 3: Upload <your-sunet-id>.zip , as output by the sanity checker, to the Box folder for this assignment

Extra Credit: If you implemented the ExtraCreditRNNLM extensions, please upload a separate zip file containing any additional parameter files (i.e. extracredit.U.npy , etc.) necessary to test your model. Name this file <your-sunet-id>-extracredit.zip , and upload it to the same Box folder as the rest of the assignment.

  • Part 0 (XOR) is "Question 1"
  • Part 1 (NER) is "Question 2"
  • Part 2 (RNNLM) is "Question 3"
  • For questions (such as 1(d) a.k.a. "Question 2 part 4") with both programming and written components, point Scoryst to the corresponding part of your writeup. We'll grade your code and include it in these parts.
  • For programming-only questions (such as 0(c) a.k.a "Question 1 part 3"), just point Scoryst to a dummy location; we'll enter the code grade as in Assignment 1.
  • Part 2 (RNNLM): "Question 3", parts 8 and 9 are for Extra Credit: unigram filling and RNNLM optimizations/extensions, respectively. If you did these, please point these questions to the relevant section of the report.

Assignment Overview (Tasks)

There will be three parts to this assignment. Coding the neural dependency parsing (Q2 part (h)) is designed to be completed in after Part 1. The rest of the assignment can be done independently. We recommend reading the assignment carefully and starting early as some parts may take significant time.

Q1: Tensorflow Softmax (25 points, coding)

Q2: neural transition-based dependency parsing (50 points, mostly coding with a bit of theory), q3: recurrent neural networks: language modeling (25 points, theory).

We also have made a video going over the assignment [ link ] (not required viewing, everything is in the handout or code documentation).

Assignment 5

Handout: CS 224N: Assignment 5: Self-Attention, Transformers, and Pretraining

1. Attention Exploration

(a). copying in attention.

\(\alpha\) is calculating the softmax of \(k_i^T q\) which makes it like a categorical probability distribution.

To make \(\alpha_j \gg \sum_{i \neq j} \alpha_i\) for some \(j\) . \(k_j^T q \gg k_i^T q, \forall i\neq j\) is required.

under conditions give in ii. \(c\approx v_j\)

Intuitively, the larger \(\alpha_i\) is, the higher attention is given on \(v_i\) in the output \(c\) .

(b). An average of two

Let $$ M=\left[\begin{array}{c} a_{1}^{\top} \\ \vdots \\ a_{m}^{\top} \end{array}\right] $$ then, \(Ms = M(v_a+v_b)=v_a\)

(c). Drawbacks of single-headed attention

Since the variance is small, we can treat \(k_i\) as concentrating around \(\mu_i\) , so $$ q=\beta(\mu_a+\mu_b), \beta\gg 0 $$

As the figures shows, \(k_a\) might ahve larger or smaller magnitude comparing with \(\mu_a\) . To make an estimation, we can assume \(k_a\approx \gamma \mu_a, \gamma \sim N(1, \frac{1}{2})\) , so $$ c \approx \frac{\exp (\gamma \beta)}{\exp (\gamma \beta)+\exp (\beta)} v_{a}+\frac{\exp (\beta)}{\exp (\gamma \beta)+\exp (\beta)} v_{b} =\frac{1}{\exp ((1-\gamma) \beta)+1} v_{a}+\frac{1}{\exp ((\gamma-1) \beta)+1} v_{b} $$ i.e. \(c\) will oscillates between \(v_a\) and \(v_b\) as sampling \({k_1, k_2, ..., k_n}\) multiple times.

(d). Benefits of multi-headed attention

  • \(q_1=q_2=\beta(\mu_a+\mu_b), \beta \gg 0\)
  • \(q_1 = \mu_a, q_2 = \mu_b\) , or vice versa.

Under two circumstances in i. 1. Averaging between different samples makes \(k_a\) closer to its expectation \(\mu_a\) , the result is that \(c\) is closer to \(\frac{1}{2}(v_a+v_b)\) . 2. \(c\) is always approximately \(\frac{1}{2}(v_a+v_b)\) , exactly when \(\alpha=0\) .

2. Pretrained Transformer models and knowledge access

Implementation: Assignment 5 Code

(g). sythesize variant

The single sythesizer can't capture the inter-dimension relative importance.

Search code, repositories, users, issues, pull requests...

Provide feedback.

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly.

To see all available qualifiers, see our documentation .

  • Notifications

Complete solutions for Stanford CS224n, winter, 2019

ZacBi/CS224n-2019-solutions

Folders and files, repository files navigation.

996.icu

CS224n-winter19

Solutions for CS224n, winter, 2019. Welcome to discuss problems appearing in assigments, please submit to issue. Also take notes for the key point in lectures. The solutions for assignment is written by Markdown in Assignments/written part .  

  • Course page: https://web.stanford.edu/class/cs224n
  • Video page: https://www.youtube.com/watch?v=8rXD5-xhemo&list=PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z

update 2019/12/03

  After CS224n I realize that more systematical training is needed. So I start a new repo learn_NLP_again , here is the description(algorithms and solutions is available for chapter 1 until now):

  Here is why I started this project: learn NLP from scratch again . I choose Speech and language process as my entry point, and try to write solutions and implement some algorithms/models of this book. I hope I can stick to this project and update frequently.

  After one year's training in corporation and lab, I find many faults or incorrect habbits in past parctice, (btw, there is too many commits in this repo). I'll review the code in this repo and solve issues gradually.(:smile:, hopefully)

Welcome communications in new repo!

  • note: Word Vectors I: Introduction, SVD and Word2Ve
  • Word2Vec Tutorial - The Skip-Gram Model  
  • coding: Assignment1
  • note: Word Vectors II: GloVe, Evaluation and Trainin
  • gradient-notes
  • CS231n notes on backprop
  • review-differential-calculus
  • backprop_old
  • CS231n notes on network architectures
  • coding: Assignment2
  • writing: Assignment2
  • note: Dependency Parsing
  • note: Language Models and Recurrent Neural Network
  • coding: Assignment3
  • writing: Assignment3
  • note: Machine Translation, Sequence-to-sequence and Attention
  • read: Attention and Augmented Recurrent Neural Networks
  • read: Massive Exploration of Neural Machine Translation Architectures (practical advice for hyperparameter choices)
  • coding: Assignment4
  • writing: Assignment4

key point for a4

How to understand pack_padded_sequence and pad_packed_sequence? (Chinese ed) (English ed)

It has been long time for no updating...

  • coding: Assignment5
  • writing: Assignment5

Final project

  • final-project-practical-tips
  • default-final-project-handout
  • project-proposal-instructions
  • Practical Methodology_Deep Learning book chapter
  • Highway Networks
  • Bidirectional Attention Flow for Machine Comprehension
  • anotate codes
  • train baseline
  • Python 68.0%
  • Jupyter Notebook 29.3%
  • JavaScript 1.1%

IMAGES

  1. cs224n-transformer学习笔记

    cs224n assignment 4 solution

  2. Cs224n midterm 2018 solution

    cs224n assignment 4 solution

  3. CENG534 CS224N assignment

    cs224n assignment 4 solution

  4. Assignment 4

    cs224n assignment 4 solution

  5. Assignment 4

    cs224n assignment 4 solution

  6. 【Stanford CS224N: NLP with Deep Learning】#1 Introduction & word2vector

    cs224n assignment 4 solution

VIDEO

  1. Hướng dẫn trọn bộ: CS224n

  2. [CS224N] Lec02 Neural Classifiers

  3. Manufacturing Process Technology I & II

  4. CS411 Assignment 2 100% Correct Solution 2024 BY VUBWN

  5. SOFT SKILLS NPTEL ASSIGNMENT 4 SOLUTION DEC 2023

  6. CS504 Assignment 2 Solution Fall 2023

COMMENTS

  1. amanchadha/stanford-cs224n-assignments-2021

    These are my solutions to the assignments of CS224n (Natural Language Processing with Deep Learning) offered by Stanford University in Winter 2021. There are five assignments in total. ... Assignment 4: Neural machine translation with seq2seq and attention a4/a4.pdf; Assignment 5: Neural machine translation with sub-word modeling a5/a5.pdf;

  2. Assignment 4

    Assignment 4. Handout: CS 224n: Assignment #4. 1. Neural Machine Translation with RNNs. Implementation: Assignment 4 Code. In the first task, a sequence-to-sequence (Seq2Seq) network with attention is built as a Neural Translation (NMT) system for Cherokee to English translation. Training Curves:

  3. PDF CS 224n: Assignment #4

    CS 224n Assignment 4 Page 4 of 8 (d) (8 points) (coding) Implement the encode function in nmt_model.py. This function converts the padded source sentences into the tensor X, generates henc 1,...,hencm, and computes the initial state hdec 0 and initial cell cdec 0 for the Decoder. You can run a non-comprehensive sanity check by execut-

  4. PDF CS 224n: Assignment #4

    CS 224n Assignment 4 Page 4 of 7 (e)(8 points) (coding) Implement the decode function in nmt model.py. This function constructs y and runs the step function over every timestep for the input. You can run a non-comprehensive sanity check by executing: python sanity_check.py 1e (f)(10 points) (coding) Implement the step function in nmt model.py.

  5. CS224N: Natural Language Processing with Deep Learning

    Assignment 4 (14%): Self-supervised learning and fine-tuning with Transformers; Deadlines: All assignments are due on either a Tuesday or a Thursday before class (i.e. before 4:30pm). ... Students are required to independently submit their solutions for CS224N homework assignments. Collaboration with generative AI tools such as Co-Pilot and ...

  6. 一个神经机器翻译作业:CS 224n- Assignment #4- NMT with RNNs

    一个神经机器翻译作业:CS 224n- Assignment #4- NMT with RNNs. NLP小学生. 又红又专的自然语言处理工程师. 大家都知道斯坦福大学有很多高质量公开课,其中一个比较有名的是 CS224n: Natural Language Processing with Deep Learning ,做NLP的小伙伴基本都听说过。. 这门课不仅课件好 ...

  7. cs224n-assignment-solutions · GitHub Topics · GitHub

    To associate your repository with the cs224n-assignment-solutions topic, visit your repo's landing page and select "manage topics." GitHub is where people build software. More than 100 million people use GitHub to discover, fork, and contribute to over 420 million projects.

  8. a4.pdf

    CS 224n Assignment 4 Page 3 of 7 P t = softmax(W vocab o t) where P t ∈ R V t × 1, W vocab ∈ R V t × h (13) Here, V t is the size of the target vocabulary. Finally, to train the network we then compute the softmax cross entropy loss between P t and g t, where g t is the one-hot vector of the target word at timestep t: J t (θ) = CrossEntropy (P t, g t ) (14) Here, θ represents all the ...

  9. CS224N

    CS224N - Natural Language Processing. Course is Inactive. This course is designed to introduce students to the fundamental concepts and ideas in natural language processing (NLP), and to get them up to speed with current research in the area. It develops an in-depth understanding of both the algorithms available for the processing of linguistic ...

  10. CS 224N Assignment 4: Question Answering on SQuAD

    CS 224N Assignment 4: Question Answering on SQuAD. R. A. Ozturk, Huseyin A. Inan, Kevin Garbe. Published 2017. Computer Science. TLDR. This project's implementation is motivated from a recent highperformance achieving method that combines coattention encoder with a dynamic pointing decoder known as Dynamic Coattention Network. Expand.

  11. a4.pdf

    CS 224n: Assignment #4 This assignment is split into two sections: Neural Machine Translation with RNNs and Analyzing NMT Systems. The first is primarily coding and implementation focused, whereas the second entirely consists of written, analysis questions. If you get stuck on the first section, you can always work on the second.

  12. CS 224N

    Foundations of Machine Learning (e.g. CS 221 or CS 229) We will be formulating cost functions, taking derivatives and performing optimization with gradient descent. If you already have basic machine learning and/or deep learning knowledge, the course will be easier; however it is possible to take CS224n without it.

  13. GitHub

    Stanford cs224n course assignments. assignment 1: Exploring word vectors (sparse or dense word representations). assignment 2: Implement Word2Vec with NumPy. assignment 3: Implement a neural transition-based dependency parser with PyTorch. (ref: A Fast and Accurate Dependency Parser using Neural Networks ( https://nlp.stanford.edu/pubs ...

  14. PDF CS 224n: Assignment #2

    CS 224n: Assignment #2 Hint: Note that con guration variables are stored in the Con g class. You will need to use these con guration variables in the code. Solution: Placeholder variables and feed dictionaries make it possible to feed data (such as training examples for a neural network) into the computational graph.

  15. CS224n: Natural Language Processing with Deep Learning

    Assignment 4 (12%): Neural Machine Translation with sequence-to-sequence, attention, and subwords ... students explore deep learning solutions to the SQuAD (Stanford Question Asking Dataset) challenge. This year's project is similar to last year's, on SQuAD 2.0 with baseline code in PyTorch. ... CS224n 2015 (lectures 2/3/4) Statistical Machine ...

  16. GitHub

    CS224n-Assignment. 2019-Assignment 1: Introduction to word vectors. 2019-Assignment 2: Derivatives and implementation of word2vec algorithm. 2019-Assignment 3: Dependency parsing and neural network foundations. 2019-Assignment 4: Neural Machine Translation with sequence-to-sequence and attention. 2021-Assignment 5: Self-supervised learning and ...

  17. CS224n: Natural Language Processing with Deep Learning

    Course materials and notes for Stanford class CS224n: Natural Language Processing with Deep Learning. ... Assignment #2: TensorFlow, Neural Dependency Parsing, and RNN Language Modeling. Due Date: 2/9 (Thu) 11:59 PM PST. Hard deadline: 2/12 (Sun) 11:59 PM PST with 3 late days. ... please upload a PDF file of your solutions to Gradescope. When ...

  18. Assignment 5

    Under two circumstances in i. 1. Averaging between different samples makes k a closer to its expectation μ a, the result is that c is closer to 1 2 ( v a + v b). 2. c is always approximately 1 2 ( v a + v b), exactly when α = 0. 2. Pretrained Transformer models and knowledge access. Implementation: Assignment 5 Code.

  19. GitHub

    Complete solutions for Stanford CS224n, winter, 2019 - ZacBi/CS224n-2019-solutions. Skip to content. Toggle navigation. Sign in Product Actions. Automate any workflow Packages. Host and manage packages Security. Find and fix vulnerabilities ... The solutions for assignment is written by Markdown in Assignments/written part. ...

  20. PDF CS 224n Assignment #2: word2vec (44 Points)

    CS 224n Assignment #2: word2vec (44 Points) Due on Tuesday Jan. 26, 2021 by 4:30pm (before class) 1Written: Understanding word2vec (26 points) Let's have a quick refresher on the word2vec algorithm. The key insight behind word2vec is that 'a word is known by the company it keeps'.

  21. PDF CS 224n: Assignment #5 [updated]

    CS 224n: Assignment #5 [updated] This is the last assignment before you begin working on your projects. It is designed to prepare you for implementing things by yourself. This assignment is coding-heavy and written-question-light. The complexity of the code itself is similar to the complexity of the code you wrote in Assignment 4. What

  22. PDF Natural Language Processing with Deep Learning CS224N/Ling284

    assignment solutions •Students must independently submit their solutions to CS224N homeworks • AI tools policy •Large language models are great (!), but we don't want ChatGPT's solutions to our assignments •Collaborative coding with AI tools is allowed; asking it to answer questions is strictly prohibited