我在这里删除了这段代码:https://sourcedexter.com/tensorflow-text-classification-python/试图预测给定问题是否属于两个类别之一。
但是,我收到以下错误:
无法为Tensor' TargetsData / Y:0'提供形状值(1,1666),其形状为'(?,2)'
以下相关代码:
# 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')
我该如何解决?
答案 0 :(得分:0)
您的 model.fit()应为:
model.fit(train_x, train_y, n_epoch=1000, batch_size=8, show_metric=True)
train_y
,但您已将第二个参数指定为train_x