日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

keras 的 example 文件 imdb_bidirectional_lstm.py 解析

發布時間:2023/11/27 生活经验 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 keras 的 example 文件 imdb_bidirectional_lstm.py 解析 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

imdb是一個文本情感分析的數據集,通過評論來分析觀眾對電影是好評還是差評

其網絡結構比較簡單

________________________________________________________________________________
Layer (type)                        Output Shape                    Param #     
================================================================================
embedding_1 (Embedding)             (None, 100, 128)                2560000     
________________________________________________________________________________
bidirectional_1 (Bidirectional)     (None, 128)                     98816       
________________________________________________________________________________
dropout_1 (Dropout)                 (None, 128)                     0           
________________________________________________________________________________
dense_1 (Dense)                     (None, 1)                       129         
================================================================================
Total params: 2,658,945
Trainable params: 2,658,945
Non-trainable params: 0
________________________________________________________________________________

對imdb數據集稍微分析一下,

通過函數load_data獲取到的x_train, y_train,是一堆編號,這個編號不太直接,可以通過下面代碼解析出來:

word_index = imdb.get_word_index()word_index = {k:(v+3) for k,v in word_index.items()}
word_index["<PAD>"] = 0
word_index["<START>"] = 1
word_index["<UNK>"] = 2  # unknown
word_index["<UNUSED>"] = 3reverse_word_index = dict([(value, key) for (key, value) in word_index.items()])def decode_review(text):return ' '.join([reverse_word_index.get(i, '?') for i in text])for i in range(10):print(decode_review(x_train[i]))print(y_train[i])

就可以看到評論的具體內容,而y_train打印出來的是0和1,分別代表差評和好評

x_train和y_train的shape分別為

(25000, 100)
(25000,)

?

——————————————————————————————————

不另開帖子了,把其他幾個網絡的結構也貼出來備忘:

imdb_cnn_lstm.py的神經網絡結構如下:

________________________________________________________________________________
Layer (type)                        Output Shape                    Param #     
================================================================================
embedding_1 (Embedding)             (None, 100, 128)                2560000     
________________________________________________________________________________
dropout_1 (Dropout)                 (None, 100, 128)                0           
________________________________________________________________________________
conv1d_1 (Conv1D)                   (None, 96, 64)                  41024       
________________________________________________________________________________
max_pooling1d_1 (MaxPooling1D)      (None, 24, 64)                  0           
________________________________________________________________________________
lstm_1 (LSTM)                       (None, 70)                      37800       
________________________________________________________________________________
dense_1 (Dense)                     (None, 1)                       71          
________________________________________________________________________________
activation_1 (Activation)           (None, 1)                       0           
================================================================================
Total params: 2,638,895
Trainable params: 2,638,895
Non-trainable params: 0
________________________________________________________________________________

imdb_cnn.py的神經網絡結構如下:

____________________________________________________________________________________________________
Layer (type)                                 Output Shape                            Param #        
====================================================================================================
embedding_1 (Embedding)                      (None, 400, 50)                         250000         
____________________________________________________________________________________________________
dropout_1 (Dropout)                          (None, 400, 50)                         0              
____________________________________________________________________________________________________
conv1d_1 (Conv1D)                            (None, 398, 250)                        37750          
____________________________________________________________________________________________________
global_max_pooling1d_1 (GlobalMaxPooling1D)  (None, 250)                             0              
____________________________________________________________________________________________________
dense_1 (Dense)                              (None, 250)                             62750          
____________________________________________________________________________________________________
dropout_2 (Dropout)                          (None, 250)                             0              
____________________________________________________________________________________________________
activation_1 (Activation)                    (None, 250)                             0              
____________________________________________________________________________________________________
dense_2 (Dense)                              (None, 1)                               251            
____________________________________________________________________________________________________
activation_2 (Activation)                    (None, 1)                               0              
====================================================================================================
Total params: 350,751
Trainable params: 350,751
Non-trainable params: 0
____________________________________________________________________________________________________

?

imdb_lstm.py的神經網絡結構為:

_________________________________________________________________
Layer (type)                 Output Shape              Param #
=================================================================
embedding_1 (Embedding)      (None, None, 128)         2560000
_________________________________________________________________
lstm_1 (LSTM)                (None, 128)               131584
_________________________________________________________________
dense_1 (Dense)              (None, 1)                 129
=================================================================
Total params: 2,691,713
Trainable params: 2,691,713
Non-trainable params: 0
_________________________________________________________________

——————————————————————

總目錄

keras的example文件解析

總結

以上是生活随笔為你收集整理的keras 的 example 文件 imdb_bidirectional_lstm.py 解析的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。