Open PADMAG6 opened 5 years ago
here i used the keras :2.2.0 python:3.6 backend theano
If I am doing ``` embeddings = predict_green.layers[1].get_weights() for i in range(n_words): print('{}: {}'.format(idx2word[i], embeddings[i]))
i am getting this error IndexError: list index out of range.
here my range is 8, even idx2word, embeddings length also 8. why i am getting this error? how to slove this error?
from keras.layers import Input, Embedding, merge, Flatten, Reshape, Lambda import keras.backend as K from keras.models import Model
input_sentence = Input(shape=(sentence_maxlen,), dtype='int32') input_embedding = Embedding(n_words, n_embed_dims)(input_sentence) avepool = Lambda(lambda x: K.mean(x, axis=1, keepdims=True), output_shape=lambda x: (x[0], 1)) color_prediction = avepool(Reshape((sentence_maxlen * n_embed_dims,))(input_embedding))
predict_green = Model(input=[input_sentence], output=[color_prediction]) predict_green.compile(optimizer='sgd', loss='binary_crossentropy')
predict_green.fit([sentences_array], [is_green], nb_epoch=5000, verbose=0) embeddings = predict_green.layers[1].W.get_value()
for i in range(n_words): print('{}: {}'.format(idx2word[i], embeddings[i]))
while running this code i am getting the following error
AttributeError Traceback (most recent call last)