首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >深度学习模型: ValueError:带基10:'php‘的int()无效文本

深度学习模型: ValueError:带基10:'php‘的int()无效文本
EN

Stack Overflow用户
提问于 2021-11-25 22:23:07
回答 1查看 394关注 0票数 1

我正在努力深入学习预测标签(c,php,.)堆叠溢出柱。然而,当我试图适应我的模型,我有很多错误的形状,我的训练集。在纠正这些错误后,我收到了一个新的错误,我不知道如何纠正它。如果你能帮我纠正它,因为我是新的深入学习模式,这将是真的很好的你!

我的代码:

代码语言:javascript
复制
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)

X_train:火车 y_train:火车

错误:

代码语言:javascript
复制
---------------------------------------------------------------------------
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'
EN

回答 1

Stack Overflow用户

发布于 2021-12-24 06:32:11

使用LabelEncoder对标签进行编码

代码语言:javascript
复制
from sklearn import preprocessing
labelencode = preprocessing.LabelEncoder()

labelencode.fit(["php", "c#", "c++", "python"])

y_train = labelencode.transform(["python", "php", "python"])

输出

代码语言:javascript
复制
array([3, 2, 3])

还请看一下类似的问题https://stackoverflow.com/a/62760616/14290244

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70117846

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档