Skip to content

Commit c224e3c

Browse files
authored
Update 10.7_sentiment-analysis-rnn.md
1 parent b58e551 commit c224e3c

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ embedding_matrix = get_weights(vocab,word_to_embedding,50,word_to_index,index_to
231231
embed_size, num_hiddens, max_len = 50, 100, 500
232232
num_epochs = 5
233233

234+
#因为tensorflowlSTM无法自动堆叠,故我们不进行堆叠
234235
model = tf.keras.Sequential([
235236
layers.Embedding(len(vocab), embed_size,weights=[embedding_matrix],input_length=500),
236237
layers.Bidirectional(layers.LSTM(num_hiddens)),
@@ -243,25 +244,13 @@ model.summary()
243244

244245

245246

246-
``` python
247-
embed_size, num_hiddens, num_layers = 100, 100, 2
248-
net = BiRNN(vocab, embed_size, num_hiddens, num_layers)
249-
```
250-
251247

252-
### 10.7.2.1 加载预训练的词向量
253248

254-
由于情感分类的训练数据集并不是很大,为应对过拟合,我们将直接使用在更大规模语料上预训练的词向量作为每个词的特征向量。这里,我们为词典`vocab`中的每个词加载100维的GloVe词向量。
255-
256-
``` python
257-
glove_vocab = Vocab.GloVe(name='6B', dim=100, cache=os.path.join(DATA_ROOT, "glove"))
258-
```
259249

260-
然后,我们将用这些词向量作为评论中每个词的特征向量。注意,预训练词向量的维度需要与创建的模型中的嵌入层输出大小`embed_size`一致。此外,在训练中我们不再更新这些词向量。
261250

262251

263252

264-
### 10.7.2.2 训练并评价模型
253+
### 10.7.2.1 训练并评价模型
265254

266255
这时候就可以开始训练模型了。
267256

0 commit comments

Comments
 (0)