This is confusing, as here then your X.shape = (n_samples, ngram_size - 1). maybe change line 51 to ngram_size + 1