I’m working on a smaller project to better understand RNN, in particualr LSTM and GRU. I’m not at all an expert, so please bear that in mind.
The problem I’m facing is given as data in the form of:
>>> import numpy as np >>> import pandas as pd >>> pd.DataFrame([[1, 2, 3],[1, 2, 1], [1, 3, 2],[2, 3, 1],[3, 1, 1],[3, 3, 2],[4, 3, 3]], columns=['person', 'interaction', 'group']) person interaction group 0 1 2 3 1 1 2 1 2 1 3 2 3 2 3 1 4 3 1 1 5 3 3 2 6 4 3 3
this is just for explanation. We have different person interacting with different groups in different ways. I’ve already encoded the various features. The last interaction of a user is always a
3, which means selecting a certain group. In the short example above
person 1 chooses group
person 2 chooses group
1 and so on.
My whole data set is much bigger but I would like to understand first the conceptual part before throwing models at it. The task I would like to learn is given a sequence of interaction, which group is chosen by the person. A bit more concrete, I would like to have an output a list with all groups (there are 3 groups,
1, 2, 3) sorted by the most likely choice, followed by the second and third likest group. The loss function is therefore a mean reciprocal rank.
I know that in Keras Grus/LSTM can handle various length input. So my three questions are.
The input is of the format:
(samples, timesteps, features)
writing high level code:
import keras.layers as L import keras.models as M model_input = L.Input(shape=(?, None, 2))
timestep=None should imply the varying size and
2 is for the feature
group. But what about the samples? How do I define the batches?
For the output I’m a bit puzzled how this should look like in this example? I think for each last interaction of a person I would like to have a list of length
3. Assuming I’ve set up the output
model_output = L.LSTM(3, return_sequences=False)
I then want to compile it. Is there a way of using the mean reciprocal rank?
I know the questions are fairly high level, but I would like to understand first the big picture and start to play around. Any help would therefore be appreciated.