File size: 8,663 Bytes
c9e8126 1313459 c9e8126 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | # ZRIA-Ultimate-PFAF: Advanced Cognitive Architecture
A sophisticated neural architecture that implements dual-path processing for knowledge-based reasoning and execution-based tasks, with persistent model capabilities for large-scale text processing.
## ๐ง Architecture Overview
The ZRIA (ZRIA-Ultimate with Probabilistic Fractal Attentional Fusion) system implements:
- **Dual-Path Processing**: Separate knowledge and execution pathways
- **Dynamic Attention**: Content-aware fractal attention mechanisms
- **Quantum-Inspired Fusion**: Complex number operations for phase relationships
- **Hierarchical Memory**: Multi-scale memory systems
- **Persistent Models**: Save and reuse without retraining
## ๐ Key Features
### 1. Large Text File Processing
- **Automatic Breakdown**: Process multiple books worth of data
- **Hierarchical Categorization**: FACT, CONCEPT, PROCEDURE, RELATIONSHIP, etc.
- **Entity Extraction**: Named entities and relationships
- **Sentiment Analysis**: Built-in sentiment classification
- **Confidence Scoring**: Quality assessment of extracted knowledge
### 2. Persistent Model System
- **Save Once, Use Forever**: Train once, use repeatedly
- **Interactive Prompting**: Real-time interaction without retraining
- **Batch Processing**: Handle multiple inputs efficiently
- **Auto-Routing**: Intelligent task type detection
### 3. Advanced Cognitive Components
- **Fractal Attentional Resonance**: Dynamic, content-aware attention
- **Quantum-Inspired Fusion**: Complex-valued representations
- **Hierarchical Memory**: Multi-scale temporal patterns
- **Neural ODE**: Continuous-time dynamics
## ๐ File Structure
```
โโโ ae.py # Core ZRIA model architecture
โโโ text_processor.py # Large text file processing
โโโ persistent_model.py # Persistent model system
โโโ example_usage.py # Complete usage demonstration
โโโ requirements.txt # Dependencies
โโโ README.md # This file
```
## ๐ ๏ธ Installation
1. **Install Dependencies**:
```bash
pip install -r requirements.txt
```
2. **Download spaCy Model**:
```bash
python -m spacy download en_core_web_sm
```
3. **Download NLTK Data** (automatic on first run):
```python
import nltk
nltk.download('punkt')
nltk.download('stopwords')
nltk.download('wordnet')
```
## ๐ฏ Quick Start
### 1. Process Large Text Files
```python
from text_processor import HierarchicalTextProcessor
# Initialize processor
processor = HierarchicalTextProcessor()
# Process a large text file
knowledge = processor.process_large_text_file("your_large_text_file.txt")
# Create training data
training_data = processor.create_training_data(knowledge)
# Save knowledge base
processor.save_knowledge_base(knowledge, "knowledge_base.pkl")
```
### 2. Train and Save Model
```python
from persistent_model import create_and_train_model_from_text_file
# Train model from text file
model = create_and_train_model_from_text_file("your_large_text_file.txt", "my_model")
```
### 3. Use Persistent Model
```python
from persistent_model import load_and_use_model
# Load trained model
model = load_and_use_model("my_model")
# Interactive prompting
result = model.prompt("artificial intelligence is amazing", 'auto')
print(f"Task: {result['task_type']}")
print(f"Prediction: {result['prediction']}")
# Start interactive mode
model.interactive_mode()
```
## ๐ Knowledge Categories
The system automatically categorizes text into:
- **FACT**: Factual statements, definitions, data
- **CONCEPT**: Abstract concepts, theories, ideas
- **PROCEDURE**: How-to instructions, methods, steps
- **RELATIONSHIP**: Connections, comparisons, associations
- **ATTRIBUTE**: Properties, characteristics, qualities
- **EVENT**: Historical events, occurrences, timelines
- **LOCATION**: Places, geographical information
- **PERSON**: People, characters, entities
## ๐ Complete Pipeline Example
```python
# Run the complete demonstration
python example_usage.py
```
This will:
1. Create a sample large text file
2. Process it into structured knowledge
3. Train the ZRIA model
4. Demonstrate interactive usage
5. Show batch processing capabilities
## ๐ฎ Interactive Usage
Once you have a trained model, you can use it interactively:
```bash
python persistent_model.py load my_model
```
Then you can:
- Type `KNOW <text>` for sentiment analysis
- Type `DO <text>` for action tasks
- Type `AUTO <text>` for automatic routing
- Type `help` for commands
- Type `quit` to exit
## ๐ง Advanced Usage
### Custom Model Configuration
```python
from persistent_model import PersistentZRIAModel
model = PersistentZRIAModel("custom_model")
# Custom configuration
config = {
'dim': 256, # Model dimension
'max_seq_len': 128, # Maximum sequence length
'action_dim': 1, # Action output dimension
'batch_size': 32, # Training batch size
'epochs': 200, # Training epochs
'learning_rate': 1e-4, # Learning rate
'weight_decay': 0.01 # Weight decay
}
model.train_and_save(training_data, config)
```
### Batch Processing
```python
# Process multiple texts at once
texts = [
"artificial intelligence is revolutionary",
"count vowels in this example",
"machine learning is difficult"
]
results = model.batch_prompt(texts, 'auto')
for text, result in zip(texts, results):
print(f"{text}: {result['prediction']}")
```
### Knowledge Base Analysis
```python
from text_processor import HierarchicalTextProcessor
processor = HierarchicalTextProcessor("knowledge_base.pkl")
summary = processor.get_knowledge_summary()
print(f"Total items: {summary['total_items']}")
print(f"Categories: {summary['categories']}")
print(f"Entities: {summary['entities']}")
```
## ๐งช Model Architecture Details
### Fractal Attentional Resonance
- **Dynamic Bias Generation**: Content-aware attention biases
- **Fractal Mathematics**: Multiple mathematical transformations
- **Multi-Head Attention**: Enhanced with fractal resonance
### Quantum-Inspired Fusion
- **Complex Number Operations**: Real and imaginary components
- **Entanglement Gates**: Quantum-inspired transformations
- **Phase Relationships**: Captures complex interactions
### Hierarchical Memory System
- **Multi-Scale Memory**: 32, 16, 8 token scales
- **Attention-Based Retrieval**: Context-aware memory access
- **GRU Consolidation**: Temporal pattern integration
## ๐ Performance Considerations
### Memory Usage
- **Large Text Files**: Process in chunks (default: 10,000 chars)
- **Model Size**: ~128MB for default configuration
- **GPU Acceleration**: Automatic CUDA detection
### Processing Speed
- **Text Processing**: ~1000 sentences/minute
- **Model Inference**: ~1000 predictions/second
- **Training**: ~150 epochs for convergence
## ๐ Troubleshooting
### Common Issues
1. **spaCy Model Not Found**:
```bash
python -m spacy download en_core_web_sm
```
2. **NLTK Data Missing**:
```python
import nltk
nltk.download('punkt')
nltk.download('stopwords')
nltk.download('wordnet')
```
3. **CUDA Out of Memory**:
```python
# Use CPU instead
device = 'cpu'
```
4. **Large File Processing**:
```python
# Reduce chunk size
knowledge = processor.process_large_text_file("file.txt", chunk_size=5000)
```
## ๐ค Contributing
This system is designed for:
- **Large-scale text processing**
- **Persistent model deployment**
- **Interactive AI systems**
- **Research in cognitive architectures**
## ๐ License
This project implements advanced neural architectures for research and educational purposes.
## ๐ฏ Use Cases
### Research Applications
- **Cognitive Architecture Research**: Study dual-path processing
- **Large-Scale Text Analysis**: Process entire libraries
- **Interactive AI Systems**: Real-time prompting
- **Knowledge Extraction**: Structured information extraction
### Practical Applications
- **Document Processing**: Large document analysis
- **Content Classification**: Automatic categorization
- **Sentiment Analysis**: Large-scale sentiment processing
- **Action Recognition**: Task identification and execution
---
**Note**: This system represents a sophisticated cognitive architecture that can handle both declarative knowledge and procedural execution tasks, with advanced mechanisms for integrating different types of processing. |