1

First of all I am new to Keras and ML.

I am trying https://github.com/fchollet/keras/blob/master/examples/pretrained_word_embeddings.py example.

I saved the trained model using model.save(). Now I am writing a script to predict using another script:

model = load_model('./model.h5')

tokenizer = Tokenizer(num_words=MAX_NB_WORDS)
text = np.array(['some unseen text'])
tokenizer.fit_on_texts(text)
sequences = tokenizer.texts_to_sequences(text)
data = pad_sequences(sequences, maxlen=MAX_SEQUENCE_LENGTH)

prediction = model.predict(np.array(data))

The above returns something like: [[ 1.00000000e+00 2.66153551e-18 1.67506186e-15 1.33851482e-16 2.85387820e-16 3.06079675e-15 1.34407281e-14 1.38863788e-15 4.20352726e-16 1.28687439e-15 1.52688925e-16]]

I would like to get the label names given in the training. Any idea how I can do this?

Thanks

HJ.
  • 185
  • 1
  • 2
  • 10
  • Do you have access to the original labels? – cs95 Oct 16 '17 at 06:09
  • Yes I do. The resulted list has 11 elements, I have 11 labels. But I am not sure how to relate the label names with the result. I cannot see a relationship. – HJ. Oct 16 '17 at 06:19
  • 2
    `np.array(labels)[prediction.argmax(axis=1)]` Is this what you want? – cs95 Oct 16 '17 at 06:21
  • You might want to get the labels from the classifier, in the order the classifier learned them. – cs95 Oct 16 '17 at 06:21
  • 1
    Thanks for your quick response. I am not sure what I need! How do I get the labels from the classifier? I tried np.array(labels), but it is always returning the first label. – HJ. Oct 16 '17 at 06:29

0 Answers0