title: How to add a trainable weight to an LSTM in Keras/Tensorflow
body: <p>I would like to add a trainable weight to my LSTM and when I use the following wrapper provided by Keras, the tensor is initialized but isn't added to the LSTM layer. When I use the same code on Dense layers or convnets it works properly. Is there any other way to add a variable to a recurrent model?</p>
  
  <pre><code>def __init__(self, output_dim, **kwargs):
      self.output_dim = output_dim
      super(MyLayer, self).__init__(**kwargs)
  
  def build(self, input_shape):
      assert isinstance(input_shape, list)
      # Create a trainable weight variable for this layer.
      self.kernel = self.add_weight(name='kernel',
                                    shape=(input_shape[0][1], self.output_dim),
                                    initializer='uniform',
                                    trainable=True)
      super(MyLayer, self).build(input_shape)  # Be sure to call this at the end
  
  def call(self, x):
      assert isinstance(x, list)
      a, b = x
      return [K.dot(a, self.kernel) + b, K.mean(b, axis=-1)]
  
  def compute_output_shape(self, input_shape):
      assert isinstance(input_shape, list)
      shape_a, shape_b = input_shape
      return [(shape_a[0], self.output_dim), shape_b[:-1]]
  </code></pre>