This project implements an offline chat-reply recommendation system using a fine-tuned DistilGPT-2 model. The system is designed to generate appropriate replies to chat messages based on historical conversation data.
- Data Loading: Reads chat data from an Excel file (
conversationfile.xlsx). - Preprocessing: Cleans and standardizes sender/message columns, detects user labels, and pairs messages for supervised training.
- Dataset Preparation: Converts message pairs into tokenized format using GPT-2 tokenizer and creates a PyTorch dataset and dataloader.
- Model Training: Fine-tunes DistilGPT-2 on the chat pairs using cross-entropy loss. Training is performed on CPU for demonstration purposes.
- Evaluation: Calculates BLEU score and perplexity to assess model performance.
- Artifacts: Saves the trained model weights (
ChatRec_Model.pt), a joblib dump (Model.joblib), and a summary file (ReadMe.txt).
nchat.ipynb: Main notebook containing all code for data processing, model training, and evaluation.conversationfile.xlsx: Source chat data for training.ChatRec_Model.pt: Saved PyTorch model weights.Model.joblib: Model weights in joblib format for portability.ReadMe.txt: Text summary of the project and artifacts.
- pandas
- torch
- transformers (HuggingFace)
- nltk (for BLEU score)
- joblib
- Place your chat data in
conversationfile.xlsxwith columns for sender, message, and optionally timestamp. - Run the notebook
nchat.ipynbto preprocess data, train the model, and evaluate results. - The model can generate replies to input prompts using the
generate_replyfunction.
- BLEU Score: Measures the quality of generated replies against actual responses.
- Perplexity: Evaluates model confidence and fluency.
- Training is performed on CPU for demonstration; for larger datasets, GPU is recommended.
- The notebook is modular and can be adapted for other chat datasets with similar structure.
Pushpit Saluja
ChatRec_Model.ptModel.joblibReadMe.txt