python - Simple NN model for next word prediction -


i tried made simple model of neural networks model make next word prediction.

i have list of phrases , split list of phrases in list of 3 words. e.g.

input:

1. phrase number one. 2. phrase number two. 

result:

1. phrase 2. phrase number 3. phrase number 1 ... n. phrase number 2 

and me x values. y values put 4-th word every phrase. e.g.

x[1]: phrase y[1]: number ... x[n]: phrase number y[n]: 2 

and, in encode x , y value of 0 , 1. e.g.

x[0]: 0 0 0 ... 1 0 1 0 ... 1 - maximum 3 of '1' y[0]: 0 0 0 ... 1 0 0 0 ... 0 - maximum 1 of '1' 

where 1 in every vectors represent position of word in vocabulary.

and data. i'm not sure if best way embedding. exist way more better?

next, model this:

model = sequential() model.add(dense(12, input_dim=len(x_train[0]), kernel_initializer='uniform', activation='relu')) model.add(dense(8, input_dim=len(x_train[0]), kernel_initializer='uniform', activation ='relu')) model.add(dense(len(x_train[0]), input_dim=len(x_train[0]), kernel_initializer='uniform', activation ='sigmoid'))  # compile model model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])  # fit model model.fit(x_train, y_train, epochs=10, batch_size=10, verbose=1) 

but when want make prediction recived every time same next word.

recover code next word prediction:

    y_pred = model.predict(x_test)     in range(0, len(x_test)):     current_sentence = []     pred_word = []     j in range(0, len(x_test[i])):         if x_test[i][j] == 1:             current_sentence.append(vocabulary[j])      pred_word.append(vocabulary[list(y_pred[i]).index(max(y_pred[i]))])      print("---------------\n")     print("current sentence: ", current_sentence)     print("next word prediction: ", pred_word) 


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -