def test(self, sentence, model, words):
"""
test only a sentence
:param sentence: a sentence, if ischar==False, the sentence should be segmented
:param model: cnn model
:param words: words list
:return:
"""
if self.ischar is True:
sentence = list(sentence)
else:
sentence = sentence.split()
x_test = [[words[w] for w in sentence if words.has_key(w)]]
x_test = sequence.pad_sequences(x_test, maxlen=self.maxlen)
pred_y = model.predict(x_test)
return pred_y
评论列表
文章目录