Я использую TensorFlow 2.0 для классификации текста.
Структура данных выглядит примерно так:
1-й подход:
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
нигде не используется.
2-й подход:
Я попытался использовать массив 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.
3-й подход:
Это побудило меня изменить структуру данных на:
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).
4-й подход:
Trying,
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(...)
не примет эти параметры?
См. Мой ответ ниже.