naply-ai 1.0.0
Lightweight CPU-friendly framework for domain-specific AI
Requires Python: >=3.8
Keywords: ai, machine-learning, nlp, transformers, fine-tuning, cpu, lightweight

# NAPLY v1.0 - Lightweight Domain AI Framework

A simple, CPU-friendly framework for fine-tuning and deploying domain-specific language models.

**Status:** Early-stage project | **Focus:** Domain AI on CPU | **Goal:** Simple fine-tuning

---

## ⚠️ Important: What NAPLY Is and Isn't

### ✅ NAPLY Is Good For:
- Fine-tuning small models on domain data (medical, legal, code)
- CPU-based training (4-8GB RAM)
- Quick prototyping and deployment
- Domain-specific chatbots and assistants

### ❌ NAPLY Is NOT:
- A replacement for PyTorch (use PyTorch for research)
- For training GPT-4 scale models
- Better than TensorFlow for Google-scale systems
- A full ecosystem like HuggingFace

---

## 🎯 Realistic Use Cases

**Perfect for:**
1. Medical Q&A bot (fine-tuned on medical texts)
2. Legal document analyzer
3. Code completion assistant
4. Customer support automation
5. Educational tutoring system

**Not suitable for:**
- Training from scratch (use PyTorch)
- Large-scale GPU clusters (use TensorFlow)
- Research experiments (use PyTorch)

---

## 🚀 Quick Start

```python
import naply

# 1. Load a pre-trained model
model = naply.load("naply/gpt-small")

# 2. Enable efficient fine-tuning
model.enable_lora(rank=8)

# 3. Train on your domain data
model.finetune("medical_data.txt", epochs=3)

# 4. Generate text
response = model.generate("What are diabetes symptoms?")
print(response)

# 5. Save for later
model.save("medical_bot/")

# 6. Deploy as API (optional)
model.serve(port=8000)
```

---

## 📦 Available Models

| Model | Parameters | Size | Min RAM | Best For |
|-------|-----------|------|---------|----------|
| `naply/gpt-tiny` | 10M | 40MB | 2GB | Testing, debugging |
| `naply/gpt-small` | 50M | 200MB | 4GB | **Most use cases** |
| `naply/gpt-medium` | 100M | 400MB | 8GB | Better quality |

**Note:** These models don't exist yet. You would need to train them first.

---

## 💻 System Requirements

### Minimum:
- Python 3.8+
- 4GB RAM
- CPU (no GPU required)

### Recommended:
- Python 3.10+
- 8GB RAM
- Multi-core CPU

---

## 📊 Realistic Benchmarks

**Expected performance on CPU (4-core Intel i5):**

| Model | Training Speed | Inference Speed | Memory |
|-------|----------------|-----------------|---------|
| gpt-tiny | ~5 min/epoch | 20 tokens/sec | 2GB |
| gpt-small | ~20 min/epoch | 10 tokens/sec | 4GB |
| gpt-medium | ~60 min/epoch | 5 tokens/sec | 8GB |

**Note:** These are estimates. Actual performance varies by hardware.

---

## 🛠️ Installation

```bash
pip install naply
```

### Optional Dependencies:

For model serving:
```bash
pip install flask
```

For GPU support (if available):
```bash
pip install cupy
```

---

## 📚 API Reference

### Loading Models

```python
import naply

# From hub (when available)
model = naply.load("naply/gpt-small")

# From local path
model = naply.load("my_model/")

# Create new
model = naply.create("small")
```

### Fine-tuning

```python
# Enable LoRA (recommended)
model.enable_lora(rank=8)

# Train
model.finetune(
    data_path="data.txt",  # Text file, one sample per line
    epochs=3,
    batch_size=4,
    learning_rate=1e-4
)
```

### Generation

```python
response = model.generate(
    prompt="What is diabetes?",
    max_length=100,
    temperature=0.8
)
```

### Serving

```python
# Start API server
model.serve(port=8000)

# Then use:
# POST http://localhost:8000/generate
# {"prompt": "Hello!"}
```

---

## 🎓 Example Projects

### 1. Medical Assistant

```python
import naply

# Load model
model = naply.load("naply/gpt-small")

# Prepare medical data
# Create a file 'medical.txt' with medical Q&A pairs:
# Q: What is diabetes?
# A: Diabetes is a chronic condition...

# Fine-tune
model.enable_lora(rank=8)
model.finetune("medical.txt", epochs=3)

# Test
response = model.generate("What are diabetes symptoms?")
print(response)

# Save
model.save("medical_assistant/")
```

### 2. Code Helper

```python
import naply

model = naply.load("naply/gpt-small")
model.enable_lora(rank=8)
model.finetune("code_docs.txt", epochs=3)

# Ask coding questions
response = model.generate("How do I sort a list in Python?")
```

---

## ⚠️ Limitations

**Please read these carefully:**

1. **Small ecosystem**: Not as many pre-trained models as HuggingFace
2. **CPU-focused**: GPU support is basic
3. **Not for research**: Use PyTorch for novel architectures
4. **Limited models**: Only GPT-style transformers currently
5. **Early stage**: May have bugs and missing features
6. **Training from scratch**: Not recommended (use pre-trained + fine-tune)

---

## 🔍 Comparison with Other Frameworks

| Feature | NAPLY | PyTorch | HuggingFace | TensorFlow |
|---------|-------|---------|-------------|------------|
| **Ease of Use** | ⭐⭐⭐⭐⭐ | ⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐ |
| **Ecosystem** | ⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ |
| **CPU Training** | ⭐⭐⭐⭐⭐ | ⭐ | ⭐ | ⭐ |
| **Research** | ⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐ |
| **Production** | ⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐ | ⭐⭐⭐⭐⭐ |
| **Model Variety** | ⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ |

**Choose based on your needs:**
- **NAPLY**: Quick domain AI on CPU
- **PyTorch**: Research and custom models
- **HuggingFace**: Use existing NLP models
- **TensorFlow**: Production at scale

---

## 🐛 Troubleshooting

### Out of Memory
- Use `naply/gpt-tiny` instead of larger models
- Reduce batch_size to 1 or 2
- Enable LoRA (saves 50% memory)

### Slow Training
- Use smaller model
- Reduce sequence length in data
- Ensure data is clean (no duplicates)

### Poor Results
- Train for more epochs (4-5)
- Clean your training data
- Add more training examples
- Try larger model if RAM allows

---

## 🤝 Contributing

This is an early-stage project. Contributions welcome:

- Bug reports
- Documentation improvements
- Example projects
- Pre-trained models
- Performance optimizations

---

## 📄 License

MIT License

---

## 🙏 Acknowledgments

NAPLY is inspired by:
- PyTorch (dynamic graphs)
- HuggingFace Transformers (ease of use)
- LoRA paper (efficient fine-tuning)

**This is not a replacement for these frameworks, but a simpler alternative for specific use cases.**

---

**Status:** Early development | **Use at your own risk** | **Feedback welcome**