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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

RNN实践之唐诗创作

發布時間:2024/3/24 编程问答 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 RNN实践之唐诗创作 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這次,嘗試先用RNN玩一下唐詩創作。

//update 201602100001 本來是唐詩的,結果唐詩里面太多生僻字 所以我剛剛從網上下載了一些歌詞,想仿照參考資料【4】創作一首歌。 不過,只有111KB,不知道訓練模型夠不夠。 同時,我傍晚訓練唐詩時,因為買的服務器是1G1核的,根本難以訓練,所以換了個4G的服務器。 //當然,同樣是只有CPU

安裝Torch

買了臺最便宜的云服務器,Ubuntu.?
將torch裝在/home/tom/torch/下;安裝過程可以查看官方文檔。

//新建用戶tom useradd tom -m -s /bin/bash //添加用戶到sudo組sudo usermod -a -G sudo tom

由于我是剛買的服務器,可能在安裝torch之前需要先執行以下命令

apt-get update apt-get install curl apt-get install git apt-get install cmake

安裝過程中,出現了如下錯誤:

【錯誤1】

remote: Compressing objects: 100% (4/4), done. error: RPC failed; result=56, HTTP code = 200 | 924.00 KiB/s fatal: The remote end hung up unexpectedly fatal: early EOF fatal: index-pack failed Clone of 'https://github.com/torch/cutorch.git' into submodule path 'extra/cutorch' failed

解決方案為這個鏈接

git clone https://github.com/torch/distro.git ~/torch --recursive --depth 1

【錯誤2】

Error: Build error: Failed compiling object readline.o

解決方案為:

sudo apt-get install libreadline-dev

安裝成功后輸入th得到下圖:

Char-rnn

Char-rnn是一個基于RNN的字符級的語句生成工具。

這里的安裝過程完全參照這個鏈接;作者是Andrej Karpathy,該作者同時寫了一個介紹RNN的博客,可以訪問這里查看。

按照上面安裝了torch之后,就需要安裝以下三個包。

$ luarocks install nngraph $ luarocks install optim $ luarocks install nn

訓練過程中

creating vocabulary mapping... putting data into tensor... saving data/chinesepoetry/vocab.t7 /home/tom/torch/install/bin/luajit: cannot open <data/chinesepoetry/vocab.t7> in mode w at /home/tom/torch/pkg/torch/lib/TH/THDiskFile.c:640 stack traceback:

這是權限錯誤

//終于可以訓練了 th train.lua -data_dir data/tinyshakespeare -rnn_size 112 -num_layers 2 -dropout 0.5

結果

//201602091728 現在讓它去訓練吧,結果再說。 //201602100011 因為1唐詩中大量生僻字使得文本過于復雜;2之前那個云服務器只有1G內存。故重新訓練。

訓練了好幾次,結果都是中文亂碼,,,這個有點煩。?
?
簡單來說,解決方案為,將input.txt的編碼格式設置為下圖(Notepad++)?
UNIX UTF-8?


現在,終于成功了。?
然而,慘不忍睹


參考資料

【1】torch?
http://torch.ch/docs/getting-started.html?
【2】char-rnn?
https://github.com/karpathy/char-rnn?
【3】讓神經網絡做唐詩?
http://zhengwy.com/neural-network-for-tangshi/?
【4】汪峰老師作詞機?
https://github.com/phunterlau/wangfeng-rnn

總結

以上是生活随笔為你收集整理的RNN实践之唐诗创作的全部內容,希望文章能夠幫你解決所遇到的問題。

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