Skip to content

Commit 05a9a0b

Browse files
authored
Update text_sentiment_ngrams_tutorial.py
Updates for build.
1 parent d6bb0af commit 05a9a0b

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

beginner_source/text_sentiment_ngrams_tutorial.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,6 @@ def test(data_):
251251
print(f'\tLoss: {train_loss:.4f}(train)\t|\tAcc: {train_acc * 100:.1f}%(train)')
252252
print(f'\tLoss: {valid_loss:.4f}(valid)\t|\tAcc: {valid_acc * 100:.1f}%(valid)')
253253

254-
if valid_loss < min_valid_loss:
255-
min_valid_loss = valid_loss
256-
torch.save(model, 'text_classification.pt')
257-
258254

259255
######################################################################
260256
# Running the model on GPU with the following information:
@@ -358,10 +354,12 @@ def predict(text, model, vocab, ngrams):
358354
front nine at TPC Southwind."
359355

360356
vocab = train_dataset.get_vocab()
361-
with open("text_classification.pt", 'rb') as f:
362-
model = torch.load(f).to("cpu")
363-
print("This is a %s news" %ag_news_label[predict(ex_text_str, model, vocab, 2)])
357+
`
358+
model = model.to("cpu")
359+
360+
print("This is a %s news" %ag_news_label[predict(ex_text_str, model, vocab, 2)])
364361

362+
`
365363
366364
######################################################################
367365
# This is a Sports news

0 commit comments

Comments
 (0)