Skip to content

Commit 97da3c3

Browse files
committed
Fix bug preventing build in nlp tutorial
1 parent cffd379 commit 97da3c3

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

beginner_source/nlp/advanced_tutorial.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@
124124
import torch.autograd as autograd
125125
import torch.nn as nn
126126
import torch.optim as optim
127-
from sequence_models_tutorial import prepare_sequence
128127

129128
torch.manual_seed(1)
130129

@@ -141,6 +140,13 @@ def argmax(vec):
141140
_, idx = torch.max(vec, 1)
142141
return to_scalar(idx)
143142

143+
144+
def prepare_sequence(seq, to_ix):
145+
idxs = [to_ix[w] for w in seq]
146+
tensor = torch.LongTensor(idxs)
147+
return autograd.Variable(tensor)
148+
149+
144150
# Compute log sum exp in a numerically stable way for the forward algorithm
145151

146152

0 commit comments

Comments
 (0)