【问题标题】:How can i make my model take string inputs我怎样才能让我的模型接受字符串输入
【发布时间】:2020-01-29 20:23:03
【问题描述】:

我收到错误 2020-01-29 12:49:54.219205: W tensorflow/core/framework/op_kernel.cc:1632] OP_REQUIRES 在 cast_op.cc:123 失败:未实现:不支持将字符串转换为浮点数 2020 -01-29 12:49:54.219705: E tensorflow/core/common_runtime/executor.cc:

我考虑过将字符串转换为整数,只是它们在 alffbhet 中的位置会起作用,还是有更好的方法在 keras 中输入字符串? 这是我的代码

import tensorflow as tf
model = tf.keras.models.Sequential()
word = [['ja'],['ske'],['no'],['fork']]
language = [['dansk'],['dansk'],['engelsk'],['engelsk']]


tf.keras.layers.Flatten()
model.add(tf.keras.layers.Dense(128, activation = tf.nn.relu))
model.add(tf.keras.layers.Dense(128, activation = tf.nn.relu))
model.add(tf.keras.layers.Dense(128, activation = tf.nn.relu))
model.add(tf.keras.layers.Dense(2, activation = tf.nn.softmax))

model.compile(optimizer='adam',
                  loss='sparse_categorical_crossentropy', #mean_absolute_percentage_error
                  metrics=['accuracy'])
model.fit(word,language, epochs = 100)

【问题讨论】:

  • 好吧,你不能。

标签: tensorflow keras sequential


【解决方案1】:

很遗憾,你不能。机器学习模型不理解单词,它们理解数字。基本上就是数学,一切都要转化成数字来计算。

您必须将模型输入转换为有意义的数字。这可以使用one Hot encoding 等技术来完成。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多