Reputation: 1
Can somebody explain the logic how each inputs are fed into a neural network using python with keras. I am working with text data set so obviously it's a word but how each words are fed into the network as an input? Below is the code:
model = models.Sequential()
model.add(layers.Dense(8, activation='relu', input_shape=(4000,)))
model.add(layers.Dense(8, activation='relu'))
model.add(layers.Dense(1, activation='sigmoid'))
model.compile(optimizer='rmsprop',loss='binary_crossentropy',metrics=['accuracy'])
Upvotes: 0
Views: 44
Reputation: 7369
There are multiple ways to do it. You have to convert each word to a fixed dimensional vector.
There are multiple methods again.
Or you can convert the words to embedding, which may again involve multiple methods:
a. Use a pre-trained embedding
b. Create your own embeddings for the words that are present in your dataset
Then involves, selecting a fixed length of inputs (Say 50 or 100 words)
In the case of simple neural networks, you can just concatenate all the vectors of the words (Fixed length of course) and feed it at the input layer of your neural network.
Upvotes: 1