Skip to content

Commit 2328c64

Browse files
authored
fix bug in load_pretrained_embedding #84
1 parent 3932834 commit 2328c64

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

docs/chapter10_natural-language-processing/10.7_sentiment-analysis-rnn.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,19 @@ def load_pretrained_embedding(words, pretrained_vocab):
195195
idx = pretrained_vocab.stoi[word]
196196
embed[i, :] = pretrained_vocab.vectors[idx]
197197
except KeyError:
198-
oov_count += 0
198+
oov_count += 1
199199
if oov_count > 0:
200-
print("There are %d oov words.")
200+
print("There are %d oov words." % oov_count)
201201
return embed
202202

203203
net.embedding.weight.data.copy_(
204204
load_pretrained_embedding(vocab.itos, glove_vocab))
205205
net.embedding.weight.requires_grad = False # 直接加载预训练好的, 所以不需要更新它
206206
```
207+
输出:
208+
```
209+
There are 21202 oov words.
210+
```
207211

208212
### 10.7.2.2 训练并评价模型
209213

0 commit comments

Comments
 (0)