(self, length)
Truncate vocabulary to keep most frequent words
        
        Args:
            None
            
        Returns:
            None
Truncate vocabulary to keep most frequent words
        
        Args:
            None
            
        Returns:
            None
Truncate vocabulary to keep most frequent words Args : None Returns : None
def limit_vocab_length(self, length):
        """
        Truncate vocabulary to keep most frequent words
        
        Args:
            None
            
        Returns:
            None 
        """
        if length > self.__len__():
            return
        new_word_to_index = {self.unknown:0}
        new_index_to_word = {0:self.unknown}
        self.word_freq.pop(self.unknown)          #pop unk word
        sorted_tup = sorted(self.word_freq.items(), key=operator.itemgetter(1))
        sorted_tup.reverse()
        vocab_tup = sorted_tup[:length]
        self.word_freq = dict(vocab_tup)
        for word in self.word_freq:
            index = len(new_word_to_index)
            new_word_to_index[word] = index
            new_index_to_word[index] = word
        self.word_to_index = new_word_to_index
        self.index_to_word = new_index_to_word
        self.word_freq[self.unknown]=0
def limit_vocab_length ( self , length ) : if length > self . __len__ ( ) : return new_word_to_index = { self . unknown : 0 } new_index_to_word = { 0 : self . unknown } self . word_freq . pop ( self . unknown ) #pop unk word sorted_tup = sorted ( self . word_freq . items ( ) , key = operator . itemgetter ( 1 ) ) sorted_tup . reverse ( ) vocab_tup = sorted_tup [ : length ] self . word_freq = dict ( vocab_tup ) for word in self . word_freq : index = len ( new_word_to_index ) new_word_to_index [ word ] = index new_index_to_word [ index ] = word self . word_to_index = new_word_to_index self . index_to_word = new_index_to_word self . word_freq [ self . unknown ] = 0