DistilBERT,少于 512 个代币,Colab 崩溃
我正在遵循本指南 https ://jalammar.github.io/a-visual-guide-to-using-bert-for-the-first-time/ ,我的文本观察平均包含少于 250-300 个单词,所以我不没有 512 个令牌在任何文本行中。
但与这个问题类似: Fluctuating RAM in google colab while运行 BERT 模型 我必须将 max_length
限制为小于 100,否则 Google Colab 会崩溃。
我看到了应用基于 BERT 的变压器和使用 Pytorch DataLoader 批量加载数据的其他示例,但不知道如何在这个示例中实现它。
I'm following this guide https://jalammar.github.io/a-visual-guide-to-using-bert-for-the-first-time/ and my text observations contain less than 250-300 words on average, so I don't have 512 tokens in any text row.
But similar to this question: Fluctuating RAM in google colab while running a BERT model I have to limit max_length
to less than 100, because otherwise Google Colab crashes.
I see other examples of applying BERT-based transformers and using Pytorch DataLoader
to load data in batches but can't figure out how to implement it in this example.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如您所说的正确,您在教程中显示的似乎没有使用批处理,因此整个数据都会批量传递给模型,这对于 colab 允许您使用的资源来说可能太多了。
如果您只是想让它工作,您可以尝试限制数据中的行数,类似于本教程的做法(在本例中为 2000):
https://www.kaggle.com/rahulvks/distilbert-text-classification
或者,更好的是,使用数据加载器,然后以类似于本教程的方式迭代它们:https://seekinginference.com/applied_nlp/distilbert.html
一般来说,在 Colab 中使用 Transformer 模型时,您应该确保激活 GPU 使用(编辑 -> 笔记本设置),因为这让您可以免费使用一些相当不错的 GPU,并极大地提高训练速度。
As you said correctly it seems like in the tutorial you show there is no batching used, so the entire data is handed to the model in one batch which might be too much for the ressources colab allows you to use.
If you just want to get it to work you can try to limit the number of rows in the data it similarily to how this tutorial did it (in this case 2000):
https://www.kaggle.com/rahulvks/distilbert-text-classification
Or, even better, use dataloaders and then iterate over them similarily to how this tutorial does it: https://seekinginference.com/applied_nlp/distilbert.html
Generally when working with transformer models in Colab you should make sure to activate GPU usage (Edit -> Notebook Settings) since this gives you access to some pretty nice GPUs for free and drastically improves training speed.