Skip to main content

A nano-LLM trained from scratch on personal chat data to mimic a conversational style.

Project description

Personal Chat SLM (Small Language Model)

PyPI version License: MIT Python Version

A command-line tool to train a "nano" language model from scratch on your personal chat history. This project takes a raw chat export (like from WhatsApp) and builds a character-level Transformer model that learns to mimic the unique style, vocabulary, and rhythm of your conversations.

Think of it as creating a "digital conversational ghost" from your chat data. It's designed primarily as an educational tool to understand how language models are built from the ground up, rather than a large-scale, general-purpose chatbot.

Features

  • Builds from Scratch: Doesn't use pre-trained models. You build and train your own Transformer architecture.
  • Character-Level Learning: Learns the statistical patterns of your chat one character at a time, allowing it to capture unique spellings, slang, and emoji usage.
  • CLI Interface: A simple, powerful command-line interface to manage the entire workflow: cleaning data, training the model, and generating text.
  • Packaged for Distribution: Published as a public package on PyPI, so anyone can install and use it.

How It Works

The tool follows a three-step process, managed entirely by the command-line interface:

  1. Clean: It ingests a raw chat file (e.g., _chat.txt from WhatsApp) and strips away all metadata like timestamps, sender names, and system messages (<Media omitted>). This produces a clean text corpus.
  2. Train: It uses this clean corpus to train a decoder-only Transformer model (like GPT). The model learns the probability of which character is likely to follow a given sequence of characters.
  3. Generate: Once trained, the model can be given a starting prompt. It then generates new text character-by-character based on the patterns it learned, effectively mimicking the conversational style of the training data.

Installation

You can install personal-chat-slm directly from PyPI using pip:

pip install personal-chat-slm

Usage: The 3-Step Workflow

Using the tool involves preparing your data and then running the three main commands in order.

Step 1: Prepare Your Data

You need a raw chat log file. The tool is designed to work with WhatsApp chat exports.

  1. In WhatsApp, go to a chat, tap the three dots -> More -> Export chat -> Without media.
  2. Save the resulting .txt file inside a data/ folder in your project directory. Let's assume you name it data/my_chat.txt.

Step 2: Clean the Data

Run the clean command to process your raw chat file.

# This command will read your raw chat file and create a clean version.
personal-chat-slm clean --input-file data/my_chat.txt --output-file data/chat_clean.txt

Step 3: Train the Model

Now, use the cleaned data to train your model. This step will take time and is best run on a machine with a GPU.

# This command starts the training process and saves the final model.
personal-chat-slm train --data_path data/chat_clean.txt --max-iters 5000
  • --max-iters: The number of training steps. 5000 is a good starting point. More iterations can lead to a better model but will take longer.
  • The trained model will be saved by default to models/nano_llm_model.pth.

Step 4: Generate Text

Once your model is trained, you can use it to generate text from any prompt.

# Provide a prompt directly on the command line.
personal-chat-slm generate "Hey, what are you doing tonight?" --max-new-tokens 300

The model will load your trained weights and generate text that continues the prompt in the style it has learned.

For Developers (Local Setup)

If you want to contribute or modify the source code, follow these steps:

  1. Clone the repository:

    git clone [https://github.com/Imprayas12/personal-chat-slm.git](https://github.com/Imprayas12/personal-chat-slm.git)
    cd personal-chat-slm
    
  2. Create and activate a virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
    
  3. Install in editable mode: This command links the personal-chat-slm command to your source code, so any changes you make are immediately reflected.

    pip install -e .
    

Ethical Considerations & Disclaimer

This project deals with highly sensitive personal data. Ethical use is paramount.

  • Consent: Do not use any chat log without the explicit, informed consent of all participants in the chat.
  • Privacy: Never upload your private chat data or trained models derived from it to public repositories like GitHub. The .gitignore file in this project is configured to prevent this automatically. Handle the data with extreme care.
  • Disclaimer: This tool is provided for educational purposes. The generated text is a statistical artifact and may not always be coherent or appropriate. The creators are not responsible for the model's output or any misuse of this software.

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

personal_chat_slm-0.1.2.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

personal_chat_slm-0.1.2-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file personal_chat_slm-0.1.2.tar.gz.

File metadata

  • Download URL: personal_chat_slm-0.1.2.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for personal_chat_slm-0.1.2.tar.gz
Algorithm Hash digest
SHA256 ec3c5e04b7c8a80ec714da89abe51bf5ce3be6bd6627c79ffcba775a74191f4d
MD5 a47e21f6bc1f266bdc78e69756805c3d
BLAKE2b-256 b2694573197f086ce54dc2ac9e0ff1c26c52c2b3640f23bc6d53e73e09306913

See more details on using hashes here.

File details

Details for the file personal_chat_slm-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for personal_chat_slm-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4d715373f52438e3763b10cc72eaa26dd6fa3aa2768f322a3d8b192ee5ecfed2
MD5 ca78ab966d19d51ba1d5732c2a601843
BLAKE2b-256 b4f7c329a2cbdadf9ce1207eeb6794f47b0c4b1f13f10cf1b0db44fcbc42f256

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page