<s> """<STR_LIT>""" <EOL> from fuel . datasets . hdf5 import H5PYDataset <EOL> class H5PYAudioDataset ( H5PYDataset ) : <EOL> def __init__ ( self , target_source , ** kwargs ) : <EOL> self . target_source = target_source <EOL> super ( H5PYAudioDataset , self ) . __init__ ( ** kwargs ) <EOL> self . open ( ) <EOL> self . char2num = self . character_map ( target_source ) <EOL> self . num2char = { num : char for char , num in self . char2num . items ( ) } <EOL> self . num_characters = len ( self . num2char ) <EOL> self . eos_label = self . char2num [ '<STR_LIT>' ] <EOL> self . bos_label = self . char2num . get ( '<STR_LIT>' ) <EOL> def character_map ( self , source ) : <EOL> return dict ( self . _file_handle [ source ] . attrs [ '<STR_LIT>' ] ) <EOL> def dim ( self , source ) : <EOL> return self . _file_handle [ source + '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> def decode ( self , labels , keep_eos = False ) : <EOL> return [ self . num2char [ label ] for label in labels <EOL> if ( label != self . eos_label or keep_eos ) <EOL> and label != self . bos_label ] <EOL> def pretty_print ( self , labels , example ) : <EOL> labels = self . decode ( labels ) <EOL> labels = '<STR_LIT>' . join ( ( '<STR_LIT:U+0020>' if chr_ == '<STR_LIT>' else chr_ for chr_ in labels ) ) <EOL> return labels <EOL> def monospace_print ( self , labels ) : <EOL> labels = self . decode ( labels , keep_eos = True ) <EOL> labels = ( '<STR_LIT:_>' if label == '<STR_LIT>' else label for label in labels ) <EOL> labels = ( '<STR_LIT>' if label == '<STR_LIT>' else label for label in labels ) <EOL> labels = ( '<STR_LIT:$>' if label == '<STR_LIT>' else label <EOL> for label in labels ) <EOL> labels = ( '<STR_LIT>' if label == '<STR_LIT>' else label <EOL> for label in labels ) <EOL> labels = '<STR_LIT>' . join ( ( chr_ for chr_ in labels ) ) <EOL> return labels <EOL> class H5PYAudioDatasetTimit ( H5PYAudioDataset ) : <EOL> phone_map = [ <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT:b>" , "<STR_LIT:b>" , "<STR_LIT:b>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT:d>" , "<STR_LIT:d>" , "<STR_LIT:d>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:l>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT:m>" , "<STR_LIT:m>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:n>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT:f>" , "<STR_LIT:f>" , "<STR_LIT:f>" ) , <EOL> ( "<STR_LIT:g>" , "<STR_LIT:g>" , "<STR_LIT:g>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT:k>" , "<STR_LIT:k>" , "<STR_LIT:k>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT:l>" , "<STR_LIT:l>" , "<STR_LIT:l>" ) , <EOL> ( "<STR_LIT:m>" , "<STR_LIT:m>" , "<STR_LIT:m>" ) , <EOL> ( "<STR_LIT:n>" , "<STR_LIT:n>" , "<STR_LIT:n>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT:n>" , "<STR_LIT:n>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT:p>" , "<STR_LIT:p>" , "<STR_LIT:p>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT:q>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT:r>" , "<STR_LIT:r>" , "<STR_LIT:r>" ) , <EOL> ( "<STR_LIT:s>" , "<STR_LIT:s>" , "<STR_LIT:s>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT:t>" , "<STR_LIT:t>" , "<STR_LIT:t>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT:v>" , "<STR_LIT:v>" , "<STR_LIT:v>" ) , <EOL> ( "<STR_LIT:w>" , "<STR_LIT:w>" , "<STR_LIT:w>" ) , <EOL> ( "<STR_LIT:y>" , "<STR_LIT:y>" , "<STR_LIT:y>" ) , <EOL> ( "<STR_LIT:z>" , "<STR_LIT:z>" , "<STR_LIT:z>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> ] <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( H5PYAudioDatasetTimit , self ) . __init__ ( * args , ** kwargs ) <EOL> self . phone_60_39 = { } <EOL> for p60 , p48 , p39 in H5PYAudioDatasetTimit . phone_map : <EOL> self . phone_60_39 [ p60 ] = p39 <EOL> def decode ( self , labels , keep_eos = False , map_to_39 = True ) : <EOL> ret = [ ] <EOL> for label in labels : <EOL> if label in [ self . eos_label , self . bos_label ] : <EOL> continue <EOL> ph = self . num2char [ label ] <EOL> if map_to_39 : <EOL> ph = self . phone_60_39 [ ph ] <EOL> if ph == "<STR_LIT>" : <EOL> continue <EOL> ret . append ( ph ) <EOL> return ret <EOL> def pretty_print ( self , labels , example ) : <EOL> labels = self . decode ( labels ) <EOL> labels = '<STR_LIT:U+0020>' . join ( labels ) <EOL> return labels </s>
