Skip to content

Commit

Permalink
added assignment 4
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdelrahmanAbouelenin committed May 5, 2020
1 parent 0bb7bcf commit ef966d6
Show file tree
Hide file tree
Showing 84 changed files with 452,869 additions and 1 deletion.
3 changes: 2 additions & 1 deletion assignment 2/sgd.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ def sgd(f, x0, step, iterations, postprocessing=None, useSaved=False,

loss = None
### YOUR CODE HERE

loss,gradient = f(x)
x=x-step*gradient
### END YOUR CODE

x = postprocessing(x)
Expand Down
Binary file removed assignment 3/__MACOSX/a3/._.DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions assignment 4/a4/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# NMT Assignment
Note: Heavily inspired by the https://github.com/pcyin/pytorch_nmt repository
Empty file added assignment 4/a4/__init__.py
Empty file.
2 changes: 2 additions & 0 deletions assignment 4/a4/collect_submission.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rm -f assignment4.zip
zip -r assignment4.zip *.py ./en_es_data ./sanity_check_en_es_data ./outputs
851 changes: 851 additions & 0 deletions assignment 4/a4/en_es_data/dev.en

Large diffs are not rendered by default.

851 changes: 851 additions & 0 deletions assignment 4/a4/en_es_data/dev.es

Large diffs are not rendered by default.

8,064 changes: 8,064 additions & 0 deletions assignment 4/a4/en_es_data/test.en

Large diffs are not rendered by default.

8,064 changes: 8,064 additions & 0 deletions assignment 4/a4/en_es_data/test.es

Large diffs are not rendered by default.

216,617 changes: 216,617 additions & 0 deletions assignment 4/a4/en_es_data/train.en

Large diffs are not rendered by default.

216,617 changes: 216,617 additions & 0 deletions assignment 4/a4/en_es_data/train.es

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions assignment 4/a4/gpu_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nltk
docopt
tqdm==4.29.1
13 changes: 13 additions & 0 deletions assignment 4/a4/local_env.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: local_nmt
channels:
- pytorch
- defaults
dependencies:
- python=3.5
- numpy
- scipy
- tqdm
- docopt
- pytorch
- nltk
- torchvision
58 changes: 58 additions & 0 deletions assignment 4/a4/model_embeddings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
CS224N 2019-20: Homework 4
model_embeddings.py: Embeddings for the NMT model
Pencheng Yin <pcyin@cs.cmu.edu>
Sahil Chopra <schopra8@stanford.edu>
Anand Dhoot <anandd@stanford.edu>
Vera Lin <veralin@stanford.edu>
"""

import torch.nn as nn

class ModelEmbeddings(nn.Module):
"""
Class that converts input words to their embeddings.
"""
def __init__(self, embed_size, vocab):
"""
Init the Embedding layers.
@param embed_size (int): Embedding size (dimensionality)
@param vocab (Vocab): Vocabulary object containing src and tgt languages
See vocab.py for documentation.
"""
super(ModelEmbeddings, self).__init__()
self.embed_size = embed_size

# default values
self.source = None
self.target = None

src_pad_token_idx = vocab.src['<pad>']
tgt_pad_token_idx = vocab.tgt['<pad>']

### YOUR CODE HERE (~2 Lines)
### TODO - Initialize the following variables:
### self.source (Embedding Layer for source language)
### self.target (Embedding Layer for target langauge)
###
### Note:
### 1. `vocab` object contains two vocabularies:
### `vocab.src` for source
### `vocab.tgt` for target
### 2. You can get the length of a specific vocabulary by running:
### `len(vocab.<specific_vocabulary>)`
### 3. Remember to include the padding token for the specific vocabulary
### when creating your Embedding.
###
### Use the following docs to properly initialize these variables:
### Embedding Layer:
### https://pytorch.org/docs/stable/nn.html#torch.nn.Embedding


### END YOUR CODE


482 changes: 482 additions & 0 deletions assignment 4/a4/nmt_model.py

Large diffs are not rendered by default.

Empty file.
Loading

0 comments on commit ef966d6

Please sign in to comment.