TorchText Vocab TypeError:Vocab.__init__() 得到了意外的关键字参数“min_freq”;
我正在研究 CNN 情感分析机器学习模型,该模型使用 Torchtext 库提供的 IMDb 数据集。 在我的一行代码中
vocab = Vocab(counter, min_freq = 1,specials=('\
尽管我确信 min_freq 参数是可接受的参数之一,但我收到了 TypeError 功能。我还收到 UserWarning Pickle 不支持 Lambda 函数,请使用常规 python 函数或 functools 部分代替。完整代码
from torchtext.datasets import IMDB
from collections import Counter
from torchtext.data.utils import get_tokenizer
from torchtext.vocab import Vocab
tokenizer = get_tokenizer('basic_english')
train_iter = IMDB(split='train')
test_iter = IMDB(split='test')
counter = Counter()
for (label, line) in train_iter:
counter.update(tokenizer(line))
vocab = Vocab(counter, min_freq = 1, specials=('\<unk\>', '\<BOS\>', '\<EOS\>', '\<PAD\>'))
源码链接 走向数据科学 github Legacy to new
我尝试删除 min_freq 参数并使用默认函数,如下
vocab = Vocab(counter,specials=('\
然而,我最终得到了相同的类型错误,但对于特殊参数而不是 min_freq。
任何帮助将不胜感激,
谢谢。
I am working on a CNN Sentiment analysis machine learning model which uses the IMDb dataset provided by the Torchtext library.
On one of my lines of code
vocab = Vocab(counter, min_freq = 1, specials=('\<unk\>', '\<BOS\>', '\<EOS\>', '\<PAD\>'))
I am getting a TypeError for the min_freq argument even though I am certain that it is one of the accepted arguments for the function. I am also getting UserWarning Lambda function is not supported for pickle, please use regular python function or functools partial instead. Full code
from torchtext.datasets import IMDB
from collections import Counter
from torchtext.data.utils import get_tokenizer
from torchtext.vocab import Vocab
tokenizer = get_tokenizer('basic_english')
train_iter = IMDB(split='train')
test_iter = IMDB(split='test')
counter = Counter()
for (label, line) in train_iter:
counter.update(tokenizer(line))
vocab = Vocab(counter, min_freq = 1, specials=('\<unk\>', '\<BOS\>', '\<EOS\>', '\<PAD\>'))
Source Links
towardsdatascience
github Legacy to new
I have tried removing the min_freq argument and use the functions default as follows
vocab = Vocab(counter, specials=('\<unk\>', '\<BOS\>', '\<EOS\>', '\<PAD\>'))
however I end up getting the same type error but for the specials argument rather than min_freq.
Any help will be much appreciated
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
AS https://github.com/pytorch/pytorch/text/text/issues/1445 应该将“词汇”更改为“词汇”。我认为他们错过了旧版笔记本。
正确的代码:
我的环境:
As https://github.com/pytorch/text/issues/1445 mentioned, you should change "Vocab" to "vocab". I think they miss-type the legacy-to-new notebook.
correct code:
my environment:
您可以尝试使用torchtext.legacy.vocab而不是可以解决问题的Vocab。这对我有用:
You can try torchtext.legacy.vocab instead of torchtext.vocab which might solve the issue. This worked for me:
抱歉,这对我不起作用。 :(
词汇是对象的正确名称,词汇不是。
我发现的简单解决方案是:从实验词汇中除去了“特殊”元组,并且不再使用!就这样。
https://github.com/pytorch/pytorch/text/text/sissues/890
我的环境:我的环境:
Sorry, it doesn't work for me. :(
Vocab is correct name of object and vocab is not.
Simply solution I found is: that "specials" tuple was removed from experimental Vocab and in no more in use! That's all.
https://github.com/pytorch/text/issues/890
my environment: