From 763ada348429f55bb850fb34e8d5c05644262337 Mon Sep 17 00:00:00 2001 From: Raushan Kossayeva <40789015+Raushan2102@users.noreply.github.com> Date: Thu, 12 Nov 2026 22:00:40 -0800 Subject: [PATCH] Note that dropout stays active during sampling in char-RNN generation tutorial --- intermediate_source/char_rnn_generation_tutorial.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/intermediate_source/char_rnn_generation_tutorial.py b/intermediate_source/char_rnn_generation_tutorial.py index 50a6afa11b7..5780bf2a213 100644 --- a/intermediate_source/char_rnn_generation_tutorial.py +++ b/intermediate_source/char_rnn_generation_tutorial.py @@ -377,6 +377,15 @@ def timeSince(since): # - Return the final name # # .. note:: +# ``rnn`` is still in training mode here, so the dropout layer stays +# active while sampling. ``torch.no_grad()`` only turns off gradient +# tracking; it does not turn off dropout. This is what makes the samples +# vary from run to run even though we always pick the top letter. To get +# the same name every time for a given category and starting letter, +# call ``rnn.eval()`` before sampling (and ``rnn.train()`` before training +# again). +# +# .. note:: # Rather than having to give it a starting letter, another # strategy would have been to include a "start of string" token in # training and have the network choose its own starting letter.