def story(z, image_loc, k=100, bw=50, lyric=False):
 (rawim, im) = load_image(image_loc)
 feats = compute_features(z['net'], im).flatten()
 feats /= norm(feats)
 feats = embedding.encode_images(z['vse'], feats[None, :])
 scores = numpy.dot(feats, z['cvec'].T).flatten()
 sorted_args = numpy.argsort(scores)[::(-1)]
 sentences = [z['cap'][a] for a in sorted_args[:k]]
 print 'NEAREST-CAPTIONS: '
 for s in sentences[:5]:
  print s
 print ''
 svecs = skipthoughts.encode(z['stv'], sentences, verbose=False)
 shift = ((svecs.mean(0) - z['bneg']) + z['bpos'])
 passage = decoder.run_sampler(z['dec'], shift, beam_width=bw)
 print 'OUTPUT: '
 if lyric:
  for line in passage.split(','):
   if (line[0] != ' '):
    print line
   else:
    print line[1:]
 else:
  print passage

def story ( z , image_loc , k = 100 , bw = 50 , lyric = False ) : ( rawim , im ) = load_image ( image_loc ) feats = compute_features ( z [ 'net' ] , im ) . flatten ( ) feats /= norm ( feats ) feats = embedding . encode_images ( z [ 'vse' ] , feats [ None , : ] ) scores = numpy . dot ( feats , z [ 'cvec' ] . T ) . flatten ( ) sorted_args = numpy . argsort ( scores ) [ : : ( - 1 ) ] sentences = [ z [ 'cap' ] [ a ] for a in sorted_args [ : k ] ] print 'NEAREST-CAPTIONS: ' for s in sentences [ : 5 ] : print s print '' svecs = skipthoughts . encode ( z [ 'stv' ] , sentences , verbose = False ) shift = ( ( svecs . mean ( 0 ) - z [ 'bneg' ] ) + z [ 'bpos' ] ) passage = decoder . run_sampler ( z [ 'dec' ] , shift , beam_width = bw ) print 'OUTPUT: ' if lyric : for line in passage . split ( ',' ) : if ( line [ 0 ] != ' ' ) : print line else : print line [ 1 : ] else : print passage
generate a story for an image at location image_loc .