How to encode categorical data that have variable length so could be fetched to nn.Embedding in PyTorch
Let's say i have a data field named movie_genre for each sample movie, it is selected from the following genres:

Action
Adventure
Animation
Comedy
...


And for each movie, it might contain multiple genres:

mid    genres
1      Action | Adventure
2      Animation
3      Comedy | Adventure | Action


which means, the movie's genres is a variable list.

If i use one hot vector to encode the genre, Action can be encoded as (1, 0, 0, 0), Adventure can be encoded as(0, 1, 0, 0), and so on.

So movie with mid1 can be encoded as (1, 1, 0, 0), mid2's genre can be encoded as (0, 0, 1, 0), and so on.

However, the pytorch embedding layer nn.Embedding takes tensor containing the indices as input, but not one-hot vector. So how should i encode the data so that it can be fetched into the embedding layer?

At the moment I can think of two way to proceed : 


Transform your multilabel problem to a multicategorical problem. That is to say for each combination of label create a new label (For example Action | Adventure become its own label), then embed those new labels as usual.
Embed separately each category and sums the embedding of all the category appearing in your list.


Edit : You can use pytorch nn.EmbeddingBag to perform the second operation in an efficient manner : https://pytorch.org/docs/stable/nn.html?highlight=nn%20e#torch.nn.EmbeddingBag
