def _create_vocab(captions):
 print('Creating vocabulary.')
 counter = Counter()
 for c in captions:
  counter.update(c)
 print('Total words:', len(counter))
 word_counts = [x for x in counter.items() if (x[1] >= FLAGS.min_word_count)]
 word_counts.sort(key=(lambda x: x[1]), reverse=True)
 print('Words in vocabulary:', len(word_counts))
 with tf.gfile.FastGFile(FLAGS.word_counts_output_file, 'w') as f:
  f.write('\n'.join([('%s %d' % (w, c)) for (w, c) in word_counts]))
 print('Wrote vocabulary file:', FLAGS.word_counts_output_file)
 reverse_vocab = [x[0] for x in word_counts]
 unk_id = len(reverse_vocab)
 vocab_dict = dict([(x, y) for (y, x) in enumerate(reverse_vocab)])
 vocab = Vocabulary(vocab_dict, unk_id)
 return vocab

def _create_vocab ( captions ) : print ( 'Creating vocabulary.' ) counter = Counter ( ) for c in captions : counter . update ( c ) print ( 'Total words:' , len ( counter ) ) word_counts = [ x for x in counter . items ( ) if ( x [ 1 ] >= FLAGS . min_word_count ) ] word_counts . sort ( key = ( lambda x : x [ 1 ] ) , reverse = True ) print ( 'Words in vocabulary:' , len ( word_counts ) ) with tf . gfile . FastGFile ( FLAGS . word_counts_output_file , 'w' ) as f : f . write ( '\n' . join ( [ ( '%s %d' % ( w , c ) ) for ( w , c ) in word_counts ] ) ) print ( 'Wrote vocabulary file:' , FLAGS . word_counts_output_file ) reverse_vocab = [ x [ 0 ] for x in word_counts ] unk_id = len ( reverse_vocab ) vocab_dict = dict ( [ ( x , y ) for ( y , x ) in enumerate ( reverse_vocab ) ] ) vocab = Vocabulary ( vocab_dict , unk_id ) return vocab
creates the vocabulary of word to word_id .