title: LSTM autoencoder on sequences - what loss function?
body: <p>I'm trying to construct an LSTM autoencoder on sequences of text (titles of web articles) mostly by reproducing the mentioned basic example in <a href="https://blog.keras.io/building-autoencoders-in-keras.html" rel="nofollow noreferrer">https://blog.keras.io/building-autoencoders-in-keras.html</a>. The input are 80 (maximum title length) one-hot vectors of length 40 (number of ascii characters in dataset). The output, against which the predictions are checked, is the same as input, because it is an autoencoder. I have about 60k sequences for testing the model, but ultimately, I would like to run it on the whole set of 320k.</p>
  
  <h2>Problem</h2>
  
  <p>But the problem is, that the LSTM network isn't learning properly at all. For instance, the Czech sentence 'Real vyhrál slavné derby s Barcelonou' gets reproduced as '###uuu...uuu' (dots mean, that the u's continue till the end).</p>
  
  <p>In the tutorial above, it doesn't mention what loss function, activation function or optimizer to use, so I searched and found, that with LSTMs <em>RMSProp</em> optimizer works the best. I tried RELU, Tanh, Softmax etc. as activation functions, though none of them did any better. What I am hesitating most about is the loss function. I thought that binary or categorical cross-entropy would work nicely, but this just might be where I am mistaken. Mean squared error didn't yield any good results either.</p>
  
  <h1>My model thus far</h1>
  
  <pre><code>input_sentence = Input(shape=(max_title_length, number_of_chars), dtype='int32')
  tofloat = Lambda(function=lambda x: tf.to_float(x))(input_sentence)
  encoder = LSTM(latent_dim, activation='tanh')(tofloat)
  
  decoder = RepeatVector(max_title_len)(encoder)
  decoder = LSTM(number_of_chars, return_sequences=True, activation='tanh')(decoder)
  autoencoder = Model(input=input_sentence, output=decoder)
  
  autoencoder.compile(loss='binary_crossentropy', optimizer='rmsprop', metrics=['accuracy'])
  </code></pre>
  
  <h1>So the questions</h1>
  
  <ol>
  <li>What loss function would you use?</li>
  <li>Does the binary/categorical cross-entropy calculate loss for the entire output matrix or for individual timesteps (rows in the output matrix)? I would like to achieve the latter.</li>
  <li>If you think this approach isn't going to work, would you suggest a different one?</li>
  </ol>