This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
cs501r_f2018:lab6 [2018/10/09 18:38] sadler [Description:] |
cs501r_f2018:lab6 [2021/06/30 23:42] (current) |
||
---|---|---|---|
Line 76: | Line 76: | ||
[[http://colah.github.io/posts/2015-08-Understanding-LSTMs/|Understanding LSTM Networks]] | [[http://colah.github.io/posts/2015-08-Understanding-LSTMs/|Understanding LSTM Networks]] | ||
+ | |||
+ | <code bash> | ||
+ | ! wget -O ./text_files.tar.gz 'https://piazza.com/redirect/s3?bucket=uploads&prefix=attach%2Fjlifkda6h0x5bk%2Fhzosotq4zil49m%2Fjn13x09arfeb%2Ftext_files.tar.gz' | ||
+ | ! tar -xzf text_files.tar.gz | ||
+ | ! pip install unidecode | ||
+ | ! pip install torch | ||
+ | </code> | ||
+ | |||
+ | |||
<code python> | <code python> | ||
Line 126: | Line 135: | ||
<code python> | <code python> | ||
+ | import time | ||
n_epochs = 2000 | n_epochs = 2000 | ||
print_every = 100 | print_every = 100 | ||
Line 142: | Line 152: | ||
for epoch in range(1, n_epochs + 1): | for epoch in range(1, n_epochs + 1): | ||
- | loss = train(*random_training_set()) | + | loss_ = train(*random_training_set()) |
- | loss_avg += loss | + | loss_avg += loss_ |
if epoch % print_every == 0: | if epoch % print_every == 0: | ||
- | print('[%s (%d %d%%) %.4f]' % (time_since(start), epoch, epoch / n_epochs * 100, loss)) | + | print('[%s (%d %d%%) %.4f]' % (time.time() - start, epoch, epoch / n_epochs * 100, loss_)) |
print(evaluate('Wh', 100), '\n') | print(evaluate('Wh', 100), '\n') | ||
Line 181: | Line 191: | ||
# decode output | # decode output | ||
| | ||
- | def forward(self, input_vector, hidden): | + | def forward(self, input_char, hidden): |
# by reviewing the documentation, construct a forward function that properly uses the output | # by reviewing the documentation, construct a forward function that properly uses the output | ||
# of the GRU | # of the GRU | ||
Line 202: | Line 212: | ||
# your code here | # your code here | ||
## / | ## / | ||
+ | loss = 0 | ||
for c in range(chunk_len): | for c in range(chunk_len): | ||
output, hidden = # run the forward pass of your rnn with proper input | output, hidden = # run the forward pass of your rnn with proper input | ||
- | loss += criterion(output, target[c].view(1)) | + | loss += criterion(output, target[c].unsqueeze(0)) |
## calculate backwards loss and step the optimizer (globally) | ## calculate backwards loss and step the optimizer (globally) |