Update README
Browse files
README.md
CHANGED
|
@@ -1,111 +1,88 @@
|
|
|
|
|
| 1 |
language:
|
| 2 |
-
|
| 3 |
-
|
| 4 |
tags:
|
| 5 |
-
amharic
|
| 6 |
-
word-embeddings
|
| 7 |
-
skip-gram
|
| 8 |
-
natural-language-processing
|
| 9 |
-
from-scratch
|
| 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 |
-
model
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
Small experiments with Amharic word-context relationships.
|
| 89 |
-
A starting point for further experimentation with Ethiopian-language NLP.
|
| 90 |
-
Limitations
|
| 91 |
-
The corpus is small, and the vocabulary contains only 271 unique words.
|
| 92 |
-
The embedding dimension is only 10.
|
| 93 |
-
Nearest neighbors can be noisy and may reflect local context or grammatical patterns rather than semantic similarity.
|
| 94 |
-
The model has not been evaluated on a held-out benchmark or downstream NLP task.
|
| 95 |
-
This is an educational prototype, not a production-ready or general-purpose Amharic language model.
|
| 96 |
-
Words not present in the vocabulary cannot be queried.
|
| 97 |
-
Dataset and reproducibility
|
| 98 |
-
|
| 99 |
-
The model was trained on a small Amharic corpus organized around multiple everyday topics. The vocabulary, preprocessing, pair-generation logic, model implementation, and training configuration are documented in the project source code.
|
| 100 |
-
|
| 101 |
-
Training configuration: window size 2, embedding dimension 10, learning rate 0.05, maximum epochs 50, and random seed 42.
|
| 102 |
-
|
| 103 |
-
Future work
|
| 104 |
-
Expand the corpus with diverse, properly licensed Amharic text.
|
| 105 |
-
Evaluate on held-out text and compare multiple context-window sizes and embedding dimensions.
|
| 106 |
-
Compare nearest neighbors with judgments from fluent Amharic speakers.
|
| 107 |
-
Add a reproducible training-loss plot and configuration comparison.
|
| 108 |
-
Explore subword handling and improved Amharic text normalization.
|
| 109 |
-
Acknowledgment
|
| 110 |
-
|
| 111 |
-
Built as an educational assignment to understand and implement Skip-gram word embeddings from first principles.
|
|
|
|
| 1 |
+
---
|
| 2 |
language:
|
| 3 |
+
- am
|
| 4 |
+
license: mit
|
| 5 |
tags:
|
| 6 |
+
- amharic
|
| 7 |
+
- word-embeddings
|
| 8 |
+
- skip-gram
|
| 9 |
+
- natural-language-processing
|
| 10 |
+
- from-scratch
|
| 11 |
+
- custom-implementation
|
| 12 |
+
metrics:
|
| 13 |
+
- loss
|
| 14 |
+
library_name: custom
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# Amharic Skip-gram Word Embeddings from Scratch
|
| 18 |
+
|
| 19 |
+
A lightweight, pure-Python implementation of a Skip-gram word embedding model trained on a small Amharic corpus. Built entirely from first principles without external numerical or machine learning libraries (no NumPy, PyTorch, or TensorFlow).
|
| 20 |
+
|
| 21 |
+
## Overview
|
| 22 |
+
|
| 23 |
+
This project implements a Skip-gram neural network to learn vector representations (word embeddings) for Amharic words. The primary goal is educational: to understand and verify the core mathematical foundations of word embeddings, including:
|
| 24 |
+
- Forward propagation and softmax distribution calculation
|
| 25 |
+
- Cross-entropy loss formulation
|
| 26 |
+
- Analytical gradient derivation for input and output weight matrices
|
| 27 |
+
- Stochastic Gradient Descent (SGD) optimization from scratch
|
| 28 |
+
|
| 29 |
+
The implementation relies strictly on Python standard library modules (`math`, `random`, lists, and loops).
|
| 30 |
+
|
| 31 |
+
---
|
| 32 |
+
|
| 33 |
+
## Model Architecture & Training Parameters
|
| 34 |
+
|
| 35 |
+
| Hyperparameter | Value |
|
| 36 |
+
| :--- | :--- |
|
| 37 |
+
| **Language** | Amharic (`am`) |
|
| 38 |
+
| **Architecture** | Skip-gram with Softmax |
|
| 39 |
+
| **Vocabulary Size** | 271 unique tokens |
|
| 40 |
+
| **Training Pairs** | 1,976 |
|
| 41 |
+
| **Embedding Dimension** | 10 |
|
| 42 |
+
| **Context Window Size** | 2 |
|
| 43 |
+
| **Learning Rate** | 0.05 |
|
| 44 |
+
| **Maximum Epochs** | 50 |
|
| 45 |
+
| **Random Seed** | 42 |
|
| 46 |
+
| **Best Checkpoint** | Epoch 49 |
|
| 47 |
+
|
| 48 |
+
The model optimizes two matrices: an input embedding matrix $E$ and an output context weight matrix $U$. For a given center word, it predicts surrounding context words via a softmax probability distribution over the vocabulary.
|
| 49 |
+
|
| 50 |
+
---
|
| 51 |
+
|
| 52 |
+
## Training & Validation Results
|
| 53 |
+
|
| 54 |
+
| Metric | Result |
|
| 55 |
+
| :--- | :--- |
|
| 56 |
+
| **Initial Mean Training Loss** | 5.602120 |
|
| 57 |
+
| **Best Mean Training Loss** | 2.798836 |
|
| 58 |
+
| **Best Epoch** | 49 |
|
| 59 |
+
| **Epochs Executed** | 50 |
|
| 60 |
+
| **Max Absolute Gradient-Check Error** | 0.00000000 |
|
| 61 |
+
|
| 62 |
+
> **Note:** The best mean training loss achieved a ~50% reduction from the initial loss. Epoch 49 was selected via early checkpointing as epoch 50 yielded a slightly higher loss value. These metrics validate implementation correctness on the training split and do not reflect generalization performance on unseen text.
|
| 63 |
+
|
| 64 |
+
---
|
| 65 |
+
|
| 66 |
+
## Implementation & Correctness Checks
|
| 67 |
+
|
| 68 |
+
The model passed a rigorous suite of mathematical and algorithmic unit tests:
|
| 69 |
+
|
| 70 |
+
- [x] **Data Processing:** Correct context-window pair generation with strict sentence-boundary protection.
|
| 71 |
+
- [x] **Forward & Loss Verification:** Forward scores, softmax probabilities, and cross-entropy loss validated against manual reference calculations.
|
| 72 |
+
- [x] **Analytical Gradients:** Exact match with expected symbolic gradients.
|
| 73 |
+
- [x] **SGD Updates:** Verified parameter updates, ensuring non-context input embedding rows remain unmodified during sparse updates.
|
| 74 |
+
- [x] **Numerical Stability:** Verified stability under extreme score magnitudes and shift invariance ($\text{softmax}(z) = \text{softmax}(z + c)$).
|
| 75 |
+
- [x] **Gradient Checking:** Finite-difference numerical gradient verification ($\epsilon = 10^{-5}$).
|
| 76 |
+
- [x] **Edge Cases:** Safe cosine similarity evaluation for zero-norm vectors.
|
| 77 |
+
- [x] **Serialization:** Full JSON round-trip consistency for vocabulary mapping, weight arrays, and nearest-neighbor outputs.
|
| 78 |
+
|
| 79 |
+
---
|
| 80 |
+
|
| 81 |
+
## Usage
|
| 82 |
+
|
| 83 |
+
This model uses a custom Python execution format rather than Hugging Face `transformers`. Download `amharic_skipgram.json` alongside your `model.py` script to run inference.
|
| 84 |
+
|
| 85 |
+
### Python Code Example
|
| 86 |
+
|
| 87 |
+
```python
|
| 88 |
+
from model import SkipGramModel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|