丁香五月天婷婷久久婷婷色综合91|国产传媒自偷自拍|久久影院亚洲精品|国产欧美VA天堂国产美女自慰视屏|免费黄色av网站|婷婷丁香五月激情四射|日韩AV一区二区中文字幕在线观看|亚洲欧美日本性爱|日日噜噜噜夜夜噜噜噜|中文Av日韩一区二区

您正在使用IE低版瀏覽器,為了您的雷峰網(wǎng)賬號(hào)安全和更好的產(chǎn)品體驗(yàn),強(qiáng)烈建議使用更快更安全的瀏覽器
此為臨時(shí)鏈接,僅用于文章預(yù)覽,將在時(shí)失效
人工智能開(kāi)發(fā)者 正文
發(fā)私信給AI研習(xí)社
發(fā)送

1

我用 tensorflow 實(shí)現(xiàn)的 “一個(gè)神經(jīng)聊天模型”

本文作者: AI研習(xí)社 編輯:賈智龍 2017-09-07 10:26
導(dǎo)語(yǔ):一個(gè)基于深度學(xué)習(xí)的聊天機(jī)器人。

雷鋒網(wǎng)按:本文原作者小灰灰,原載于專欄。雷鋒網(wǎng)已獲得作者授權(quán)。

概述

這個(gè)工作嘗試重現(xiàn)這個(gè)論文的結(jié)果 A Neural Conversational Model (aka the Google chatbot).
它使用了循環(huán)神經(jīng)網(wǎng)絡(luò)(seq2seq 模型)來(lái)進(jìn)行句子預(yù)測(cè)。它是用 python 和 TensorFlow 開(kāi)發(fā)。

程序的加載主體部分是參考 Torch 的  neuralconvo from macournoyer.

現(xiàn)在, DeepQA 支持一下對(duì)話語(yǔ)料:

To speedup the training, it's also possible to use pre-trained word embeddings (thanks to Eschnou). More info here.

安裝

這個(gè)程序需要一下依賴 (easy to install using pip: pip3 install -r requirements.txt):

  • python 3.5

  • tensorflow (tested with v1.0)

  • numpy

  • CUDA (for using GPU)

  • nltk (natural language toolkit for tokenized the sentences)

  • tqdm (for the nice progression bars)

你可能需要下載附帶的數(shù)據(jù)讓 nltk 正常工作。

python3 -m nltk.downloader punkt

Cornell 數(shù)據(jù)集已經(jīng)包括了。其他的數(shù)據(jù)集查看 readme 文件到他們所在的文件夾。  (在  data/).

網(wǎng)站接口需要一些附加的包:

  • django (tested with 1.10)

  • channels

  • Redis (see here)

  • asgi_redis (at least 1.0)

Docker 安裝也是支持的,更多詳細(xì)的教程參考  here.

運(yùn)行

聊天機(jī)器人

訓(xùn)練這個(gè)模型,直接運(yùn)行 main.py 。一旦訓(xùn)練完成,你可以測(cè)試結(jié)果用 main.py --test
(結(jié)果生成在  'save/model/samples_predictions.txt') 或者用 main.py --test interactive (更有趣).

Here are some flags which could be useful. For more help and options, use python main.py -h:

  • --modelTag: allow to give a name to the current model to differentiate between them when testing/training.

  • --keepAll: use this flag when training if when testing, you want to see the predictions at different steps (it can be interesting to see the program changes its name and age as the training progress). Warning: It can quickly take a lot of storage space if you don't increase the --saveEvery option.

  • --filterVocab 20 or --vocabularySize 30000: Limit the vocabulary size to and optimize the performances and memory usage. Replace the words used less than 20 times by thetoken and set a maximum vocabulary size.

  • --verbose: when testing, will print the sentences as they are computed.

  • --playDataset: show some dialogue samples from the dataset (can be use conjointly with --createDataset if this is the only action you want to perform).

To visualize the computational graph and the cost with TensorBoard, just run tensorboard --logdir save/.

默認(rèn)的這個(gè)網(wǎng)絡(luò)架構(gòu)是一個(gè)標(biāo)準(zhǔn)的 encoder/decoder 有兩個(gè) LSTM layers (隱藏層大小 256) ,然后 vocabulary 的 embedding size 是  32. 這個(gè)網(wǎng)絡(luò)用 ADAM 訓(xùn)練。最大的句子長(zhǎng)度設(shè)置為 10 個(gè)單詞,但是可以增加。

結(jié)果

當(dāng)然,這個(gè)網(wǎng)絡(luò)并不會(huì)很擅長(zhǎng)聊天:

Q: Hi
A: Hi.

Q: What is your name ?
A: Laura.

Q: What does that mean ?
A: I dunno.

Q: How old are you ?
A: thirty-five.

Q: Will Google hire me ?
A: No.

Q: Tell me the alphabet
A: Fuck you.

Q: That's not nice
A: Yeah.

這里有一些情況它并不能正確回答:

Q: Who is Laura ?
A: My brother.

Q: Say 'goodbye'
A: Alright.

Q: What is cooking ?
A: A channel.

Q: Can you say no ?
A: No.

Q: Two plus two
A: Manny...

預(yù)訓(xùn)練模型

項(xiàng)目截圖

我用 tensorflow 實(shí)現(xiàn)的 “一個(gè)神經(jīng)聊天模型”

chatbot_miniature.png

實(shí)測(cè)截圖

我用 tensorflow 實(shí)現(xiàn)的 “一個(gè)神經(jīng)聊天模型”

Screenshot from 2017-09-05 14-47-52.png

一步一步教程

1. 下載這個(gè)項(xiàng)目:
https://github.com/Conchylicultor/DeepQA
2. 下載訓(xùn)練好的模型:
https://drive.google.com/file/d/0Bw-phsNSkq23OXRFTkNqN0JGUU0/view
(如果網(wǎng)址不能打開(kāi)的話,今晚我會(huì)上傳到百度網(wǎng)盤,分享到:http://www.tensorflownews.com/
3. 解壓之后放在 項(xiàng)目 save 目錄下,如圖所示

我用 tensorflow 實(shí)現(xiàn)的 “一個(gè)神經(jīng)聊天模型”

Screenshot from 2017-09-05 14-52-13.png

4. 復(fù)制 save/model-pretrainedv2/dataset-cornell-old-lenght10-filter0-vocabSize0.pkl 這個(gè)文件到  data/samples/,如圖所示:

我用 tensorflow 實(shí)現(xiàn)的 “一個(gè)神經(jīng)聊天模型”

Screenshot from 2017-09-05 14-55-00.png

5. 在項(xiàng)目目錄執(zhí)行一下命令:

python3 main.py --modelTag pretrainedv2 --test interactive

程序讀取了預(yù)訓(xùn)練的模型之后,如圖:

我用 tensorflow 實(shí)現(xiàn)的 “一個(gè)神經(jīng)聊天模型”

Screenshot from 2017-09-05 14-57-14.png

聊天機(jī)器人資源合集

項(xiàng)目,語(yǔ)聊,論文,教程
https://github.com/fendouai/Awesome-Chatbot

DeepQA

https://github.com/Conchylicultor/DeepQA

備注:為了更加容易了解這個(gè)項(xiàng)目,說(shuō)明部分翻譯了項(xiàng)目的部分 readme ,主要是介紹使用預(yù)處理數(shù)據(jù)來(lái)運(yùn)行這個(gè)項(xiàng)目。

雷峰網(wǎng)版權(quán)文章,未經(jīng)授權(quán)禁止轉(zhuǎn)載。詳情見(jiàn)轉(zhuǎn)載須知。

我用 tensorflow 實(shí)現(xiàn)的 “一個(gè)神經(jīng)聊天模型”

分享:
相關(guān)文章

編輯

聚焦數(shù)據(jù)科學(xué),連接 AI 開(kāi)發(fā)者。更多精彩內(nèi)容,請(qǐng)?jiān)L問(wèn):yanxishe.com
當(dāng)月熱門文章
最新文章
請(qǐng)?zhí)顚?xiě)申請(qǐng)人資料
姓名
電話
郵箱
微信號(hào)
作品鏈接
個(gè)人簡(jiǎn)介
為了您的賬戶安全,請(qǐng)驗(yàn)證郵箱
您的郵箱還未驗(yàn)證,完成可獲20積分喲!
請(qǐng)驗(yàn)證您的郵箱
立即驗(yàn)證
完善賬號(hào)信息
您的賬號(hào)已經(jīng)綁定,現(xiàn)在您可以設(shè)置密碼以方便用郵箱登錄
立即設(shè)置 以后再說(shuō)