我用tensorflow實現的“一個神經聊天模型”:一個基於深度學習的聊天機器人
概述
這個工作嘗試重現這個論文的結果 A Neural Conversational Model (aka the Google chatbot).
它使用了迴圈神經網路(seq2seq 模型)來進行句子預測。它是用 python 和 TensorFlow 開發。
程式的載入主體部分是參考 Torch的 neuralconvo from macournoyer.
現在, DeepQA 支援一下對話語料:
* Cornell Movie Dialogs corpus (default). Already included when cloning the repository.
* OpenSubtitles (thanks to Eschnou). Much bigger corpus (but also noisier). To use it, follow those instructions and use the flag --corpus opensubs
.
* Supreme Court Conversation Data (thanks to julien-c). Available using --corpus scotus
. See the instructions for installation.
* Ubuntu Dialogue Corpus (thanks to julien-c). Available using --corpus ubuntu
. See the instructions for installation.
* Your own data (thanks to julien-c) by using a simple custom conversation format (See here for more info).
To speedup the training, it’s also possible to use pre-trained word embeddings (thanks to Eschnou). More info here.
安裝
這個程式需要一下依賴(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)
你可能需要下載附帶的資料讓 nltk 正常工作。
python3 -m nltk.downloader punkt
Cornell 資料集已經包括了。其他的資料集檢視 readme 檔案到他們所在的資料夾。 (在 data/
).
網站介面需要一些附加的包:
- django (tested with 1.10)
- channels
- Redis (see here)
- asgi_redis (at least 1.0)
Docker 安裝也是支援的,更多詳細的教程參考 here.
執行
聊天機器人
訓練這個模型,直接執行 main.py
。一旦訓練完成,你可以測試結果用 main.py --test
(結果生成在 ‘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 <name>
: 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 the <unknown>
token 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/
.
預設的這個網路架構是一個標準的 encoder/decoder 有兩個 LSTM layers (隱藏層大小 256) ,然後 vocabulary 的 embedding size 是 32.這個網路用 ADAM 訓練。最大的句子長度設定為 10個單詞,但是可以增加。
結果
當然,這個網路並不會很擅長聊天:
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...
預訓練模型
專案截圖:
實測截圖:
一步一步教程:
1.下載這個專案:
https://github.com/Conchylicultor/DeepQA
2.下載訓練好的模型:
https://drive.google.com/file/d/0Bw-phsNSkq23OXRFTkNqN0JGUU0/view
(如果網址不能開啟的話,今晚我會上傳到百度網盤,分享到:http://www.tensorflownews.com/)
3.解壓之後放在 專案 save 目錄下
如圖所示
4.複製 save/model-pretrainedv2/dataset-cornell-old-lenght10-filter0-vocabSize0.pkl 這個檔案到 data/samples/
如圖所示:
5.在專案目錄執行一下命令:
python3 main.py --modelTag pretrainedv2 --test interactive
程式讀取了預訓練的模型之後,如圖:
聊天機器人資源合集
專案,語聊,論文,教程
https://github.com/fendouai/Awesome-Chatbot
更多教程:
http://www.tensorflownews.com/
DeepQA
備註:為了更加容易瞭解這個專案,說明部分翻譯了專案的部分 readme ,主要是介紹使用預處理資料來執行這個專案。
相關文章
- 用深度學習網路搭建一個聊天機器人(下篇)深度學習機器人
- 用深度學習網路搭建一個聊天機器人(上篇)深度學習機器人
- 用Python基於Google Bard做一個互動式的聊天機器人PythonGo機器人
- 寫一個自動回覆的聊天機器人機器人
- 如何用Java寫一個聊天機器人Java機器人
- 使用 python 打造一個微信聊天機器人Python機器人
- 基於Pytorch熱門深度學習框架 從零開發NLP聊天機器人PyTorch深度學習框架機器人
- clubhouse使用機器學習實現人與聊天房間的匹配機器學習
- 從零開始造一個“智障”聊天機器人機器人
- 基於 WebRTC 與 Webcam 開發一個聊天應用Web
- 實現一個webscoket聊天系統Web
- 打造一個window桌面應用:線上聊天對話機器人機器人
- 基於ThinkPHP5.0+GatewayWorker寫的一個聊天DEMOPHPGateway
- 用node實現一個簡單的聊天室——websocket實踐Web
- 讓聊天機器人完美回覆--基於PaddlePaddle的語義匹配模型DAM機器人模型
- 基於TensorFlow的深度學習實戰深度學習
- 自動聊天機器人專案班 [一門課搞定聊天機器人]機器人
- 一個同時支援移動端與小程式的聊天機器人機器人
- 使用WebSocket實現一個簡單的頁面聊天Web
- 用node實現一個簡單的聊天室—— 升級版
- 用Java程式碼實現一個簡單的聊天室功能Java
- 聊天室應用開發實踐(二):實現基於 Web 的聊天室Web
- 深度學習基礎-基於Numpy的卷積神經網路(CNN)實現深度學習卷積神經網路CNN
- 乾貨 | 如何用 Python 打造一個聊天機器人?【附程式碼】Python機器人
- 【機器學習基礎】神經網路/深度學習基礎機器學習神經網路深度學習
- 利用docker部署深度學習模型的一個最佳實踐Docker深度學習模型
- 如何基於 ZEGO SDK 實現 Android 一對一音視訊聊天應用GoAndroid
- 如何基於 ZEGO SDK 實現 Flutter 一對一音視訊聊天應用?GoFlutter
- 如何基於 ZEGO SDK 實現 Windows 一對一音視訊聊天應用GoWindows
- 用一個小例子教你入門機器學習框架TensorFlow機器學習框架
- node+socket.io 實現一個聊天室
- Andriod 實現一個類微信聊天介面 (二)
- 聊天富文字外掛,一個基於react的富文字外掛React
- 關於聊天機器人的閱讀筆記機器人筆記
- 定製個機器人幫你和Ta聊天機器人
- 我做了第一個ChatGPT .net api聊天庫ChatGPTAPI
- 經驗&教訓分享:我的第一個機器學習專案機器學習
- 零基礎入門深度學習(一):用numpy實現神經網路訓練深度學習神經網路
- 應用聚類模型獲得聊天機器人語料聚類模型機器人