【发布时间】:2018-01-11 18:44:52
【问题描述】:
我在此处添加了此代码:https://sourcedexter.com/tensorflow-text-classification-python/,以尝试预测给定问题是否属于两个类别之一。
但是,我收到以下错误:
无法为形状为“(?, 2)”的张量“TargetsData/Y:0”提供形状 (1, 1666) 的值
相关代码如下:
# train_x contains the Bag of words and train_y contains the label/ category
train_x = list(training[:,0])
train_y = list(training[:,1])
#reset underlying graph data
tf.reset_default_graph()
#Build neural network
net = tflearn.input_data(shape=[None,len(train_x[0])])
#layer?
net = tflearn.fully_connected(net,8)
#layer?
net = tflearn.fully_connected(net,8)
#output layer
net = tflearn.fully_connected(net, len(train_y[0]),activation='softmax')
net = tflearn.regression(net)
#define model and set up tensorboard
model = tflearn.DNN(net, tensorboard_dir = 'tflearn_logs')
#start training (grad descent algo)
model.fit(train_x, train_x, n_epoch = 1000, batch_size=1, show_metric = True)
model.save('model.tflearn')
我该如何解决?
【问题讨论】:
标签: python tensorflow text-classification