#NEWLINE# def write_punctuations( net , punctuation_reverse_map , document ) : #NEWLINE# #INDENT# inputs = document . split ( ) #NEWLINE# inputs = ( fix_missing_pauses ( inputs ) + [ '<END>' ] ) #NEWLINE# word = None #NEWLINE# pause = 0.0 #NEWLINE# tags = [ ] #NEWLINE# first_word = True #NEWLINE# for token in inputs : #NEWLINE# #INDENT# if is_pause ( token ) : #NEWLINE# #INDENT# previous_pause = inputs #NEWLINE# pause = float ( token . replace ( '<sil=' , '' ) . replace ( '>' , '' ) ) #NEWLINE# word_index = utils . input_word_index ( net . in_vocabulary , word ) #NEWLINE# punctuation_index = net . predict_punctuation ( [ word_index ] , np . array ( [ previous_pause ] ) ) [ 0 ] #NEWLINE# if first_word : #NEWLINE# #INDENT# punctuation = '' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# punctuation = punctuation_reverse_map [ punctuation_index ] #NEWLINE# #UNINDENT# tagstring = ( ( ' ' . join ( tags ) + ' ' ) if tags else '' ) #NEWLINE# tags = [ ] #NEWLINE# if ( punctuation . strip ( ) == '' ) : #NEWLINE# #INDENT# sys . stdout . write ( ( '%s%s%s' % ( punctuation , tagstring , word ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# sys . stdout . write ( ( '%s %s%s' % ( punctuation [ : 1 ] , tagstring , word ) ) ) #NEWLINE# #UNINDENT# first_word = False #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if is_word ( token ) : #NEWLINE# #INDENT# word = token #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# tags . append ( token ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# sys . stdout . write ( '\n' ) #NEWLINE# sys . stdout . flush ( )