File size: 6,704 Bytes
8b4aa88
66d4b44
 
 
f62675d
66d4b44
 
 
 
 
 
 
 
 
f62675d
66d4b44
 
 
f62675d
66d4b44
 
 
 
 
 
 
 
 
f62675d
66d4b44
f62675d
66d4b44
 
 
 
 
 
 
 
 
f62675d
 
 
 
 
 
66d4b44
 
 
f62675d
66d4b44
 
 
 
 
 
 
 
 
 
f62675d
66d4b44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f62675d
66d4b44
f62675d
66d4b44
 
 
 
 
 
 
 
 
 
 
 
f62675d
66d4b44
f62675d
 
66d4b44
 
f62675d
 
66d4b44
 
 
 
 
f62675d
 
 
66d4b44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f62675d
 
66d4b44
 
 
 
 
 
f62675d
 
 
66d4b44
f62675d
 
66d4b44
f62675d
 
 
 
 
 
66d4b44
f62675d
 
 
 
 
 
 
 
 
 
66d4b44
f62675d
 
66d4b44
 
f62675d
 
 
 
66d4b44
 
 
 
 
 
 
 
f62675d
 
66d4b44
 
 
 
f62675d
66d4b44
 
 
 
 
 
 
 
 
 
 
 
f62675d
66d4b44
 
f62675d
 
 
 
66d4b44
f62675d
66d4b44
 
f62675d
 
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
# Sage

Sage is a custom-built transformer language model designed for text generation tasks. This model demonstrates the full lifecycle of building and publishing a custom AI model to Hugging Face.

## Model Overview

- **Model Type**: Transformer-based language model
- **Architecture**: Decoder-only transformer
- **Vocabulary Size**: 40 characters
- **Hidden Size**: 256
- **Number of Layers**: 4
- **Number of Attention Heads**: 8
- **Feedforward Size**: 1024
- **Max Sequence Length**: 64
- **Parameters**: ~3,195,944
- **Training Framework**: PyTorch
- **License**: MIT

## Training Data

Sage was trained on a curated dataset of example sentences covering:
- Conversational phrases and greetings
- Weather and environmental descriptions
- Machine learning and AI concepts
- Deep learning architectures (transformers, neural networks)
- Natural language processing applications
- Model development and deployment practices

The dataset consists of 10 examples designed to teach the model patterns in technical and conversational English.

## Technical Specifications

### Model Architecture
```
TransformerLM(
  (embedding): Embedding(40, 256)
  (pos_embedding): Embedding(64, 256)
  (transformer_encoder): TransformerEncoder(
    (layers): ModuleList(
      (0-3): TransformerEncoderLayer(
        (self_attn): MultiheadAttention(embed_dim=256, num_heads=8)
        (linear1): Linear(256, 1024)
        (linear2): Linear(1024, 256)
        (norm1): LayerNorm(256)
        (norm2): LayerNorm(256)
        (dropout): Dropout(p=0.1)
      )
    )
  )
  (output_layer): Linear(256, 40)
)
```

### Tokenization
Sage uses a character-level tokenizer with:
- Vocabulary: 40 unique characters including special tokens
- Special tokens: `<PAD>` (0), `<UNK>` (1)
- Encoding: UTF-8 character mapping
- Maximum sequence length: 64 tokens

## Usage

### With Transformers Library
```python
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

model_name = "itriedcoding/Sage"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

def generate_text(prompt, max_length=50, temperature=0.8):
    inputs = tokenizer.encode(prompt, return_tensors="pt")
    with torch.no_grad():
        outputs = model.generate(
            inputs,
            max_length=max_length,
            temperature=temperature,
            do_sample=True,
            pad_token_id=tokenizer.eos_token_id
        )
    return tokenizer.decode(outputs[0], skip_special_tokens=True)

print(generate_text("Hello"))
print(generate_text("Deep learning"))
```

### Direct PyTorch Usage
```python
import torch
from modeling_transformer_lm import TransformerLM

model = TransformerLM.from_pretrained("itriedcoding/Sage")
```

## Model Card Metadata

```
library_name: transformers
license: MIT
base_model: custom-built
tags:
- text-generation
- transformer
- character-level
- custom-model
- educational
pipeline_tag: text-generation
```

## Hugging Face Spaces Deployment

You can run Sage in the dedicated Hugging Face Space:
https://huggingface.co/spaces/itriedcoding/sage-space

### Gradio Space
The Space at `itriedcoding/sage-space` provides a Gradio interface for text generation.
Create a new Space with `app.py`:
```python
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

model_name = "itriedcoding/Sage"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

def generate_text(prompt, max_length, temperature):
    inputs = tokenizer.encode(prompt, return_tensors="pt")
    with torch.no_grad():
        outputs = model.generate(
            inputs,
            max_length=int(max_length),
            temperature=temperature,
            do_sample=True,
            pad_token_id=tokenizer.eos_token_id
        )
    return tokenizer.decode(outputs[0], skip_special_tokens=True)

demo = gr.Interface(
    fn=generate_text,
    inputs=[
        gr.Textbox(label="Prompt", value="Hello"),
        gr.Slider(minimum=10, maximum=100, value=30, label="Max Length"),
        gr.Slider(minimum=0.1, maximum=2.0, value=0.8, label="Temperature")
    ],
    outputs=gr.Textbox(label="Generated Text"),
    title="Sage Text Generator",
    description="Custom character-level language model"
)

if __name__ == "__main__":
    demo.launch()
```

## GGUF Format

Sage is available in GGUF format as `sage-f16.gguf`.

### Compatibility Warning
Sage uses a custom `transformer_lm` architecture that is NOT supported by standard llama.cpp or llama-cpp-python. The GGUF file is provided as a reference format and for custom inference implementations that can match Sage's architecture.

### File Details
- **File**: `sage-f16.gguf` (12.7 MB)
- **Format**: GGUF (GGML Universal Format)
- **Precision**: Float16
- **Tensors**: 52 layers
- **Architecture**: `transformer_lm` (custom)

### Using with Custom Inference
To use this GGUF file, you need a GGUF loader that supports Sage's custom architecture:
```python
import gguf
import torch
import numpy as np

# Load GGUF file
reader = gguf.GGUFReader("sage-f16.gguf")
tensors = {t.name: torch.from_numpy(t.data) for t in reader.tensors}

# Map tensor names back to Sage architecture
# See gguf_convert.py for the tensor name mapping
```

### GGUF Conversion
The conversion script `gguf_convert.py` is included in this repository. It uses the `gguf` Python library to convert the PyTorch checkpoint to GGUF format.

## Performance & Limitations

### Intended Use
- Educational demonstrations of transformer architectures
- Character-level language modeling experiments
- Prototyping and testing custom model pipelines
- Learning about model deployment on Hugging Face

### Limitations
- Character-level tokenization limits coherence
- Small training dataset (10 examples)
- Small model size (3.2M parameters)
- Not suitable for production NLP applications
- Best for short text generation (<50 tokens)

## Citation

```bibtex
@misc{sage_model_2026,
  author = {itriedcoding},
  title = {Sage: Custom Character-Level Language Model},
  year = {2026},
  publisher = {Hugging Face},
  journal = {Hugging Face Model Hub},
  url = {https://huggingface.co/itriedcoding/Sage}
}
```

## Training Reproducibility

To reproduce this model:
1. Clone the repository
2. Install requirements: `pip install torch pandas`
3. Run training: The model was trained using the script in `train_model.py`
4. The trained checkpoint is saved as a PyTorch .pth file

## Contact

- Hugging Face: https://huggingface.co/itriedcoding
- Model Space: https://huggingface.co/spaces/itriedcoding/sage-space
- Issues: Use the "Issues" tab on this model page