30 lines
1.2 KiB
Markdown
30 lines
1.2 KiB
Markdown
# 📉 AIRA Loss Functions (`ai/loss`)
|
|
|
|
[](https://github.com/adameehanairagroup/Airalang)
|
|
[](https://github.com/adameehanairagroup/Airalang)
|
|
|
|
Loss functions calculate the scalar discrepancy between model predictions and ground-truth targets, guiding gradient backpropagation.
|
|
|
|
---
|
|
|
|
## 📐 Implemented Loss Functions
|
|
|
|
### 1. `CrossEntropyLoss` (Classification & Next-Token LLM Training)
|
|
$$\mathcal{L} = -\sum_{i} y_i \log(\hat{y}_i)$$
|
|
Utilizes numerically stable Log-Softmax with max-subtraction to prevent floating-point underflow:
|
|
|
|
```aira
|
|
import "ai/loss";
|
|
|
|
let criterion = new CrossEntropyLoss();
|
|
let loss = criterion.forward(logits, target_class);
|
|
loss.backward(); // Propagates dL/dLogits back into model layers
|
|
```
|
|
|
|
### 2. `MSELoss` (Mean Squared Error)
|
|
$$\mathcal{L} = rac{1}{N} \sum_{i=1}^N (y_i - \hat{y}_i)^2$$
|
|
Ideal for continuous regression, coordinate prediction, and Diffusion noise estimation.
|
|
|
|
### 3. `BCEWithLogitsLoss`
|
|
Binary cross-entropy combining a sigmoid activation and cross-entropy for numerical stability in multi-label classification.
|