From 0efbc0007f1f95396910015f0cfcf0d96edb0434 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Wed, 17 Feb 2016 11:15:42 +0000 Subject: [PATCH] Stream sampled text --- LanguageModel.lua | 2 ++ sample.lua | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/LanguageModel.lua b/LanguageModel.lua index 57626ffc..35785f05 100644 --- a/LanguageModel.lua +++ b/LanguageModel.lua @@ -139,6 +139,7 @@ function LM:sample(kwargs) print('Seeding with: "' .. start_text .. '"') end local x = self:encode_string(start_text):view(1, -1) + io.write(start_text) local T0 = x:size(2) sampled[{{}, {1, T0}}]:copy(x) scores = self:forward(x)[{{}, {T0, T0}}] @@ -162,6 +163,7 @@ function LM:sample(kwargs) next_char = torch.multinomial(probs, 1):view(1, 1) end sampled[{{}, {t, t}}]:copy(next_char) + io.write(self.idx_to_token[next_char[1][1]]) scores = self:forward(next_char) end diff --git a/sample.lua b/sample.lua index 57b97020..bb80e973 100644 --- a/sample.lua +++ b/sample.lua @@ -41,4 +41,4 @@ if opt.verbose == 1 then print(msg) end model:evaluate() local sample = model:sample(opt) -print(sample) +print('')