brightmart / text_classification

all kinds of text classification models and more with deep learning
MIT License
7.83k stars 2.57k forks source link

single label classification #77

Closed lreaderl closed 6 years ago

lreaderl commented 6 years ago

ValueError: Cannot feed value of shape (64, 19) for Tensor 'input_y:0', which has shape '(?,)' In textCNN, input_y is defined as [None,]. However, when feed it at train.py(feed_dict[textCNN.input_y] = trainY[start:end]), there is a problem occurred as below.

lreaderl commented 6 years ago

Specifically, in p7_TextCNN_train.py, line88: feed_dict[textCNN.input_y] = trainY[start:end] It wouldn't work, anyway.

lreaderl commented 6 years ago

I solved by using get_target_label_short function.

chencjiajy commented 6 years ago

I met it too, how you using get_target_label_short function? thanks @lreaderl

lreaderl commented 6 years ago

trainY = [] for it in trainY[start:end]: trainY.append(int(get_target_labelshort1(it))) trainY = np.array(trainY_,dtype=np.int32).flatten() feed_dict[textCNN.inputy] = trainY

get_target_label_short1() returns index

echolijinghui commented 5 years ago

when using "tf.nn.sparse_softmax_cross_entropy_with_logits()",the length of “logits“ needs to be one dimensional more than ”labels“, you can modify this:

losses = tf.nn.sparse_softmax_cross_entropy_with_logits(labels=self.input_y, logits=self.logits)

to : losses = tf.nn.sparse_softmax_cross_entropy_with_logits(labels=tf.argmax(self.input_y, 1), logits=self.logits)