Liuchiang
Liuchiang

Reputation: 1

How inputs are being taken in keras?

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

Answers (1)

Ashwin Geet D'Sa
Ashwin Geet D'Sa

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.

  1. As a basic method, you can use 'one-hot-vector'
  2. 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

  3. Then involves, selecting a fixed length of inputs (Say 50 or 100 words)

  4. 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

Related Questions