title: Keras | Can't define Model - ValueError: Invalid reduction dimension 2 for input with 2 dimensions
body: <p>When I try to create this audio generating RNN I'm getting a weird error facing my input. But I don't really know how I should interpret the error. </p>
  
  <p>I'm creating two input Tensors: noise and label with dim. (100,) and (1,). Then I'm embedding the labels. Then I create a propper input and init the model input and return the finished Model with input and output.
  The error says that it's unable to reduce dimensions to 2 from 2 dim. input and that the input would have the shape [?,100], [2] which is "not" the case?</p>
  
  <p>Thanks in advance!</p>
  
  <p><strong>Code:</strong></p>
  
  <p><em>call: build_audio_generator(100, 1)</em></p>
  
  <pre><code>def build_audio_generator(latent_dim, num_classes):
  
      model = Sequential()
      model.add(LSTM(512, input_dim=latent_dim, return_sequences=True))
      model.add(Dropout(0.3))
      model.add(LSTM(512, return_sequences=True))
      model.add(Dropout(0.3))
      model.add(LSTM(512))
      model.add(Dense(256))
      model.add(Dropout(0.3))
      model.add(Dense(num_classes))
      model.add(Activation('softmax'))
  
      model.summary()
  
      noise = Input(shape=(latent_dim,))
      label = Input(shape=(1,), dtype='int32')
  
      label_embedding = Flatten()(Embedding(num_classes, 100)(label))
      model_input = multiply([noise, label_embedding])
  
      sound = model(model_input)
  
      return Model([noise, label], sound)
  </code></pre>
  
  <p><strong>Error:</strong> </p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Users\MrGrimod\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 686, in _call_cpp_shape_fn_impl
      input_tensors_as_shapes, status)
    File "C:\Users\MrGrimod\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\errors_impl.py", line 473, in __exit__
      c_api.TF_GetCode(self.status.status))
  tensorflow.python.framework.errors_impl.InvalidArgumentError: Invalid reduction dimension 2 for input with 2 dimensions. for 'sequential_3/lstm_1/Sum' (op: 'Sum') with input shapes: [?,100], [2] and with comput
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File "main.py", line 94, in &lt;module&gt;
      main()
    File "main.py", line 67, in main
      audio_generator = build_audio_generator(latent_dim, num_classes)
    File "C:\Users\MrGrimod\Desktop\gan-audio-generator\model.py", line 70, in build_audio_generator
      sound = model(model_input)
    File "C:\Users\MrGrimod\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\topology.py", line 603, in __call__
      output = self.call(inputs, **kwargs)
    File "C:\Users\MrGrimod\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\models.py", line 546, in call
      return self.model.call(inputs, mask)
    File "C:\Users\MrGrimod\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\topology.py", line 2061, in call
      output_tensors, _, _ = self.run_internal_graph(inputs, masks)
    File "C:\Users\MrGrimod\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\topology.py", line 2212, in run_internal_graph
      output_tensors = _to_list(layer.call(computed_tensor, **kwargs))
    File "C:\Users\MrGrimod\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\layers\recurrent.py", line 2023, in call
      initial_state=initial_state)
    File "C:\Users\MrGrimod\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\layers\recurrent.py", line 540, in call
      initial_state = self.get_initial_state(inputs)
    File "C:\Users\MrGrimod\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\layers\recurrent.py", line 469, in get_initial_state
      initial_state = K.sum(initial_state, axis=(1, 2))  # (samples,)
    File "C:\Users\MrGrimod\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\backend\tensorflow_backend.py", line 1242, in sum
      return tf.reduce_sum(x, axis=axis, keep_dims=keepdims)
    File "C:\Users\MrGrimod\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\ops\math_ops.py", line 1307, in reduce_sum
      name=name)
    File "C:\Users\MrGrimod\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\ops\gen_math_ops.py", line 4681, in _sum
      keep_dims=keep_dims, name=name)
    File "C:\Users\MrGrimod\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 787, in _apply_op_helper
      op_def=op_def)
    File "C:\Users\MrGrimod\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 2958, in create_op
      set_shapes_for_outputs(ret)
    File "C:\Users\MrGrimod\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 2209, in set_shapes_for_outputs
      shapes = shape_func(op)
    File "C:\Users\MrGrimod\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 2159, in call_with_requiring
      return call_cpp_shape_fn(op, require_shape_fn=True)
    File "C:\Users\MrGrimod\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 627, in call_cpp_shape_fn
      require_shape_fn)
    File "C:\Users\MrGrimod\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 691, in _call_cpp_shape_fn_impl
      raise ValueError(err.message)
  ValueError: Invalid reduction dimension 2 for input with 2 dimensions. for 'sequential_3/lstm_1/Sum' (op: 'Sum') with input shapes: [?,100], [2] and with computed input tensors: input[1] = &lt;1 2&gt;.
  </code></pre>