docs(ai): Comprehensive AI Developer Handbook & Submodule Guides — Training from Scratch in Pure .aira
This commit is contained in:
1 parent
44ad01a87d
commit
a690296e7c
10 files changed
+431
-15
No files matched your search
@@ -0,0 +1,35 @@
|
||||
# 🎯 AIRA Attention Mechanisms (`ai/attention`)
|
||||
|
||||
[](https://github.com/adameehanairagroup/Airalang)
|
||||
[](https://github.com/adameehanairagroup/Airalang)
|
||||
[](https://github.com/adameehanairagroup)
|
||||
|
||||
The `ai/attention` package provides native implementations of modern self-attention and cross-attention architectures.
|
||||
|
||||
---
|
||||
|
||||
## 🧮 Mathematical Formulation
|
||||
|
||||
### Scaled Dot-Product Attention
|
||||
$$ ext{Attention}(Q, K, V) = ext{softmax}\left(rac{Q K^T}{\sqrt{d_k}}␍ight) V$$
|
||||
|
||||
In pure `.aira`:
|
||||
|
||||
```aira
|
||||
import "ai/attention";
|
||||
|
||||
// Instantiate MultiHeadAttention with 8 heads across 512 dimensions
|
||||
let mha = new MultiHeadAttention(512, 8);
|
||||
|
||||
// Forward pass: Query, Key, Value, and Causal Attention Mask
|
||||
let context_vectors = mha.forward(Q, K, V, causal_mask);
|
||||
```
|
||||
|
||||
### Rotary Positional Embeddings (RoPE)
|
||||
Enables transformers to dynamically encode relative token positions without hard positional tables:
|
||||
|
||||
```aira
|
||||
let rope = new RotaryEmbedding(dim_per_head=64, max_seq_len=4096);
|
||||
let q_rotated = rope.apply(Q, position_ids);
|
||||
let k_rotated = rope.apply(K, position_ids);
|
||||
```
|
||||
Reference in new issue
Block a user