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

歡迎訪問 生活随笔!

生活随笔

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

生活经验

keras 的 example 文件 lstm_text_generation.py 解析

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

該程序是學習現有的文章,然后學習預測下個字符,這樣一個字符一個字符的學會寫文章

?

先打印下char_indices

{'\n': 0, ' ': 1, '!': 2, '"': 3, "'": 4, '(': 5, ')': 6, ',': 7, '-': 8, '.': 9, '0': 10, '1': 11, '2': 12, '3': 13, '4': 14, '5': 15, '6': 16, '7': 17, '8': 18, '9': 19, ':': 20, ';': 21, '=': 22, '?': 23, '[': 24, ']': 25, '_': 26, 'a': 27, 'b': 28, 'c': 29, 'd': 30, 'e': 31, 'f': 32, 'g': 33, 'h': 34, 'i': 35, 'j': 36, 'k': 37, 'l': 38, 'm': 39, 'n': 40, 'o': 41, 'p': 42, 'q': 43, 'r': 44, 's': 45, 't': 46, 'u': 47, 'v': 48, 'w': 49, 'x': 50, 'y': 51, 'z': 52, '?': 53, '?': 54, 'é': 55, '?': 56}

?

然后構造訓練數據,輸入是?sentences,輸出是?next_chars,構造成如下結構,sentences就是把句子拆分出來,next_chars,名字就看出來了,就是下一個字符

                                  sentences next_chars
preface\n\n\nsupposing that truth is a woma          n
face\n\n\nsupposing that truth is a woman--          w
e\n\n\nsupposing that truth is a woman--wha          t\nsupposing that truth is a woman--what t          hpposing that truth is a woman--what then          ?sing that truth is a woman--what then? i          sg that truth is a woman--what then? is t          hhat truth is a woman--what then? is ther          etruth is a woman--what then? is there n          outh is a woman--what then? is there not           gis a woman--what then? is there not gro          ua woman--what then? is there not ground         \nwoman--what then? is there not ground\nfo          ran--what then? is there not ground\nfor s          u-what then? is there not ground\nfor susp          eat then? is there not ground\nfor suspect          ithen? is there not ground\nfor suspectingn? is there not ground\nfor suspecting th          ais there not ground\nfor suspecting that           athere not ground\nfor suspecting that allre not ground\nfor suspecting that all ph          inot ground\nfor suspecting that all philo          sground\nfor suspecting that all philosop          hound\nfor suspecting that all philosopher          sd\nfor suspecting that all philosophers,           ior suspecting that all philosophers, in           ssuspecting that all philosophers, in so           fpecting that all philosophers, in so farting that all philosophers, in so far asg that all philosophers, in so far as th          ehat all philosophers, in so far as they           hall philosophers, in so far as they hav          el philosophers, in so far as they have b          ehilosophers, in so far as they have been         \nosophers, in so far as they have been\ndo          gphers, in so far as they have been\ndogma          trs, in so far as they have been\ndogmatis          tin so far as they have been\ndogmatists,so far as they have been\ndogmatists, ha          vfar as they have been\ndogmatists, have           fr as they have been\ndogmatists, have fai          ls they have been\ndogmatists, have failedhey have been\ndogmatists, have failed tohave been\ndogmatists, have failed to un          dve been\ndogmatists, have failed to under          sbeen\ndogmatists, have failed to understa          nn\ndogmatists, have failed to understand           wogmatists, have failed to understand wom          eatists, have failed to understand women-          -sts, have failed to understand women--th          a

啊,有一點,就是上面的sentence,直接看起來好像不一樣長,實際是一樣長的,只不過前面三行,有兩個\n,在打印的時候是兩個字符,實際上\n是一個字符,導致的看起來不整齊

然后進行one-hot編碼,這都是NLP的常規操作,然后輸入輸出數據shape為:

x.shape ?(200285, 40, 57)
y.shape ?(200285, 57)

神經網絡模型為

_________________________________________________________________
Layer (type)                 Output Shape              Param #
=================================================================
lstm_1 (LSTM)                (None, 128)               95232
_________________________________________________________________
dense_1 (Dense)              (None, 57)                7353
=================================================================
Total params: 102,585
Trainable params: 102,585
Non-trainable params: 0
_________________________________________________________________

?

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

總目錄

keras的example文件解析

總結

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

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