title: Keras - Predict on model after learning sentiment data throws errors
body: <p>My problem is in getting results through predict method in keras using tensorflow backend. But first a small introduction.</p>
  
  <p>I am using </p>
  
  <ul>
  <li>Python 2.7.12</li>
  <li>Keras==1.2.1</li>
  <li>numpy==1.12.0</li>
  <li>tensorflow==0.12.1</li>
  </ul>
  
  <p>I created a convolutional neural network like in these documentation: <a href="https://blog.keras.io/using-pre-trained-word-embeddings-in-a-keras-model.html" rel="nofollow noreferrer">https://blog.keras.io/using-pre-trained-word-embeddings-in-a-keras-model.html</a></p>
  
  <p>I trained the network with 11842 prepared twitter texts. The only individual change is that I have 3 possibilities for a result (0,1,2). I defined that in following code line:</p>
  
  <pre><code>preds = Dense(3, activation='softmax')(x)
  </code></pre>
  
  <p>So the method fit works without a problem and I am achieving between 88-92% acc.</p>
  
  <pre><code>model_fit = model.fit(x_train, y_train, validation_data=(x_val, y_val), nb_epoch=10, batch_size=128)
  </code></pre>
  
  <p>After the learning process I saved the model in .h5 format (also works fine).</p>
  
  <p>Now I try to load the models and predict with them. First example (trained_model) is done via the same data I used to train ... because I wanted to compare them. The second example (trained_model_2) is done via new twitter texts (I collected earlier).</p>
  
  <pre><code>trained_model = load_model("trained_model.h5")
  prediction_result = trained_model.predict(data_train, batch_size=128)
  print prediction_result.shape ### Prints: (11842, 3)
  
  trained_model_2 = load_model("trained_model.h5")
  prediction_result_2 = trained_model_2.predict(data_predict, batch_size=128)
  </code></pre>
  
  <p>For comparing the training dataset with the "live / new" data set: </p>
  
  <p><code>print data_train.shape   # (11842, 1000)</code></p>
  
  <p><code>print data_predict.shape # (46962, 1000)</code></p>
  
  <p>Also both are from type <code>dtype=int32</code></p>
  
  <p>Following code line raises the first error:</p>
  
  <pre><code>prediction_result_2 = trained_model_2.predict(data_predict, batch_size=128)
  </code></pre>
  
  <blockquote>
    <p>tensorflow.python.framework.errors_impl.InvalidArgumentError: indices[0,999] = 13608 is not in [0, 13480)
         [[Node: Gather_1 = Gather[Tindices=DT_INT32, Tparams=DT_FLOAT, validate_indices=true, _device="/job:localhost/replica:0/task:0/cpu:0"](embedding_1_W_1/read, _recv_input_1_1_0)]]</p>
  </blockquote>
  
  <p>Following code line raises the second error:</p>
  
  <pre><code>trained_model_2 = load_model("trained_model.h5")
  </code></pre>
  
  <blockquote>
    <p>InvalidArgumentError (see above for traceback): indices[0,999] = 13608 is not in [0, 13480)
         [[Node: Gather_1 = Gather[Tindices=DT_INT32, Tparams=DT_FLOAT, validate_indices=true, _device="/job:localhost/replica:0/task:0/cpu:0"](embedding_1_W_1/read, _recv_input_1_1_0)]]</p>
  </blockquote>
  
  <p><strong>EDIT</strong>
  Source Code of the methods I created. Method "trainModule" is only used for training the network / save it. The method "predict_sentiment" is used for my predict tests. The first prediction_results works and returns a numpy array with following shape <strong>(11842, 3)</strong>
  <a href="http://pastebin.com/vZ8bVpfW" rel="nofollow noreferrer">Code - pastbin</a></p>
  
  <p>The whole error output: <a href="http://pastebin.com/uxEweWUn" rel="nofollow noreferrer">Error output - pastbin</a></p>
  
  <p>If some additional information is needed, I will update the question...</p>