'Return terms per document with nonzero entries in X.
Parameters
X : {array, sparse matrix}, shape = [n_samples, n_features]
Returns
X_inv : list of arrays, len = n_samples
List of arrays of terms.'

def inverse_transform(self, X):

    self._check_vocabulary()
    if sp.issparse(X):
        X = X.tocsr()
    else:
        X = np.asmatrix(X)
    n_samples = X.shape[0]
    terms = np.array(list(self.vocabulary_.keys()))
    indices = np.array(list(self.vocabulary_.values()))
    inverse_vocabulary = terms[np.argsort(indices)]
    return [inverse_vocabulary[X[i, :].nonzero()[1]].ravel() for i in range(n_samples)]
