我正在尝试训练一个用于二元分类的RNN
。我已经从1000000个单词中创建了我的词汇表,请查看下面的输出…
text_field = torchtext.data.Field(tokenize=word_tokenize)
print(text_field.vocab.freqs.most_common(15))>>[('.', 516822), (',', 490533), ('the', 464796), ('to', 298670), ("''", 264416), ('of', 226307), ('I', 224927), ('and', 215722), ('a', 211773), ('is', 180965), ('you', 180359), ('``', 165889), ('that', 156425), ('in', 138038), (':', 132294)]
print(text_field.vocab.itos[:15])>>['<unk>', '<pad>', '.', ',', 'the', 'to', "''", 'of', 'I', 'and', 'a', 'is', 'you', '``', 'that']
text_field.vocab.stoi>>{'<unk>': 0,'<pad>': 1,'.': 2,',': 3,'the': 4,'to': 5,"''": 6,'of': 7,'I': 8,'and': 9,'a': 10, 'is': 11,'you': 12,'``': 13,'that': 14,'in': 15,....................
文档中说明:
freqs – 一个collections.Counter对象,保存用于构建词汇表的tokens在数据中的频率。stoi – 一个collections.defaultdict实例,将token字符串映射到数值标识符。itos – 一个由数值标识符索引的token字符串列表。
我觉得这些解释不够清楚。
能有人解释一下这些是什么意思,并给出每个部分的直观理解吗?
例如,如果the
被表示为4
,那么如果一个句子包含单词the
,
- 位置4会是1吗?还是
- 位置464796会是1吗?还是
- 位置464796会是4吗?
如果有多个the
会发生什么?
回答:
如果”the”被表示为4,那么这意味着
itos[4]
是”the”stoi["the"]
是4- 在
freqs
中某个地方有一个元组('the', <count>)
,其中count
是’the’在你的输入文本中出现的次数。这个计数与其数值标识符4无关。