Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed stochastic sampling (it was indexing a scalar). #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,19 @@ def run_sampler(dec, c, beam_width=1, stochastic=False, use_unk=False):
"""
Generate text conditioned on c
"""
if stochastic and beam_width > 1:
print ("Beam search does not support stochastic sampling. " +
"Setting beam_width to 1\n")
beam_width = 1

sample, score = gen_sample(dec['tparams'], dec['f_init'], dec['f_next'],
c.reshape(1, dec['options']['dimctx']), dec['options'],
trng=dec['trng'], k=beam_width, maxlen=1000, stochastic=stochastic,
use_unk=use_unk)
text = []
if stochastic:
sample = [sample]
score = [score]
for c in sample:
text.append(' '.join([dec['word_idict'][w] for w in c[:-1]]))

Expand Down
4 changes: 2 additions & 2 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
ImageFile.LOAD_TRUNCATED_IMAGES = True


def story(z, image_loc, k=100, bw=50, lyric=False):
def story(z, image_loc, k=100, bw=50, lyric=False, stochastic=False):
"""
Generate a story for an image at location image_loc
"""
Expand Down Expand Up @@ -62,7 +62,7 @@ def story(z, image_loc, k=100, bw=50, lyric=False):
shift = svecs.mean(0) - z['bneg'] + z['bpos']

# Generate story conditioned on shift
passage = decoder.run_sampler(z['dec'], shift, beam_width=bw)
passage = decoder.run_sampler(z['dec'], shift, beam_width=bw, stochastic=stochastic)
print 'OUTPUT: '
if lyric:
for line in passage.split(','):
Expand Down