File size: 5,585 Bytes
7fa9242
 
 
 
 
 
 
 
 
 
 
 
 
 
7873cbc
7fa9242
 
 
 
 
 
 
 
c781996
7fa9242
 
 
 
 
 
 
 
 
 
7873cbc
 
 
 
030c272
7873cbc
7fa9242
 
 
030c272
9c45cbc
7fa9242
4c972d5
7fa9242
 
 
 
 
 
c781996
 
 
7fa9242
 
b25dc7b
c781996
 
 
7fa9242
 
 
 
9c45cbc
 
 
 
7fa9242
 
 
 
9c45cbc
 
 
7fa9242
7873cbc
 
9c45cbc
 
c781996
 
9fc6e13
9c45cbc
9fc6e13
 
9c45cbc
7873cbc
 
9c45cbc
7fa9242
 
 
 
 
 
 
 
9c45cbc
 
9fc6e13
7873cbc
 
c781996
9fc6e13
7fa9242
9fc6e13
 
 
 
7fa9242
 
9c45cbc
9fc6e13
 
9c45cbc
 
 
 
 
 
 
9fc6e13
7fa9242
9fc6e13
 
7fa9242
9fc6e13
7fa9242
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7873cbc
7fa9242
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7873cbc
7fa9242
 
 
 
 
 
 
 
 
 
 
 
9fc6e13
ea79706
7fa9242
 
 
 
 
 
 
 
 
7873cbc
7fa9242
 
 
 
 
 
 
 
 
 
 
 
 
 
c781996
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
---
language: en
license: mit
tags:
- image-classification
- imagenet
- multi-scale
- crystal-geometry
- david
datasets:
- imagenet-1k
metrics:
- accuracy
model-index:
- name: David-hierarchical-progressive
  results:
  - task:
      type: image-classification
    dataset:
      name: ImageNet-1K
      type: imagenet-1k
    metrics:
    - type: accuracy
      value: 76.81
---

# David: Multi-Scale Crystal Classifier

**David** is a multi-scale deep learning classifier that uses crystal geometry (pentachora/4-simplexes) 
as class prototypes with role-weighted similarity computation (Rose Loss).

## Model Details

### Architecture
- **Preset**: hierarchical_refinement
- **Sharing Mode**: hierarchical
- **Fusion Mode**: progressive
- **Scales**: [256, 512, 768, 1024]
- **Feature Dim**: 512
- **Parameters**: 10,493,184

### Training Configuration
- **Dataset**: AbstractPhil/imagenet-clip-features-orderly
- **Model Variant**: clip_vit_laion_b32
- **Epochs**: 10
- **Batch Size**: 1024
- **Learning Rate**: 0.001
- **Rose Loss Weight**: 0.1 β†’ 0.5
- **Cayley Loss**: False

## Performance

### Best Results
- **Validation Accuracy**: 76.81%
- **Best Epoch**: 7
- **Final Train Accuracy**: 88.98%

### Per-Scale Performance
- **Scale 256**: 70.05%
- **Scale 512**: 74.26%
- **Scale 768**: 75.67%
- **Scale 1024**: 75.56%


## Usage

### Quick Model Lookup

**Check `MODELS_INDEX.json` in the repo root** - it lists all trained models sorted by accuracy with links to weights and configs.

### Repository Structure

```
AbstractPhil/gated-david/
β”œβ”€β”€ MODELS_INDEX.json                # πŸ“Š Master index of all models (sorted by accuracy)
β”œβ”€β”€ README.md                         # This file
β”œβ”€β”€ best_model.json                   # Latest best model info
β”œβ”€β”€ weights/
β”‚   └── david_hierarchical/
β”‚       └── 20251012_145649/
β”‚           β”œβ”€β”€ MODEL_SUMMARY.txt     # 🎯 Human-readable performance summary
β”‚           β”œβ”€β”€ training_history.json # πŸ“ˆ Epoch-by-epoch training curve
β”‚           β”œβ”€β”€ best_model_acc76.81.safetensors  # ⭐ Accuracy in filename!
β”‚           β”œβ”€β”€ best_model_acc76.81_metadata.json
β”‚           β”œβ”€β”€ final_model.safetensors
β”‚           β”œβ”€β”€ checkpoint_epoch_X_accYY.YY.safetensors
β”‚           β”œβ”€β”€ david_config.json
β”‚           └── train_config.json
└── runs/
    └── david_hierarchical/
        └── 20251012_145649/
            └── events.out.tfevents.* # TensorBoard logs
```

### Loading the Model

```python
from geovocab2.train.model.core.david import David, DavidArchitectureConfig
from huggingface_hub import hf_hub_download

# Browse available models in MODELS_INDEX.json first!

# Specify model variant and run
model_name = "david_hierarchical"
run_id = "20251012_145649"
accuracy = "76.81"  # From MODELS_INDEX.json

# Download config
config_path = hf_hub_download(
    repo_id="AbstractPhil/gated-david", 
    filename=f"weights/{model_name}/{run_id}/david_config.json"
)
config = DavidArchitectureConfig.from_json(config_path)

# Download weights (accuracy in filename!)
weights_path = hf_hub_download(
    repo_id="AbstractPhil/gated-david", 
    filename=f"weights/{model_name}/{run_id}/best_model_acc{accuracy}.safetensors"
)

# Download training history (optional - see full training curve)
history_path = hf_hub_download(
    repo_id="AbstractPhil/gated-david", 
    filename=f"weights/{model_name}/{run_id}/training_history.json"
)

# Load model
from safetensors.torch import load_file
david = David.from_config(config)
david.load_state_dict(load_file(weights_path))
david.eval()
```

### Inference

```python
import torch
import torch.nn.functional as F

# Assuming you have CLIP features (512-dim for ViT-B/16)
features = get_clip_features(image)  # [1, 512]

# Load anchors
anchors_dict = torch.load("anchors.pth")

# Forward pass
with torch.no_grad():
    logits, _ = david(features, anchors_dict)
    predictions = logits.argmax(dim=-1)
```

## Architecture Overview

### Multi-Scale Processing
David processes inputs at multiple scales (256, 512, 768, 1024), 
allowing it to capture both coarse and fine-grained features.

### Crystal Geometry
Each class is represented by a pentachoron (4-simplex) in embedding space with 5 vertices:
- **Anchor**: Primary class representative
- **Need**: Complementary direction
- **Relation**: Contextual alignment
- **Purpose**: Functional direction
- **Observer**: Meta-perspective

### Rose Loss
Similarity computation uses role-weighted cosine similarities:
```
score = w_anchor * sim(z, anchor) + w_need * sim(z, need) + ...
```

### Fusion Strategy
**progressive**: Intelligently combines predictions from multiple scales.

## Training Details

### Loss Components
- **Cross-Entropy**: Standard classification loss
- **Rose Loss**: Pentachora role-weighted margin loss (weight: 0.1β†’0.5)
- **Cayley Loss**: Geometric regularization (disabled)

### Optimization
- **Optimizer**: AdamW
- **Weight Decay**: 1e-05
- **Scheduler**: cosine_restarts
- **Gradient Clip**: 10.0
- **Mixed Precision**: True

## Citation

```bibtex
@software{david_classifier_2025,
  title = {David: Multi-Scale Crystal Classifier},
  author = {AbstractPhil},
  year = {2025},
  url = {https://huggingface.co/AbstractPhil/gated-david},
  note = {Run ID: 20251012_145649}
}
```

## License

MIT License

## Acknowledgments

Built with crystal lattice geometry and multi-scale deep learning.
Special thanks to Claude (Anthropic) for debugging assistance.

---

*Generated on 2025-10-12 15:11:05*