{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Session 6: 构建聊天机器人 (import a chatbot)\n",
    "\n",
    "* 讲一讲聊天机器人的制作原理，包括基于深度学习的实现\n",
    "* 选择一个聊天机器人框架， 将其导入进我们的框架"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "___"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 用一篇英文来了解 chat bot\n",
    "\n",
    "https://www.analyticsvidhya.com/blog/2018/03/essentials-of-deep-learning-sequence-to-sequence-modelling-with-attention-part-i/"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "___"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 1. text to text\n",
    "\n",
    "聊天基于语言，语言就是文本\n",
    "\n",
    "所以本质上我们的输入是文本，输出也是文本"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "___"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 2. sequence to sequence\n",
    "\n",
    "计算机不能直接处理文本\n",
    "\n",
    "所以得先把文本转成数字，而一串数字就是 `sequence (序列)`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "___"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 3. by people, for people\n",
    "\n",
    "讲道理，人是看不懂 `sequence` 的\n",
    "\n",
    "所以最终还得转为文本\n",
    "\n",
    "所以 text -> number -> text\n",
    "\n",
    "also `encoder` to `decoder`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "___"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 选择一个开源 bot\n",
    "\n",
    "\n",
    "`https://github.com/tensorlayer/seq2seq-chatbot`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "___"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 1. clone project to local\n",
    "\n",
    "`git clone https://github.com/tensorlayer/seq2seq-chatbot.git`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 2. install requirements\n",
    "\n",
    "`cd seq2seq-chatbot`\n",
    "\n",
    "`sudo pip3 install -r requirements.txt`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 3. train\n",
    "\n",
    "`python3 main.py --batch-size 32 --num-epochs 50 -lr 0.001`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 4. usage\n",
    "\n",
    "`python3 main.py --inference-mode`\n",
    "\n",
    "send model to server: `scp -r /path_to_your_file username@server_Ip:~/`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "___"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
