diff --git a/12_2_hello_rnn.py b/12_2_hello_rnn.py index c0364e3..90651da 100644 --- a/12_2_hello_rnn.py +++ b/12_2_hello_rnn.py @@ -75,9 +75,10 @@ def init_hidden(self): hidden, output = model(hidden, input) val, idx = output.max(1) sys.stdout.write(idx2char[idx.data[0]]) + label=label.view(1) loss += criterion(output, label) - print(", epoch: %d, loss: %1.3f" % (epoch + 1, loss.data[0])) + print(", epoch: %d, loss: %1.3f" % (epoch + 1, loss.item())) loss.backward() optimizer.step()