Skip to content

Commit f2a771a

Browse files
nadavbh12soumith
authored andcommitted
Handle tied + dimensions mismatch (pytorch#124)
1 parent 18df41e commit f2a771a

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

word_language_model/model.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ def __init__(self, rnn_type, ntoken, ninp, nhid, nlayers, dropout=0.5, tie_weigh
2626
# "Tying Word Vectors and Word Classifiers: A Loss Framework for Language Modeling" (Inan et al. 2016)
2727
# https://arxiv.org/abs/1611.01462
2828
if tie_weights:
29+
if nhid != ninp:
30+
raise ValueError('When using the tied flag, nhid must be equal to emsize')
2931
self.decoder.weight = self.encoder.weight
3032

3133
self.init_weights()

0 commit comments

Comments
 (0)