我正在阅读存储在我的数据库中的文本文件,它们都有不同的大小。当我运行我的代码时,它突然停止并给出这个错误。在任何地方都找不到任何相关的答案。我尝试更改 max_seq_embeddings 但仍然无法正常工作。一旦我遇到长度为 3619 的文件,它就会引发错误。
YES <class 'str'> 1814
YES <class 'str'> 1334
YES <class 'str'> 3619
Traceback (most recent call last):
File "C:/Users/DeLL/PycharmProjects/Phase1/venv/src/Main.py", line 24, in <module>
output = model.predict(data.text)
File "C:\Users\DeLL\PycharmProjects\Phase1\venv\src\bert.py", line 77, in predict
logits = self.model(input_ids, segment_ids, input_mask,valid_ids)
File "C:\Users\DeLL\PycharmProjects\Phase1\venv\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py", line 891, in __call__
outputs = self.call(cast_inputs, *args, **kwargs)
File "C:\Users\DeLL\PycharmProjects\Phase1\venv\src\model.py", line 55, in call
sequence_output = self.bert([input_word_ids, input_mask, input_type_ids],**kwargs)
File "C:\Users\DeLL\PycharmProjects\Phase1\venv\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py", line 891, in __call__
outputs = self.call(cast_inputs, *args, **kwargs)
File "C:\Users\DeLL\PycharmProjects\Phase1\venv\lib\site-packages\tensorflow_core\python\keras\engine\network.py", line 708, in call
convert_kwargs_to_constants=base_layer_utils.call_context().saving)
File "C:\Users\DeLL\PycharmProjects\Phase1\venv\lib\site-packages\tensorflow_core\python\keras\engine\network.py", line 860, in _run_internal_graph
output_tensors = layer(computed_tensors, **kwargs)
File "C:\Users\DeLL\PycharmProjects\Phase1\venv\src\bert_modeling.py", line 197, in __call__
return super(BertModel, self).__call__(inputs, **kwargs)
File "C:\Users\DeLL\PycharmProjects\Phase1\venv\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py", line 891, in __call__
outputs = self.call(cast_inputs, *args, **kwargs)
File "C:\Users\DeLL\PycharmProjects\Phase1\venv\src\bert_modeling.py", line 217, in call
word_embeddings=word_embeddings, token_type_ids=input_type_ids)
File "C:\Users\DeLL\PycharmProjects\Phase1\venv\src\bert_modeling.py", line 329, in __call__
return super(EmbeddingPostprocessor, self).__call__(inputs, **kwargs)
File "C:\Users\DeLL\PycharmProjects\Phase1\venv\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py", line 891, in __call__
outputs = self.call(cast_inputs, *args, **kwargs)
File "C:\Users\DeLL\PycharmProjects\Phase1\venv\src\bert_modeling.py", line 355, in call
tf.slice(self.position_embeddings, [0, 0], [seq_length, width]),
File "C:\Users\DeLL\PycharmProjects\Phase1\venv\lib\site-packages\tensorflow_core\python\ops\array_ops.py", line 866, in slice
return gen_array_ops._slice(input_, begin, size, name=name)
File "C:\Users\DeLL\PycharmProjects\Phase1\venv\lib\site-packages\tensorflow_core\python\ops\gen_array_ops.py", line 9212, in _slice
input, begin, size, name=name, ctx=_ctx)
File "C:\Users\DeLL\PycharmProjects\Phase1\venv\lib\site-packages\tensorflow_core\python\ops\gen_array_ops.py", line 9251, in _slice_eager_fallback
ctx=_ctx, name=name)
File "C:\Users\DeLL\PycharmProjects\Phase1\venv\lib\site-packages\tensorflow_core\python\eager\execute.py", line 67, in quick_execute
six.raise_from(core._status_to_exception(e.code, message), None)
File "<string>", line 3, in raise_from
tensorflow.python.framework.errors_impl.InvalidArgumentError: Expected size[0] in [0, 512], but got 891 [Op:Slice]
Process finished with exit code 1
这是所有使用的文件的链接。 https://github.com/kamalkraj/BERT-NER-TF