π€ LLM-Powered News Content Enhancer
Fine-tuning LLaMA 3.2-1B with LoRA for Semantic Newsletter Analysis
π― Project Overview
This is a personal project addressing my need around news analysis of the fast-moving AI industry. I collect AI-related news content from various sources and needed a way to enhance raw news content with rich semantic metadata. This enables deeper, structured analysis and pattern-finding across trends and developments in the AI industry.
What This Project Does
- Enhance and add rich semantic metadata to AI-related news content as part of my news analyst application system
- Explore, test and compare Thinking Machines' Tinker's managed training & finetuning API service
Why This Matters
- 3-5x better content organization through semantic understanding
- 10x more metadata extracted from newsletter content
- 2-3x better cross-newsletter insights for knowledge synthesis
- 40-60% richer NotebookLM outputs for analysis and research
ποΈ System Architecture
This fine-tuning project is part of a larger News Analyst MCP Agent system:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β News Analyst MCP Agent β
β (Production system for automated newsletter processing) β
ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββ
β LLM Enhancement Layer β β This Project
β (Fine-tuned LoRA) β
βββββββββββββββββββββββββ
β
ββββββββββββββ΄βββββββββββββ
βΌ βΌ
βββββββββββββββββ ββββββββββββββββ
β Tinker LoRA β β Unsloth LoRA β
β (Cloud-based) β β (Local) β
βββββββββββββββββ ββββββββββββββββ
Integration Context:
- Deployment: Local Windows Surface Pro (Intel Iris Xe, 16GB RAM)
- Base Model: LLaMA 3.2-1B (1 billion parameters, optimized for edge devices)
- Architecture: LoRA adapters for parameter-efficient fine-tuning
- Production System: See
docs/NEWS_ANALYST_SYSTEM_ARCHITECTURE.md
π¬ LoRA vs Full Fine-Tuning Comparison
This project uses LoRA (Low-Rank Adaptation) instead of full fine-tuning for several critical reasons:
| Criterion | LoRA | Full Fine-Tuning | Winner |
|---|---|---|---|
| Memory (Colab T4) | 2.5GB | 17GB (exceeds 15GB limit) | β LoRA |
| Training Speed | 30-45 min | 60-90 min (if feasible) | β LoRA |
| Model Size | 50-100MB adapter | 1.2GB full model | β LoRA |
| Parameter Efficiency | 0.5% trainable | 100% trainable | β LoRA |
| Catastrophic Forgetting | Low risk | High risk | β LoRA |
| Data Requirements | 50-200 examples | 500-5000 examples | β LoRA |
| Performance | 90-95% of full FT | 100% (theoretical) | β οΈ Full FT |
Verdict: LoRA achieves 9.2/10 weighted score vs 6.0/10 for full fine-tuning.
Key Advantages:
- β Fits within Google Colab free tier (T4 GPU, 15GB VRAM)
- β Deployable on limited hardware (Intel Iris Xe, 16GB RAM)
- β Preserves general language capabilities
- β 99.5% parameter reduction (1-5M trainable vs 1.2B total)
See docs/LORA_COMPARISON.md for detailed analysis.
π Results
Model Comparison
Comprehensive Model Evaluation
Advanced Metrics Comparison
Performance Comparison Table
| Model | Quality Score | JSON Valid | ROUGE-1 | BERTScore | Consistency (CV) | Training Time |
|---|---|---|---|---|---|---|
| Tinker LoRA | 0.8674 | 100% | 0.7714 | 0.9649 | 0.0% β | 2.65 min |
| Unsloth LoRA | 0.2664 | 0% | 0.0311 | 0.7721 | 156.3% | 0.94 min |
| Base Model | 0.3302 | 0% | 0.0501 | 0.8003 | 45.2% | N/A |
Winner: Tinker LoRA achieved best performance across all metrics.
Key Findings
- Tinker LoRA: Perfect consistency, 100% valid JSON, highest semantic similarity
- Unsloth LoRA: Fast training but inconsistent outputs (placeholder text issue)
- Base Model: Verbose markdown output, doesn't follow JSON format
Performance Metrics
- Quality Score: Composite metric (ROUGE + BERTScore + JSON validation)
- JSON Validation: Schema compliance for structured output
- ROUGE-1: N-gram overlap with reference summaries
- BERTScore: Semantic similarity using contextual embeddings
- Consistency (CV): Coefficient of variation (lower is better)
See results/reports/evaluation_report.md for detailed analysis.
π Quick Start
Prerequisites
# Python 3.8+
python --version
# CUDA-capable GPU (for training) or CPU (for inference)
nvidia-smi # Optional: Check GPU availability
Installation
# Clone repository
git clone https://github.com/youshen-lim/llama-tinker-lora-newsletter.git
cd llama-tinker-lora-newsletter
# Install dependencies
pip install -r requirements.txt
Training Data
- Training examples: 101 annotated newsletters
- Test examples: 20 newsletters
- Format: JSONL with user/assistant message pairs
- Annotation: Custom widget for manual annotation
# View training data
head -n 5 data/processed/newsletter_train_data.jsonl
Fine-Tuning
Option 1: Tinker API (Recommended)
# See notebooks/News_Analyst_1_Notebook.ipynb for complete workflow
# Training time: ~2.65 minutes for 3 epochs
Option 2: Unsloth (Local)
# See notebooks/News_Analyst_1_Notebook.ipynb for complete workflow
# Training time: ~0.94 minutes for 3 epochs
Inference
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
# Load base model
base_model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.2-1B")
# Load LoRA adapter
model = PeftModel.from_pretrained(base_model, "models/tinker/")
model = model.merge_and_unload()
# Load tokenizer
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-3.2-1B")
# Run inference
newsletter = "Your newsletter text here..."
inputs = tokenizer(newsletter, return_tensors="pt")
outputs = model.generate(**inputs, max_new_tokens=500)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(response)
π Project Structure
newsletter-finetuning/
βββ README.md # This file
βββ LICENSE # MIT License
βββ .gitignore # Git ignore rules
βββ requirements.txt # Python dependencies
β
βββ notebooks/
β βββ News_Analyst_1_Notebook.ipynb # Main fine-tuning workflow
β βββ JSONL_Annotation_Notebook_Final.ipynb # Annotation tool
β
βββ scripts/
β βββ news_analyst_1_notebook.py # Python script version
β
βββ data/
β βββ processed/
β βββ newsletter_train_data.jsonl # Training data (101 examples)
β βββ newsletter_test_data.jsonl # Test data (20 examples)
β
βββ models/
β βββ tinker/ # Tinker LoRA adapter
β βββ unsloth/ # Unsloth LoRA adapter
β βββ baseline/ # Base model info
β
βββ results/
β βββ metrics/ # Evaluation metrics
β βββ visualizations/ # Charts and graphs
β βββ reports/ # Evaluation reports
β
βββ docs/
βββ NEWS_ANALYST_SYSTEM_ARCHITECTURE.md # Production system overview
βββ LORA_COMPARISON.md # LoRA vs full fine-tuning
βββ FINE_TUNING_CONFIGURATION.md # Model configuration
βββ EVALUATION_METHODOLOGY.md # Evaluation metrics
βββ DATA_PREPARATION.md # Data annotation process
βββ TINKER_TRAINING_GUIDE.md # Tinker API guide
βββ MODEL_DEPLOYMENT.md # Deployment instructions
βββ TROUBLESHOOTING.md # Common issues and fixes
π Documentation
Core Documentation
- System Architecture - How this fits into the larger news analyst system
- LoRA Comparison - Why LoRA was chosen over full fine-tuning
- Fine-Tuning Configuration - Model and training parameters
Guides
- Data Preparation - Annotation process and data formatting
- Tinker Training - Using Tinker API for fine-tuning
- Model Deployment - Local deployment instructions
- Evaluation Methodology - Metrics and evaluation process
- Troubleshooting - Common issues and solutions
π οΈ Technologies Used
- Base Model: LLaMA 3.2-1B by Meta AI
- Fine-Tuning Method: LoRA (Low-Rank Adaptation) via PEFT
- Training Platforms:
- Tinker API - Managed fine-tuning service
- Unsloth - Optimized local fine-tuning
- Evaluation: ROUGE, BERTScore, Sentence-BERT, JSON schema validation
- Deployment: Local inference with Transformers
π€ Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π Acknowledgments
- Meta AI for LLaMA 3.2-1B base model
- Thinking Machines for Tinker API managed fine-tuning service
- Unsloth for optimized local fine-tuning library
- Hugging Face for Transformers and PEFT libraries
π§ Contact
Aaron (Youshen) Lim - @youshen-lim
Project Link: https://github.com/youshen-lim/llama-tinker-lora-newsletter
β If you find this project useful, please consider giving it a star!
- Downloads last month
- 19
Model tree for Truthseeker87/llama-tinker-lora-news-enhancer
Base model
meta-llama/Llama-3.2-1B
