forked from patrickloeber/pytorch-chatbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2002a2d
Showing
1 changed file
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# Implementation of a Contextual Chatbot in PyTorch. | ||
Simple chatbot implementation with PyTorch. | ||
|
||
- The implementation should be easy to follow for beginners and provide a basic understanding of chatbots. | ||
- The implementation is straightforward with a Feed Forward Neural net with 2 hidden layers. | ||
- Customization for your own use case is super easy. Just modify `intents.json` with possible patterns and responses and re-run the training (see below for more info). | ||
|
||
The approach is inspired by this article and ported to PyTorch: [https://chatbotsmagazine.com/contextual-chat-bots-with-tensorflow-4391749d0077](https://chatbotsmagazine.com/contextual-chat-bots-with-tensorflow-4391749d0077). | ||
|
||
## Installation | ||
|
||
### Create an environment | ||
Whatever you prefer (e.g. `conda` or `venv`) | ||
```console | ||
mkdir myproject | ||
$ cd myproject | ||
$ python3 -m venv venv | ||
``` | ||
|
||
### Activate it | ||
Mac / Linux: | ||
```console | ||
. venv/bin/activate | ||
``` | ||
Windows: | ||
```console | ||
venv\Scripts\activate | ||
``` | ||
### Install PyTorch and dependencies | ||
|
||
For Installation of PyTorch see [official website](https://pytorch.org/). | ||
|
||
You also need `nltk`: | ||
```console | ||
pip install nltk | ||
``` | ||
|
||
If you get an error during the first run, you also need to install `nltk.tokenize.punkt`: | ||
Run this once in your terminal: | ||
```console | ||
$ python | ||
>>> import nltk | ||
>>> nltk.download('punkt') | ||
``` | ||
|
||
## Usage | ||
Run | ||
```console | ||
python train.py | ||
``` | ||
This will dump `data.pth` file. And then run | ||
```console | ||
python chat.py | ||
``` | ||
## Customize | ||
Have a look at [intent.json](intents.json). You can customize it according to your own use case. Just define a new `tag`, possible `patterns`, and possible `responses` for the chat bot. You have to re-run the training whenever this file is modified. | ||
```console | ||
{ | ||
"intents": [ | ||
{ | ||
"tag": "greeting", | ||
"patterns": [ | ||
"Hi", | ||
"Hey", | ||
"How are you", | ||
"Is anyone there?", | ||
"Hello", | ||
"Good day" | ||
], | ||
"responses": [ | ||
"Hey :-)", | ||
"Hello, thanks for visiting", | ||
"Hi there, what can I do for you?", | ||
"Hi there, how can I help?" | ||
] | ||
}, | ||
... | ||
] | ||
} | ||
```console |