NovelCrafter is an incremental fine-tuning framework for training language models on literary works. It enables efficient training of LLMs on books and novels using LoRA (Low-Rank Adaptation) with automatic incremental training, progress tracking, and Hugging Face integration.
- π PDF Text Extraction: Automatically extracts and processes text from PDF books
 - π Incremental Training: Splits large texts into manageable chunks for progressive training
 - β‘ LoRA Fine-Tuning: Memory-efficient training using Parameter-Efficient Fine-Tuning (PEFT)
 - πΎ Auto-Save & Resume: Automatic progress tracking and ability to resume training
 - βοΈ HuggingFace Integration: Automatic model uploads to Hugging Face Hub
 - π WandB Logging: Optional Weights & Biases integration for experiment tracking
 - π₯οΈ CPU/GPU Support: Automatic device detection with optimized configurations
 - π§ Smart Model Selection: Uses 1B model for CPU, 3B model for GPU
 
- Python 3.8 or higher
 - PyTorch 2.0 or higher
 - 8GB+ RAM (16GB recommended for CPU training)
 - GPU with 8GB+ VRAM (optional, but recommended)
 
- 
Clone the repository
git clone https://github.com/990aa/novelCrafter.git cd novelCrafter - 
Create a virtual environment
python -m venv .venv # On Windows .venv\Scripts\activate # On Linux/Mac source .venv/bin/activate
 - 
Install dependencies
pip install -r requirements.txt
 - 
Set up environment variables
Create a
.envfile in the project root:HF_TOKEN=your_huggingface_token_here WANDB_API_KEY=your_wandb_api_key_here # Optional BOOK_PDF=your_book.pdf # The PDF filename in input/ folder
Get your tokens:
- Hugging Face Token: https://huggingface.co/settings/tokens (needs write permission)
 - WandB API Key: https://wandb.ai/authorize (optional)
 
 
- 
Place your book PDF in the
input/directoryinput/ βββ your_book.pdf - 
Update the .env file with your PDF filename:
BOOK_PDF=your_book.pdf
 - 
Run the training script
python main.py
 - 
Training Progress
- The script will train on 10 incremental parts
 - After each part, you'll be asked to continue
 - Models are automatically saved and uploaded to HuggingFace
 - Progress is saved in 
train_progress.json 
 - 
Resume Training (if interrupted)
- Simply run 
python main.pyagain - It will automatically resume from the last completed part
 
 - Simply run 
 
novelCrafter/
βββ main.py                    # Main training script
βββ requirements.txt           # Python dependencies
βββ .env                       # Environment variables (create this)
βββ .gitignore                # Git ignore rules
βββ LICENSE.md                # MIT License
βββ README.md                 # This file
βββ MODEL_CARD.md             # Model documentation
βββ USAGE.md                  # Detailed usage guide
βββ train_progress.json       # Training progress tracker
βββ input/                    # Place your PDF books here
β   βββ The_crocodile.pdf
βββ book_model_part_1/        # Saved model checkpoints
βββ book_model_part_2/
βββ wandb/                    # WandB logs (if enabled)
The script automatically selects the appropriate model based on your hardware:
- GPU (CUDA): 
meta-llama/Llama-3.2-3B-Instruct(3 billion parameters) - CPU: 
meta-llama/Llama-3.2-1B-Instruct(1 billion parameters) 
You can modify this in main.py around line 115.
Key training parameters (in main.py):
# Text chunking
chunk_size = 10              # Sentences per chunk
num_parts = 10               # Number of training parts
# LoRA Configuration
r=8                          # LoRA rank
lora_alpha=32               # LoRA alpha
lora_dropout=0.05           # Dropout rate
# Training Arguments
num_train_epochs=3          # Epochs per part
per_device_train_batch_size=1
gradient_accumulation_steps=8
learning_rate=5e-5
weight_decay=0.01Update the repository name in main.py (line 83):
hf_repo = "your-username/your-model-name"1. Out of Memory (OOM)
- Reduce 
per_device_train_batch_sizeto 1 - Increase 
gradient_accumulation_steps - Use the 1B model instead of 3B
 - Close other applications
 
2. Slow Training on CPU
- Expected behavior - CPU training is 10-100x slower than GPU
 - Consider using Google Colab or cloud GPU
 - Reduce 
num_train_epochsfor faster iterations 
3. Model Not Uploading to HuggingFace
- Check your HF_TOKEN has write permissions
 - Ensure repository exists: 
huggingface-cli repo create your-model-name - Check internet connection
 
4. Import Errors
- Reinstall requirements: 
pip install -r requirements.txt --upgrade - Check Python version: 
python --version(needs 3.8+) 
- Training progress is printed to console
 - Models saved in 
book_model_part_X/directories - Progress tracked in 
train_progress.json 
If you set WANDB_API_KEY, view training metrics at:
https://wandb.ai/your-username/huggingface
- Style Transfer: Train models to write in the style of specific authors
 - Book Continuation: Generate text that continues a book's narrative
 - Literary Analysis: Fine-tune models for book-specific Q&A
 - Creative Writing: Use as a writing assistant trained on specific genres
 - Educational: Learn about LLM fine-tuning and PEFT techniques
 
Contributions are welcome! Please feel free to submit a Pull Request. For major changes:
- Fork the repository
 - Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
 
This project is licensed under the MIT License - see the LICENSE.md file for details.
- Meta AI for the Llama models
 - Hugging Face for transformers and PEFT libraries
 - Microsoft for DeepSpeed optimizations
 - Weights & Biases for experiment tracking
 
If you use this project in your research, please cite:
@software{novelcrafter2025,
  author = {990aa},
  title = {NovelCrafter: Incremental Fine-Tuning Framework for Literary LLMs},
  year = {2025},
  url = {https://github.com/990aa/novelCrafter}
}If you find this project useful, please consider giving it a star! β
Made with β€οΈ for the AI and Literature community