Skip to content

Commit 19cdeeb

Browse files
committed
fix test loss doesn't accumulate
1 parent 36ea6fc commit 19cdeeb

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

beginner_source/text_sentiment_ngrams_tutorial.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,7 @@ def test(data_):
197197
text, offsets, cls = text.to(device), offsets.to(device), cls.to(device)
198198
with torch.no_grad():
199199
output = model(text, offsets)
200-
loss = criterion(output, cls)
201-
loss += loss.item()
200+
loss += criterion(output, cls).item()
202201
acc += (output.argmax(1) == cls).sum().item()
203202

204203
return loss / len(data_), acc / len(data_)

0 commit comments

Comments
 (0)