bojone / bert4keras

keras implement of transformers for humans
https://kexue.fm/archives/6915
Apache License 2.0
5.37k stars 929 forks source link

运行task_sentence_similarity_lcqmc.py,报错'data_generator' object has no attribute 'sample' #367

Open gaolizhao opened 3 years ago

gaolizhao commented 3 years ago

基本信息

核心代码

train_lcqmc_cls.py 等于 task_sentence_similarity_lcqmc.py

python3 train_lcqmc_cls.py

输出信息

File "train_lcqmc_cls.py", line 158, in main() File "train_lcqmc_cls.py", line 147, in main callbacks=[evaluator] File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py", line 66, in _method_wrapper return method(self, *args, **kwargs) File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py", line 815, in fit model=self) File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/data_adapter.py", line 1112, in init model=model) File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/data_adapter.py", line 772, in init peek, x = self._peek_and_restore(x) File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/data_adapter.py", line 830, in _peek_and_restore peek = next(x) File "/usr/local/lib/python3.6/dist-packages/bert4keras/snippets.py", line 250, in forfit for d in self.iter(True): File "train_lcqmc_cls.py", line 56, in iter for is_end, (text1, text2, label) in self.sample(random): AttributeError: 'data_generator' object has no attribute 'sample'

自我尝试

之前是tf=2.3.1报如上错误,切换到建议版本后,还是报错。tf.keras和keras都会报这个错误。

找个另外的电脑升级到tf=2.4+,然后使用tf.keras可以解决,但是目前物理GPU集群仅支持tf=2.3.1以下,因此还需要解决这个问题。

i4never commented 3 years ago

这个tf/keras有什么关系吗

bojone commented 3 years ago

升级bert4keras