Skip to content

Commit 20781ca

Browse files
committed
reformatted code
1 parent 2de473a commit 20781ca

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Seq_to_Seq/Learning_Phrase_Representations.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def forward(self, src):
101101

102102
class Decoder(nn.Module):
103103
def __init__(self, output_dim, emb_dim, hid_dim, dropout):
104-
super().__init__()()
104+
super().__init__()
105105

106106
self.hid_dim = hid_dim
107107
self.output_dim = output_dim
@@ -269,7 +269,10 @@ def train(model, iterator, optimizer, criterion, clip):
269269

270270
# trg = [trg len, batch size]
271271
# output = [trg len, batch size, output dim]
272+
output_dim = output.shape[-1]
272273

274+
output = output[1:].view(-1, output_dim)
275+
trg = trg[1:].view(-1)
273276
loss = criterion(output, trg)
274277

275278
loss.backward()
@@ -351,4 +354,4 @@ def epoch_time(start_time, end_time):
351354

352355
test_loss = evaluate(model, test_iterator, criterion)
353356

354-
print(f"| Test Loss: {test_loss:.3f} | Test PPL: {math.exp(test_loss):7.3f} |")
357+
print(f"| Test Loss: {test_loss:.3f} | Test PPL: {math.exp(test_loss):7.3f} |")

0 commit comments

Comments
 (0)