Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,95 @@
|
|
|
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
---
|
| 3 |
license: apache-2.0
|
| 4 |
+
tags:
|
| 5 |
+
- slm
|
| 6 |
+
- custom-code
|
| 7 |
+
- micro-model
|
| 8 |
+
- in-context-learning
|
| 9 |
+
pipeline_tag: text-generation
|
| 10 |
---
|
| 11 |
+
|
| 12 |
+
# ApproxDumb (560-Parameter Micro-SLM)
|
| 13 |
+
|
| 14 |
+
`ApproxDumb` is an ultra-micro language model built with just **560 parameters**.
|
| 15 |
+
It serves as a proof-of-concept for **In-Context Learning (ICL)** in micro-architectures, demonstrating how a model can infer underlying rules (such as dynamic addition patterns) on-the-fly from a single provided example.
|
| 16 |
+
|
| 17 |
+
---
|
| 18 |
+
|
| 19 |
+
## ⚠️ Input & Output Constraints
|
| 20 |
+
|
| 21 |
+
Due to the extreme parameter budget, this model **cannot** process natural language text or complex multi-digit arithmetic. Please strictly adhere to the following input and output specifications.
|
| 22 |
+
|
| 23 |
+
### 1. Input Constraints
|
| 24 |
+
- **Allowed Vocabulary**:
|
| 25 |
+
- **Single Digits**: `0`, `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`
|
| 26 |
+
- **Separator**: `->`
|
| 27 |
+
- **Special Tokens**: `<bos>`, `<eos>`, `<pad>`
|
| 28 |
+
- *Note: Words, letters, multi-digit numbers (e.g., 10, 100), or unsupported punctuation are **NOT** allowed.*
|
| 29 |
+
- **Formatting**:
|
| 30 |
+
- Tokens **must be separated by half-width spaces** (e.g., `"1 3 -> 4"`).
|
| 31 |
+
- Recommended Prompt Structure: `[Example Input] [Example Output] -> [Query Input]` (Total of 4 tokens).
|
| 32 |
+
- **Max Sequence Length**: **8 tokens** (4 to 5 tokens recommended).
|
| 33 |
+
|
| 34 |
+
### 2. Output Constraints
|
| 35 |
+
- **Output Format**: The model predicts the probability distribution (logits) for the **next single digit token (`0`–`9`)**.
|
| 36 |
+
- **Limitations**:
|
| 37 |
+
- Cannot generate multi-digit numbers ($\ge 10$) or negative numbers.
|
| 38 |
+
- Not designed for multi-token free-form text generation (specialized for single next-token prediction).
|
| 39 |
+
|
| 40 |
+
---
|
| 41 |
+
|
| 42 |
+
## 💡 Prompt Examples
|
| 43 |
+
|
| 44 |
+
By providing a single "Example", the model infers the rule and predicts the answer for the "Query".
|
| 45 |
+
|
| 46 |
+
| Prompt (`input_text`) | Inferred Rule | Expected Prediction |
|
| 47 |
+
| :--- | :--- | :--- |
|
| 48 |
+
| `"1 2 -> 4"` | $+1$ rule | **`5`** |
|
| 49 |
+
| `"1 3 -> 4"` | $+2$ rule | **`6`** |
|
| 50 |
+
| `"1 4 -> 2"` | $+3$ rule | **`5`** |
|
| 51 |
+
| `"0 4 -> 1"` | $+4$ rule | **`5`** |
|
| 52 |
+
|
| 53 |
+
---
|
| 54 |
+
|
| 55 |
+
## 🚀 How to Use
|
| 56 |
+
|
| 57 |
+
Make sure to pass `trust_remote_code=True` when loading the model and tokenizer.
|
| 58 |
+
|
| 59 |
+
```python
|
| 60 |
+
import torch
|
| 61 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 62 |
+
|
| 63 |
+
# Load model and tokenizer
|
| 64 |
+
model_id = "56m/ApproxDumb" # Replace with your Hugging Face repository
|
| 65 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
|
| 66 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, trust_remote_code=True)
|
| 67 |
+
|
| 68 |
+
# Prepare prompt: Example "1 -> 3" (+2 rule), Query "4 -> ?"
|
| 69 |
+
prompt = "1 3 -> 4"
|
| 70 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 71 |
+
|
| 72 |
+
# Inference
|
| 73 |
+
model.eval()
|
| 74 |
+
with torch.no_grad():
|
| 75 |
+
outputs = model(**inputs)
|
| 76 |
+
|
| 77 |
+
# Extract the most probable next digit token from the final position
|
| 78 |
+
next_token_logits = outputs.logits[0, -1, :]
|
| 79 |
+
predicted_token_id = torch.argmax(next_token_logits).item()
|
| 80 |
+
predicted_symbol = tokenizer.decode([predicted_token_id])
|
| 81 |
+
|
| 82 |
+
print(f"Input: '{prompt}'")
|
| 83 |
+
print(f"Predicted Next Digit: {predicted_symbol}")
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
---
|
| 87 |
+
|
| 88 |
+
## 🏗️ Model Architecture
|
| 89 |
+
|
| 90 |
+
- **Architecture**: Decoder-only Micro-Transformer
|
| 91 |
+
- **Total Parameters**: 560
|
| 92 |
+
- **Embedding Dimension ($d_{model}$)**: 6
|
| 93 |
+
- **Transformer Layers**: 1
|
| 94 |
+
- **Attention Heads**: 1
|
| 95 |
+
- **Vocabulary Size**: 14
|