知识卡片
词表编号需确定且随模型保存
list(set(tokens))产生的顺序不宜当稳定词表,重跑环境可能改变编号。应采用确定顺序或保存完整tok2id与id2tok,并核对互逆;嵌入矩阵一行只与当时编号匹配,换词表后不能直接复用参数。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
- · 用词嵌入推理
原书出处 · 1 处
- · 查看原书依据
You’ll need to compute the vocabulary for your dataset to handle the one-hot encoding and decoding for your neural network: >>> vocab = list(set( ... [tok for row in dset['train']['tokens'] for tok in row])) >>> vocab[:4] ['cast', 'kaifeng', 'recovered', 'doctorate'] >>> id2tok = dict(enumerate(vocab)) >>> list(id2tok.items())[:4] [(0, 'cast'), (1, 'kaifeng'), (2, 'recovered'), (3, 'doctorate')] >>> tok2id = {tok: i for (i, tok) in id2tok.items()} >>>
参考来源
- 位置:《Natural Language Processing in Action, Second Edition》第06章《用词嵌入推理》(来源项目:a19c7933-4eda-4176-aebd-30fe7e1ad292;源文件:extracted/Natural Language Processing in Action, Second Edition/_epub-src/OEBPS/Text/chapter-6.html)
- 结论依据:摘录中关于词表编号需确定且随模型保存的定义、比较或条件支撑卡片;原书表述不严谨的范围已在覆盖记录逐项限定,不把案例结果外推为普遍结论。
- 原始内容:You’ll need to compute the vocabulary for your dataset to handle the one-hot encoding and decoding for your neural network: >>> vocab = list(set( ... [tok for row in dset['train']['tokens'] for tok in row])) >>> vocab[:4] ['cast', 'kaifeng', 'recovered', 'doctorate'] >>> id2tok = dict(enumerate(vocab)) >>> list(id2tok.items())[:4] [(0, 'cast'), (1, 'kaifeng'), (2, 'recovered'), (3, 'doctorate')] >>> tok2id = {tok: i for (i, tok) in id2tok.items()} >>>