This repository facilitates the training of a character-level or word-level language model solely based on WhatsApp chat messages. After model training, one can kick-off a synthetic conversation with the trained on Whatsapp chat group.
assets/input/chat.txt
is just a placeholder, to be replaced with the actual corpus of chat messages.|-- assets
| |-- input
| | |-- chat.txt
| |-- output
| | |-- contacts.txt
| | |-- vocab.txt
| | |-- train.pt
| | |-- valid.pt
| |-- models
| | |--model.pt
|-- src
| |-- chat.py
| |-- model.py
| |-- preprocess.py
| |-- train.py
| |-- utils.py
|-- config.py
|-- run.py
assets/input/chat.txt:
The input file needs to be an exported WhatsApp chat (without media).assets/output/:
The encoded training/validation data and the trained model will be written into this localtion.assets/models/model.pt:
Trained pytorch model object.src/preprocess.py:
Converts chat messages into encoded PyTorch tensors. Data is split into training and validation set.src/model.py:
Defines the language model class.src/train.py:
Contains code for training the language model.src/chat.py:
Contains the function for conversational interaction with the model.src/utils.py:
Other useful utility functions.run.py:
The main script with an argument parser to call either of the three actions ("preprocess", "train", "chat").config.py:
Parameters for preprocessing and model training are recorded.git clone https://github.com/bernhard-pfann/lad-gpt.git
cd lad-gpt
pip install -r requirements.txt
To utilize this project fully, you'll need a .txt file that contains messages from a WhatsApp chat. Here are the steps to export your WhatsApp group chat into a .txt file:
Once you have the .txt file, place it in the assets/input
directory, called chat.txt
. Then you are ready to go!
Once input data is in place, the chats need to be encoded into numerical tensors. The encoded data is also split into training and validation set:
python run.py preprocess
To train a language model from scratch and solely based on the encoded chat data. Set --update
in case you want to continue training an already model.
python run.py train --update
To initiale a chat with the trained model:
python run.py chat