未验证 提交 2328c646 编写于 作者: S ShusenTang 提交者: GitHub

fix bug in load_pretrained_embedding #84

上级 39328348
......@@ -195,15 +195,19 @@ def load_pretrained_embedding(words, pretrained_vocab):
idx = pretrained_vocab.stoi[word]
embed[i, :] = pretrained_vocab.vectors[idx]
except KeyError:
oov_count += 0
oov_count += 1
if oov_count > 0:
print("There are %d oov words.")
print("There are %d oov words." % oov_count)
return embed
net.embedding.weight.data.copy_(
load_pretrained_embedding(vocab.itos, glove_vocab))
net.embedding.weight.requires_grad = False # 直接加载预训练好的, 所以不需要更新它
```
输出:
```
There are 21202 oov words.
```
### 10.7.2.2 训练并评价模型
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册