Skip to content

Commit

Permalink
sample: Add output file option
Browse files Browse the repository at this point in the history
Some dependencies erroneously print diagnostic
messages to stdout, mixing them with sampling result.

-file option allows workaround this
  • Loading branch information
vi committed Aug 18, 2016
1 parent 690036d commit e4ed2cd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ The sampling script `sample.lua` accepts the following command-line flags:
- `-gpu`: The ID of the GPU to use (zero-indexed). Default is 0. Set this to -1 to run in CPU-only mode.
- `-gpu_backend`: The GPU backend to use; either `cuda` or `opencl`. Default is `cuda`.
- `-verbose`: By default just the sampled text is printed to the console. Set this to 1 to also print some diagnostic information.
- `-output`: By default sampled text gets output to standard output, together with diagnostic messages. This option specifies the file to output the result.
10 changes: 9 additions & 1 deletion sample.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ cmd:option('-temperature', 1)
cmd:option('-gpu', 0)
cmd:option('-gpu_backend', 'cuda')
cmd:option('-verbose', 0)
cmd:option('-output', '-')
local opt = cmd:parse(arg)


Expand All @@ -39,4 +40,11 @@ if opt.verbose == 1 then print(msg) end
model:evaluate()

local sample = model:sample(opt)
print(sample)
if opt.output == "-" then
print(sample)
else
require 'io'
local outfile = io.open(opt.output, "w")
outfile:write(sample)
outfile:close()
end

0 comments on commit e4ed2cd

Please sign in to comment.