Git Product home page Git Product logo

Comments (6)

zllearn avatar zllearn commented on June 12, 2024 1

我今天也出现了这种错误,最后我把所有的输出形状都打印了出来,发现最后一个batch_size的大小为1,所以导致了这种错误,只要把dataloader的drop_last设置为True,就能正常运行了

from pytorch_bert_bilstm_crf_ner.

iamshujie avatar iamshujie commented on June 12, 2024
> E:\env\py7\lib\site-packages\transformers\optimization.py:309: FutureWarning: This implementation of AdamW is deprecated and will be removed in a future version. Use thePyTorch implementation torch.optim.AdamW instead, or set `no_deprecation_warning=True` to disable this warning
>   `FutureWarning,`
> Traceback (most recent call last):
>   File "F:/pytorch_bert_bilstm_crf_ner-main/pytorch_bert_bilstm_crf_ner-main/main.py", line 214, in <module>
>     bertForNer.train()
>   File "F:/pytorch_bert_bilstm_crf_ner-main/pytorch_bert_bilstm_crf_ner-main/main.py", line 46, in train
>     torch.nn.utils.clip_grad_norm_(self.model.parameters(), self.args.max_grad_norm)
>   File "E:\env\py7\lib\site-packages\torch\nn\utils\clip_grad.py", line 31, in clip_grad_norm_
>     total_norm = torch.norm(torch.stack([torch.norm(p.grad.detach(), norm_type) for p in parameters]), norm_type)
> RuntimeError: stack expects a non-empty TensorList

> 

这是我运行出来的错误

from pytorch_bert_bilstm_crf_ner.

taishan1994 avatar taishan1994 commented on June 12, 2024
> E:\env\py7\lib\site-packages\transformers\optimization.py:309: FutureWarning: This implementation of AdamW is deprecated and will be removed in a future version. Use thePyTorch implementation torch.optim.AdamW instead, or set `no_deprecation_warning=True` to disable this warning
>   `FutureWarning,`
> Traceback (most recent call last):
>   File "F:/pytorch_bert_bilstm_crf_ner-main/pytorch_bert_bilstm_crf_ner-main/main.py", line 214, in <module>
>     bertForNer.train()
>   File "F:/pytorch_bert_bilstm_crf_ner-main/pytorch_bert_bilstm_crf_ner-main/main.py", line 46, in train
>     torch.nn.utils.clip_grad_norm_(self.model.parameters(), self.args.max_grad_norm)
>   File "E:\env\py7\lib\site-packages\torch\nn\utils\clip_grad.py", line 31, in clip_grad_norm_
>     total_norm = torch.norm(torch.stack([torch.norm(p.grad.detach(), norm_type) for p in parameters]), norm_type)
> RuntimeError: stack expects a non-empty TensorList

> 

这是我运行出来的错误

你把训练注释掉之前是否已经训练好模型了,然后也正确加载了模型。

from pytorch_bert_bilstm_crf_ner.

iamshujie avatar iamshujie commented on June 12, 2024

不知道我理解的对不对,您是指最后在final_data里生成pkl文件吗,这个我已经生成。程序中的read_pkl也能够读取。训练的模型不应该是经过bertForNer.train()才能生成吗?

from pytorch_bert_bilstm_crf_ner.

taishan1994 avatar taishan1994 commented on June 12, 2024

不知道我理解的对不对,您是指最后在final_data里生成pkl文件吗,这个我已经生成。程序中的read_pkl也能够读取。训练的模型不应该是经过bertForNer.train()才能生成吗?

可以预先处理,也可以在训练中生成,先生成pkl是为了避免每次都要重新处理耗时

from pytorch_bert_bilstm_crf_ner.

iamshujie avatar iamshujie commented on June 12, 2024

十分感谢,您说办法很有效,batch_size的大小对于能否成功运行很重要

from pytorch_bert_bilstm_crf_ner.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.