yoonkim / CNN_sentence

CNNs for sentence classification
2.05k stars 826 forks source link

How could get the value of y_pred? just like, the value of test_set_y #7

Open wyqnumber opened 8 years ago

wyqnumber commented 8 years ago

y_pred = T.argmax(p_y_given_x, axis=1) I want to get y_pred, such as [1, 0, 1, 1...]. It is the value of the classes. I try the function of eval(), but it doesn't work!

Thank you very much!

yoonkim commented 8 years ago

You want to create (and compile) a theano function whose output is y_pred, given the input.

wyqnumber commented 8 years ago

test_set_x = datasets[1][:,:img_h] test_set_y = np.asarray(datasets[1][:,1], "int32")

test_set_yList = test_set_y.tolist()

shareTestX, shareTestY = shared_dataset((test_set_x ,test_set_y))

test_y_pred = classifier.predict(test_layer1_input)

predict_model = theano.function([index], T.mul(test_y_pred,1), givens={x: shareTestX[index:(index+1)]})

predict_value = [test_model(i) for i in xrange(len(test_set_yList))]

print predict_value

But, it is wrong, How to write the code? Thank you!

alex-j-j commented 8 years ago

In case anybody else stumbles over the same problem: define a function predict_val = theano.function([x], test_y_pred, allow_input_downcast=True) and call it wherever you deem it necessary, e.g. in the epoch loop: predictions = predict_val(test_set_x). This seems to output the predictions for test_set_x.