0
$\begingroup$

I want to generate some text based on the value of certain parameters. For instance, let's say I want to generate descriptions of video games. So, besides real descriptions as training data, I would like that the model takes in account the following parameters (for example) about the game:

  • Violent: yes
  • Multiplatform: yes
  • Drugs: no

So that if the game has drugs content, the output text has some phrase referring to it.

Is this possible? If so, how could I do it in Python? I was going to use LSTM neural networks in Tensorflow.

$\endgroup$
2
  • $\begingroup$ Is there no other input to the generation of the description but these 3 binary features? $\endgroup$
    – noe
    Mar 5 '20 at 13:45
  • $\begingroup$ There may be more binary features, and a little manual introduction (i.e. "Call of duty is") or a categorical feature with the name $\endgroup$ Mar 5 '20 at 14:22
0
$\begingroup$

A direct way would be to encode any binary input features as embedded vectors and add them together as the initial hidden state for the LSTM, and then you train it as a normal language model.

The "little manual introduction" could be supplied to the language model (together with the initial hidden state created from the binary features) at inference time and then use it autoregressively to generate the description.

Given that you are going to deal with proper nouns (i.e. the name of the game), you should use a vocabulary that does not lead to out-of-vocabulary words. I would suggest using a subword-level vocabulary (e.g. byte-pair encoding).

For the implementation, you could do it in Pytorch, using as a starting point their language model example.

$\endgroup$
2
  • $\begingroup$ Thank you very much. It would be possible to do it in Keras instead of PyTorch or Keras is too high level for this kind of tasks? $\endgroup$ Mar 9 '20 at 18:27
  • $\begingroup$ It should be possible to do it in Keras. You could create a custom Layer class (inheriting from keras.engine.topology.Layer), add there a parameter with self.add_weight and then just tile it and concatenate it with the input. I have never done something like this, though, so maybe I am missing something. $\endgroup$
    – noe
    Mar 9 '20 at 18:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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