【发布时间】:2020-01-22 09:18:39
【问题描述】:
我正在使用 TensorFlow 2.0 进行文本分类。
数据的结构或多或少是这样的:
第一种方法:
x: List[List[int]] # list of sentences consisting of a list of word IDs for each word in the sentence
y: List[int] # binary truth indicator
但是,当调用model.fit(...) 时,我收到以下错误消息:
Failed to find data adapter that can handle input: (<class 'list'> containing values of types {'(<class \'list\'> containing values of types {"<class \'int\'>"})', "(<class 'list'> containing values of types set())"}), <class 'numpy.ndarray'>
尽管没有在任何地方使用set。
第二种方法:
我尝试对内部列表使用 numpy 数组,如下所示:
x: List[np.ndarray[np.int32]]
y: np.ndarray[np.int32]
但我收到以下错误:
Input arrays should have the same number of samples as target arrays. Found 32 input samples and 479 target samples.
第三种方法:
这促使我将数据结构更改为:
x: np.ndarray[np.ndarray[np.int32]]
y: np.ndarray[np.int32]
这导致了以下错误:
Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray).
第四种方法:
尝试,
x: np.ndarray[List[int]]
y: np.ndarray[int]
导致以下类似的错误消息:
Failed to convert a NumPy array to a Tensor (Unsupported object type list).
TLDR;
所以问题是:发生了什么事?为什么model.fit(...) 不接受这些参数?
请看下面我的回答。
【问题讨论】:
标签: python numpy tensorflow tensorflow2.0