【发布时间】:2022-09-22 20:50:14
【问题描述】:
我将以下表格数据存储在数据框df 中:
| input3 | input2 | score |
|---|---|---|
| aaaaaa | xxxxxx | 0.1. |
| ... | ... | ... |
| bbbbbb | yyyyyy | 0.1. |
我想使用 TF 功能 API 建立一个回归模型。由于字符串,我使用嵌入层。这是网络:
input1 = Input(shape=(1,), name=\"input1\")
embedding1 = Embedding(n_input1, 5)(input1)
vec1 = Flatten()(embedding1)
# creating user embedding path
input2 = Input(shape=(1,), name=\"input2\")
embedding2 = Embedding(n_input2, 5)(input2)
vec2 = Flatten()(embedding2)
# concatenate features
conc = Concatenate()([vec1, vec2])
# add fully-connected-layers
fc1 = Dense(256, activation=\'relu\')(conc)
fc2 = Dense(128, activation=\'relu\')(fc1)
fc3 = Dense(128, activation=\'relu\')(fc2)
out = Dense(1)(fc3)
# Create model and compile it
model = Model([input1, input2], out)
model.compile(\'adam\', \'mean_squared_error\')
其中n_input_1 和n_input_2 是每列中唯一项目的数量。
因为,我有 df.dtypes 返回:
input1 object
input2 object
score float64
dtype: object
我做df = data_df.astype({\'input1\': \'string\', \'input2\': \'string\'})——不确定这是否有用
尝试使用以下方法拟合模型时:
history = model.fit([df.input1, df.input2], df.score, epochs=10, verbose=1)
我最终得到以下错误:
UnimplementedError: Graph execution error:
Detected at node \'model/Cast\' defined at (most recent call last):
...
File \"/usr/local/lib/python3.7/dist-packages/keras/engine/functional.py\", line 671, in _conform_to_reference_input
tensor = tf.cast(tensor, dtype=ref_input.dtype)
Node: \'model/Cast\'
2 root error(s) found.
(0) UNIMPLEMENTED: Cast string to float is not supported
[[{{node model/Cast}}]]
(1) CANCELLED: Function was cancelled before it was started
0 successful operations.
0 derived errors ignored. [Op:__inference_train_function_965]
不太确定我在这里错过了什么?
标签: pandas tensorflow embedding