我正在努力深入学习预测标签(c,php,.)堆叠溢出柱。然而,当我试图适应我的模型,我有很多错误的形状,我的训练集。在纠正这些错误后,我收到了一个新的错误,我不知道如何纠正它。如果你能帮我纠正它,因为我是新的深入学习模式,这将是真的很好的你!
我的代码:
model = Sequential()
model.add(Dense(16,activation='relu',input_shape = (384,))) #hidden
model.add(Dense(len(data.tag_name.unique()),activation='sigmoid')) #output
model.compile(optimizer='SGD',loss='binary_crossentropy',metrics=['accuracy'])
model.fit(np.array(list_embedding),tf.one_hot(np.array(data.tag_name).reshape([2686,1]),depth=len(data.tag_name.unique())),validation_data=0.3,epochs=20)错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-20-3fddbbfa9112> in <module>
10
11 model.compile(optimizer='SGD',loss='binary_crossentropy',metrics=['accuracy'])
---> 12 model.fit(np.array(list_embedding),tf.one_hot(np.array(data.tag_name).reshape([2686,1]),depth=len(data.tag_name.unique())),validation_data=0.3,epochs=20) #reshape y one hot encoding dummies
/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/util/dispatch.py in wrapper(*args, **kwargs)
204 """Call target, and fall back on dispatchers if there is a TypeError."""
205 try:
--> 206 return target(*args, **kwargs)
207 except (TypeError, ValueError):
208 # Note: convert_to_eager_tensor currently raises a ValueError, not a
/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/ops/array_ops.py in one_hot(indices, depth, on_value, off_value, axis, dtype, name)
4347 "dtype {1} of off_value".format(on_dtype, off_dtype))
4348
-> 4349 return gen_array_ops.one_hot(indices, depth, on_value, off_value, axis,
4350 name)
4351
/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/ops/gen_array_ops.py in one_hot(indices, depth, on_value, off_value, axis, name)
6232 if tld.is_eager:
6233 try:
-> 6234 _result = pywrap_tfe.TFE_Py_FastPathExecute(
6235 _ctx, "OneHot", name, indices, depth, on_value, off_value, "axis",
6236 axis)
ValueError: invalid literal for int() with base 10: 'php'发布于 2021-12-24 06:32:11
使用LabelEncoder对标签进行编码
from sklearn import preprocessing
labelencode = preprocessing.LabelEncoder()
labelencode.fit(["php", "c#", "c++", "python"])
y_train = labelencode.transform(["python", "php", "python"])输出
array([3, 2, 3])https://stackoverflow.com/questions/70117846
复制相似问题