title: How do I fix an InvalidArgumentError with tf.sparse.reorder on my KerasClassifier model?
body: <p>I am trying to run a KerasClassifier on some comment data. Below is my code with the error I keep getting:</p>
  <pre><code>N_FEATURES = 5000
  N_CLASSES= 3
  
  def build_network():
      '''Build a compiled neural netowrk'''
      nn = Sequential()
      nn.add(Dense(500, activation='relu'))
      nn.add(Dense(150, activation='relu'))
      nn.add(Dense(N_CLASSES, activation='softmax'))
      nn.compile(
          loss='categorical_crossentropy',
          optimizer='adam',
          metrics=['accuracy']
      )
      return nn
  
  pipeline = Pipeline([
      ('vect', TfidfVectorizer(max_features=N_FEATURES)),
      ('nn', KerasClassifier(build_fn=build_network,
                            epochs=200,
                            batch_size=128))
  ])
  
  # Make comments a list
  x_list = comm_sample.txt.to_list()
  
  # Stem words
  p_stemmer = PorterStemmer()
  x_stemmed = []
  for word in x_list:
      x_stemmed.append(p_stemmer.stem(word))
  
  # Lemmatize words
  wordnet_lemmatizer = WordNetLemmatizer()
  x_lemma = []
  for word in x_stemmed:
      x_lemma.append(wordnet_lemmatizer.lemmatize(word))
  
  # Remove punctuation 
  x_punct = []
  for word in x_lemma:
      x_punct.append(re.sub(r'[^\w\s]','',word))
  
  X = x_punct
  Y = comm_sample.cat.to_list()
  
  Scores = cross_val_score(pipeline, X, Y, cv=12, scoring='accuracy', error_score='raise', n_jobs=-1)
  Scores
  </code></pre>
  <p>The end of the error from the cross_val_score call:</p>
  <pre><code>InvalidArgumentError: indices[3] = [0,2680] is out of order. Many sparse ops require sorted indices.
      Use `tf.sparse.reorder` to create a correctly ordered copy.
  
   [Op:SerializeManySparse]
  </code></pre>
  <p>I have tried using lists, arrays, and dataframes for the X and Y input into the model and none of it worked. I tried running the cross_val_score() without using a Pipeline and that also didn't work. I also tried ordering the lists/etc. before using them in the model and that didn't change anything. This is my first time building anything with Keras so I'm hoping this is an easy fix. I appreciate any guidance.</p>
  <p>This is a sample of what the data looks like for reference:
  <a href="https://i.stack.imgur.com/hFNIB.png" rel="nofollow noreferrer">comments data</a></p>