def add_ngram(sequences, token_indice, ngram_range=2):
 new_sequences = []
 for input_list in sequences:
  new_list = input_list[:]
  for i in range(((len(new_list) - ngram_range) + 1)):
   for ngram_value in range(2, (ngram_range + 1)):
    ngram = tuple(new_list[i:(i + ngram_value)])
    if (ngram in token_indice):
     new_list.append(token_indice[ngram])
  new_sequences.append(new_list)
 return new_sequences

def add_ngram ( sequences , token_indice , ngram_range = 2 ) : new_sequences = [ ] for input_list in sequences : new_list = input_list [ : ] for i in range ( ( ( len ( new_list ) - ngram_range ) + 1 ) ) : for ngram_value in range ( 2 , ( ngram_range + 1 ) ) : ngram = tuple ( new_list [ i : ( i + ngram_value ) ] ) if ( ngram in token_indice ) : new_list . append ( token_indice [ ngram ] ) new_sequences . append ( new_list ) return new_sequences
augment the input list of list by appending n-grams values .