About

Jowa-mAi is a lightweight, open-source Large Language Model (MiniGPT) built with PyTorch. It uses an LSTM-based architecture trained on character-level Q&A data fetched from a remote database. Designed to run on low-end hardware with no GPU required.

🧠 LSTM Architecture

2-layer LSTM with 512 hidden units and 256-dim embeddings — lightweight yet capable

📡 Remote Database Training

Fetches Q&A pairs live from GitHub and trains on them using cross-entropy loss + Adam optimizer

⏱ Early Stopping

Training auto-stops when loss stops improving — saves the best weights automatically

💻 Cross-Platform

Runs on Windows and Linux — CPU or GPU via CUDA auto-detection

How the Code Works

1

Model Definition — JowaMAI

A PyTorch nn.Module with an Embedding layer → 2-layer LSTM → Dropout → Linear output layer. Takes a sequence of character indices and predicts the next character at each step.

class JowaMAI(nn.Module): embedding → LSTM(layers=2, hidden=512) → Dropout(0.4) → Linear(vocab_size) forward(x) → returns (output_logits, hidden_state)
2

Vocabulary / Tokenization

No subword tokenizer — the model works at the character level. data_tokens is a list of every supported character (a–z, A–Z, 0–9, symbols, space, newline). Each character maps to its list index.

# encode indices = [data_tokens.index(c) for c in text if c in data_tokens] # decode char = data_tokens[predicted_index]
3

Remote Data Fetch

fetch_remote_data() pulls a JSON file from GitHub. The JSON is a flat dictionary of "question": "answer" pairs used as the training corpus.

url = "https://raw.githubusercontent.com/.../database.json" data = requests.get(url).json() # { "q": "a", ... }
4

Training Loop

Each Q&A pair is formatted as "Q: ...\nA: ...\n" then encoded. The model learns to predict the next character given all previous ones. Uses ReduceLROnPlateau to decay the learning rate and early stopping (patience=10) to avoid overfitting.

optimizer = Adam(lr=0.001) criterion = CrossEntropyLoss() scheduler = ReduceLROnPlateau(patience=5, factor=0.5) for epoch in range(100): loss = criterion(model(inputs), targets) loss.backward() → optimizer.step() if no_improve == 10: break # early stop torch.save(model.state_dict(), "jowa-mAi-1.6.pt")
5

Text Generation

Given a user prompt, the model formats it as "Q: {prompt}\nA: ", then generates characters one by one using temperature-scaled softmax sampling until it hits a sentence-ending punctuation or max length.

prompt → "Q: {prompt}\nA: " → encode → feed to LSTM for step in range(max_len): logits = output / temperature # scale confidence probs = softmax(logits) char = multinomial_sample(probs) # random weighted pick if char in [".", "!", "?"]: break

License — GNU GPL v2.0

GNU General Public License v2.0
This software is free and open-source. You are free to use, study, modify, and distribute it under the terms of the GNU GPL v2.0. Any derivative work must also be released under the same license. No warranty is provided.

Copyright © 2025/2026 Ahmed Walid (AXV)Full License Text
Download Jowa-mAi v1.6