我正在尝试训练一个情感分析模型,
我得到以下错误:
Training model with https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-4_H-512_A-8/1
Epoch 1/5
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-118-21a4b57536e8> in <cell line: 2>()
1 print(f'Training model with {tfhub_handle_encoder}')
----> 2 history = classifier_model.fit(x=train_data['clean_text'], y=train_data['sentiment'],
3 validation_data=val_data.empty,
4 epochs=epochs)
1 frames
/usr/local/lib/python3.10/dist-packages/tensorflow/python/eager/polymorphic_function/polymorphic_function.py in _call(self, *args, **kwds)
855 # In this case we have created variables on the first call, so we run the
856 # defunned version which is guaranteed to never create variables.
--> 857 return self._no_variable_creation_fn(*args, **kwds) # pylint: disable=not-callable
858 elif self._variable_creation_fn is not None:
859 # Release the lock early so that multiple threads can perform the call
TypeError: 'NoneType' object is not callable
当调用以下函数时:
print(f'Training model with {tfhub_handle_encoder}')
history = classifier_model.fit(x=train_data['clean_text'], y=train_data['sentiment'],
validation_data=val_data.empty,
epochs=epochs)
我的train_data的形状是(534,2),验证数据是(35,2)
train_data的示例如下所示:
| 纯文本|情绪|
| --|--|
| 真的很喜欢这部电影|2.0|
有人知道出了什么问题吗?似乎无法理解这个错误。奇怪的是,我还需要瓦尔_data上的.empty,否则我会得到
The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
我相信我的输入是不正确的,但我不知道为什么当我打印形状时,模型期望我得到以下结果:
(None,) <dtype: 'string'>
(None, 1) <dtype: 'float32'>
text [(None,)] string
preprocessing None float32
BERT_encoder {'input_mask': (None, 128), 'input_word_ids': (None, 128), 'input_type_ids': (None, 128)} float32
dropout_4 (None, 512) float32
classifier (None, 512) float32
[None, None, None, None, None]
1条答案
按热度按时间hs1rzwqc1#
validation_data
参数要求输入类型为Numpy
阵列的A tuple (x_val, y_val)
或tensors
。NumPy
数组的A tuple
(x_瓦尔,y_瓦尔,瓦尔_sample_weights)。keras.utils.Sequence
返回(inputs, targets)
或(inputs, targets, sample_weights)
。validation_data=(input,target)
input
是您的clean_text
target
是sentiment