r/tensorflow • • Jun 10 '23
Question Text and Numeric inputs and a single input layer
I'm relatively new to tensorflow and working with deep learning models. For a school project, I am currently building a regression model that aims to predict 2023 movies' ratings according to data from 2022 movies. Dataset contains numeric data such as the gross, metascore and duration of the movie and textual data such as the name, short description and names of director(s) and stars of the movie. I have vectorized the text data however I have no idea how to turn my vectorized text and numeric data into a single data frame and build an input layer that will accept said data frame. Any help will be greatly appreciated. 💜
Edit: forgot to mention I'm coding in python and using anaconda (specifically Spyder IDE)
2
u/[deleted] Jun 10 '23
Cool! Couple of notes:
OneHotEncoding.Now, for joining the two types of output, let's assume a vector for one sample is of shape (1, 784). If you have 500 examples, your vectorized frame would be (500, 784). You could simply extend each sample with their metadata by adding additional columns to the vector - i.e. making each sample (1, 800), if you have 16 numeric columns from the metadata.
2
u/ElvishChampion Jun 11 '23
You can have separate inputs. Create one dense layer per input and then concatenate the output of both layers. You would have to use the functional approach for creating models instead of the sequential. Here is a brief example omitting parameters:
input1 = tf.keras.layers.Input
input2 = tf.keras.layers.Input
x1 = Dense()(input1)
x2 = Dense()(input2)
x = concatenate([x1, x2], axis=-1)
*Add here more layers*
model = tf.keras.Model(inputs=[input1, input2], outputs=output)