I made a neural network with word embedding, RNN and some dense layers to predict the score of computer game reviews based on the title of the game. I used Keras in Python. I was wondering if it would be somehow possible to transform my model into a generative one that would produce titles with high (or low) predicted score. It could be possible to do brute forcing and run all combinations through my network but maybe there is a smarter solution.

  • $\begingroup$ Out of interest, does your regression model perform well at all, on new/unseen data? A generative model conditioned on the review score will only perform well if there is truly a link between the the title and review score. Intuitively, I would expect a game title to be at best very weakly correlated to review scores, and even if your model appears to work, I first would go looking for possible data leaks (such as established series titles in both training and test set) $\endgroup$ Feb 3, 2017 at 11:37
  • $\begingroup$ I think the general question - how to move from predictive to generative model - is very interesting though. I have seen this done for image/CNN-based classifier networks, but don't know how to make a similar thing work for text/RNN-based ones. $\endgroup$ Feb 3, 2017 at 11:38
  • $\begingroup$ You are right, intuitively I also thought that. But at the end my MSE was 2.2 that means I have less than 1.5 point error in average on a scale of 0-10. Tested and trained on the IGN game review dataset that is available on Kaggle. It is a little messy yet but you can take a look at my jupyter notebook about the training process. You can also try the model in my web app. $\endgroup$
    – Viktor
    Feb 3, 2017 at 11:46
  • $\begingroup$ What's the MSE for guessing the mean review rating for all games? $\endgroup$ Feb 3, 2017 at 11:51
  • $\begingroup$ MSE for using only the mean is 2.93 $\endgroup$
    – Viktor
    Feb 3, 2017 at 13:13

1 Answer 1


There's more than one type of generative network. However, I am not aware of a generic approach that can take a trained RNN-based network and essentially run it backwards to sample an input that is expected to produce a given output. So I am suggesting a couple of generative approaches that I have seen working, but that will require that you construct and train a new network.

You can bring in some knowledge about the typical size of network that learns the regression model, but you cannot AFAIK directly re-use the regression model and somehow reverse it.

A caveat: Although I have played briefly with both types of generative network, I have never constructed one conditioned on desired goal like the one you want to work with.

With a purely RNN-based approach, you might do OK by making your network predict the next letter/word in the title - a classifier - whilst taking the title so far (or X characters/words of it) and the rating (normalised) as inputs.

Then, once trained, you can sample from the RNN randomly to generate new strings. This is the technique used by e.g. Karpathy in his now famous blog "The Unreasonable Effectiveness of Recurrent Neural Networks". There are many examples of such sequence sampling generators available to study.

You could also take the output of such a model and see if it matches your regression model from earlier. But I don't think there is much you can do if it does not, except perhaps filter out generated titles if they don't meet expectations - e.g. generate many titles with intended rating of 10, and only display one when your initial model also agrees with a close to 10 rating.

The most relevant Keras example for this I could find is lstm_text_generation.py

A RNN-based generative adversarial network (GAN) might also be able to achieve what you want. However, please note that GANs are notoriously fiddly to train.

A GAN is actually 2 networks. You create a discriminator and a generator and train them in parallel. The generator takes a small completely random vector (e.g. 10 numbers sampled from N(0,1)), plus the rating you want to achieve. Then it generates a text sequence output. The discriminator would take a text input, and a rating, and outputs 1 if it is real, or 0 if it is fake. You present either real training data or output form the generator to the discriminator, and use these to train it. You train the generator based on whether it fools the discriminator.

The tricky part is to maintain balance between the two components - if either becomes too good relative to the other, training will stall.

However, if you can get it to work, you will have a true generative model, which samples from a population space (the noise vector that you input) plus is conditioned on the rating.

The most relevant Keras example for this I could find is mnist_acgan.py which generates an image, not text sequence, but hopefully should give a start.

  • $\begingroup$ Thanks for the detailed answer! It is a little different approach that I wanted to achieve but may have the same output. $\endgroup$
    – Viktor
    Feb 3, 2017 at 13:41
  • $\begingroup$ @Viktor: Well, there might still be other approaches that suit you better, wait and see if anyone else answers. Also a good place to browse for ideas in generative neural networks could be creativeai.net - there are quite a few trained sequence generators amongst the projects there that could inspire some research. $\endgroup$ Feb 3, 2017 at 13:44
  • $\begingroup$ Thanks for the detailed answer! It is a different approach than my question but may have similar output. My problem with the RNN based solution is that it is only a smarter version of brute forcing. The generated titles will be similar to the real ones but there is no guarantee that they will also score high. Maybe I can filter my dataset and use only titles with high values for training. Or maybe somehow I can incorporate into the loss function the score to direct my network more toward learning good scored titles. I haven't seen GAN yet but looks interesting. Thanks for recommending! $\endgroup$
    – Viktor
    Feb 3, 2017 at 13:50
  • $\begingroup$ You can condition the output of the RNN with the desired rating - which is what I suggest. I don't think either method will guarantee that your existing trained model will agree with the input score. To do that you would really need some kind of reversal to the input data - with images that is possible, it is how e.g. Deep Dream works. But for a RNN I don't know how you could take that approach. But essentially for Deep Dream or style transfer you input noise, run the network forward, then run the training backprop all the way back to the input and adjust that using the gradient. $\endgroup$ Feb 3, 2017 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.