diff --git a/lime/lime_text.py b/lime/lime_text.py index b9716b7f..6223a797 100644 --- a/lime/lime_text.py +++ b/lime/lime_text.py @@ -468,11 +468,11 @@ def distance_fn(x): return sklearn.metrics.pairwise.pairwise_distances( x, x[0], metric=distance_metric).ravel() * 100 - doc_size = indexed_string.num_words() - sample = self.random_state.randint(1, doc_size + 1, num_samples - 1) - data = np.ones((num_samples, doc_size)) - data[0] = np.ones(doc_size) - features_range = range(doc_size) + vocab_size = indexed_string.num_words() + sample = self.random_state.randint(1, vocab_size + 1, num_samples - 1) + data = np.ones((num_samples, vocab_size)) + data[0] = np.ones(vocab_size) + features_range = range(vocab_size) inverse_data = [indexed_string.raw_string()] for i, size in enumerate(sample, start=1): inactive = self.random_state.choice(features_range, size,