Paddle 文本分类训练demo出错:win10/cuda10.2/paddle2.0rc1:paddlehub/demo/text_classification/train.py 源代码无法使用,paddlepaddle报错

cdmah0mi  于 2021-12-07  发布在  Java
关注(0)|答案(3)|浏览(263)
  • 版本、环境信息:

   1)PaddleHub和PaddlePaddle版本:PaddlePaddle2.0.0rc1, paddlehub==2.0.0b
   2)CPU:i7 9750H
   3)GPU:GTX1650 CUDA10.2
   4)系统环境:Windows10,python3.7

  • 训练信息

   1)单机单卡
   2)显存信息:4G
   3)Operator信息

  • 复现信息:源代码:

import paddle
import paddlehub as hub

ifname== 'main':
model = hub.Module(name='ernie_tiny', version='2.0.0', task='sequence_classification')

train_dataset = hub.datasets.ChnSentiCorp(
    tokenizer=model.get_tokenizer(tokenize_chinese_chars=True), max_seq_len=128, mode='train')
dev_dataset = hub.datasets.ChnSentiCorp(
    tokenizer=model.get_tokenizer(tokenize_chinese_chars=True), max_seq_len=128, mode='dev')
test_dataset = hub.datasets.ChnSentiCorp(
    tokenizer=model.get_tokenizer(tokenize_chinese_chars=True), max_seq_len=128, mode='test')

optimizer = paddle.optimizer.AdamW(learning_rate=5e-5, parameters=model.parameters())
trainer = hub.Trainer(model, optimizer, checkpoint_dir='test_ernie_text_cls', use_gpu=True)

trainer.train(train_dataset, epochs=3, batch_size=32, eval_dataset=dev_dataset, save_interval=1)
trainer.evaluate(test_dataset, batch_size=32)
  • 问题描述:

Traceback (most recent call last):
File ".\测试.py", line 30, in
trainer.train(train_dataset, epochs=3, batch_size=32, eval_dataset=dev_dataset, save_interval=1)
File "D:\conda\envs\work_hub2\lib\site-packages\paddlehub\finetune\trainer.py", line 199, in train
loss, metrics = self.training_step(batch, batch_idx)
File "D:\conda\envs\work_hub2\lib\site-packages\paddlehub\finetune\trainer.py", line 336, in training_step
result = self.model.training_step(batch, batch_idx)
File "C:\Users\zkj.paddlehub\modules\ernie_tiny\module.py", line 122, in training_step
predictions, avg_loss, acc = self(input_ids=batch[0], token_type_ids=batch[1], labels=batch[2])
File "D:\conda\envs\work_hub2\lib\site-packages\paddle\fluid\dygraph\layers.py", line 884, incall
outputs = self.forward(inputs,kwargs)
File "C:\Users\zkj.paddlehub\modules\ernie_tiny\module.py", line 72, in forward
loss = self.criterion(logits, labels)
File "D:\conda\envs\work_hub2\lib\site-packages\paddle\fluid\dygraph\layers.py", line 884, in
call
*
outputs = self.forward(*inputs,**kwargs)
File "D:\conda\envs\work_hub2\lib\site-packages\paddle\nn\layer\loss.py", line 249, in forward
name=self.name)
File "D:\conda\envs\work_hub2\lib\site-packages\paddle\nn\functional\loss.py", line 1220, in cross_entropy
axis=axis)
File "D:\conda\envs\work_hub2\lib\site-packages\paddle\fluid\layers\loss.py", line 1264, in softmax_with_cross_entropy
axis)
ValueError: (InvalidArgument) Tensor holds the wrong type, it holds int, but desires to be int64_t.
[Hint: Expected valid == true, but received valid:0 != true:1.] (at D:\2.0.0rc1\paddle\paddle/fluid/framework/tensor_impl.h:33)
[Hint: If you need C++ stacktraces for debugging, please set FLAGS_call_stack_level=2.]
[operator < softmax_with_cross_entropy > error]

计算loss时因为数据格式报错,不知怎么处理

bxfogqkk

bxfogqkk1#

您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看官网API文档常见问题历史IssueAI社区来寻求解答。祝您生活愉快~

Hi! We've received your issue and please be patient to get responded. We will arrange technicians to answer your questions as soon as possible. Please make sure that you have posted enough message to demo your request. You may also check out the APIFAQGithub Issue and AI community to get the answer.Have a nice day!

s1ag04yj

s1ag04yj2#

ValueError: (InvalidArgument) Tensor holds the wrong type, it holds int, but desires to be int64_t.
[Hint: Expected valid == true, but received valid:0 != true:1.] (at D:\2.0.0rc1\paddle\paddle/fluid/framework/tensor_impl.h:33)
[Hint: If you need C++ stacktraces for debugging, please set FLAGS_call_stack_level=2.]
[operator < softmax_with_cross_entropy > error]

相关问题