To start, let me just say that I am very new to tensorflow and Machine Learning in general. But, as part of my learning project I am trying to adapt the tensorflow wide and deep model to generate movie recommendations. However, the part I'm getting stuck on is handling multiple values for a categorical column. Below is a sample of how a couple of rows in my CSV look like.


The Genres and Tags column have multiple categorical values. I have looked at tf.string_split to parse the strings and return a SparseTensor.

Once I have parsed my delimited string values into SparseTensor, what do I do with? If I want to create categorical_column_with_vocabulary_file, how does the SparseTensor interact with it? Is that even the correct step? Should the SparseTensor be converted into a something before I can create a categorical_column_*?

I am just not sure how to train the Wide and Deep model when you have multiple categorical values for a single column. Some people have suggested that I use each 'Genre' as its own column and encode it using One-Hot, but it is not realistic for me to do this, because there could be 100s of genres and tags in the data.

Any help on this matter would be welcome. Thank you!!

  • $\begingroup$ Programming issues are off-topic here. Please, read ai.stackexchange.com/help/on-topic for more details and to understand which questions are on-topic here. If you have a programming issue, the best place to ask your question is Stack Overflow. $\endgroup$
    – nbro
    Jun 2 '20 at 23:43

I am also stuck with this problem and after some searchs I end up here.

Maybe you can take a look at indicator column. I think embedding column behaves in a similar way.

  • $\begingroup$ I ended up using the following way to read them into tensorflow: df_dataset = read_csv(file=input_file) df_dataset = df_dataset.fillna(value='') And then for my Categorical for col in _CATEGORICAL_COLUMNS: df_dataset[col] = df_dataset[col].str.split(pat=':').astype('|S') From there I just used categorical_column_with_vocabulary_file $\endgroup$ Jul 31 '18 at 17:27

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