【发布时间】:2020-08-18 17:54:45
【问题描述】:
我正在尝试使用以下命令将我的 pandas 数据帧 (df) 加载到 Tensorflow 数据集中:
target = df['label']
features = df['encoded_sentence']
dataset = tf.data.Dataset.from_tensor_slices((features.values, target.values))
这是我的 pandas 数据框的摘录:
+-------+-----------------------+------------------+
| label | sentence | encoded_sentence |
+-------+-----------------------+------------------+
| 0 | Hello world | [5, 7] |
+-------+-----------------------+------------------+
| 1 | my name is john smith | [1, 9, 10, 2, 6] |
+-------+-----------------------+------------------+
| 1 | Hello! My name is | [5, 3, 9, 10] |
+-------+-----------------------+------------------+
| 0 | foo baar | [8, 4] |
+-------+-----------------------+------------------+
# df.dtypes gives me:
label int8
sentence object
encoded_sentencee object
但它总是给我一个值错误:
ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type list).
谁能告诉我如何在我的 Tensorflow 数据集中使用编码句子?非常感谢您的帮助!
【问题讨论】:
标签: pandas numpy tensorflow