xezpeleta commited on
Commit
c5b3d7a
·
verified ·
1 Parent(s): ad4ed19

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +51 -19
README.md CHANGED
@@ -14,14 +14,14 @@ tags:
14
  pipeline_tag: text-generation
15
  ---
16
 
17
- # Morpheus v2 (Mamba-2) — Basque Autocomplete
18
 
19
- A 91M-parameter Mamba-2 language model for on-device Basque (Euskara) text autocompletion.
20
 
21
  ## Model Details
22
 
23
- - **Architecture:** Mamba-2 (State Space Model)
24
- - **Parameters:** 91M
25
  - **Embedding vocab:** 4,000 (Unigram SentencePiece)
26
  - **Hidden dimension:** 768
27
  - **Layers:** 24
@@ -29,38 +29,70 @@ A 91M-parameter Mamba-2 language model for on-device Basque (Euskara) text autoc
29
  - **Head dimension:** 64
30
  - **Inner dimension:** 1,536
31
  - **Sequence length:** 1,024
32
- - **Training tokens:** ~10 billion
33
- - **Training steps:** 76,000 (best checkpoint at 74,000)
34
- - **Held-out PPL:** 7.13
35
- - **Trained without BOS token**
36
 
37
  ## Tokenizer
38
 
39
- A 4K Unigram SentencePiece tokenizer trained on the cleaned Basque corpus. The small vocabulary size was chosen based on evidence that lower vocab sizes achieve lower downstream perplexity for agglutinative low-resource languages (cf. QuechuaTok).
 
 
 
 
 
 
 
40
 
41
  - `add_bos_token: false` (the model was trained without a BOS token)
42
  - EOS token: `</s>` (id=2)
43
  - UNK token: `<unk>` (id=0)
44
 
45
- ## Intended Use
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
- On-device Basque text autocomplete and predictive keyboard input. The model is small enough to run on CPU via llama.cpp (see the GGUF quantized versions at [itzune/morpheus-gguf](https://huggingface.co/itzune/morpheus-gguf)).
 
 
 
 
 
 
48
 
49
  ## Training Data
50
 
51
- Trained on a ~22 GB cleaned Basque text corpus comprising Wikipedia, news (Berria), literature, and other web-crawled sources. The corpus underwent a multi-stage cleaning pipeline (deduplication, language filtering, quality auditing).
52
 
53
- ## Quantized Versions
 
 
54
 
55
- GGUF quantized models (Q4_K_M, Q5_K_M) for llama.cpp inference are available at:
56
- [itzune/morpheus-gguf](https://huggingface.co/itzune/morpheus-gguf)
 
57
 
58
  ## Citation
59
 
60
  ```bibtex
61
- @misc{morpheus_v2_mamba,
62
- author = {Xabier Ezpeleta},
63
- title = {Morpheus v2: On-Device Basque Autocompletion with Mamba-2},
64
- year = {2026},
 
65
  }
66
  ```
 
 
 
14
  pipeline_tag: text-generation
15
  ---
16
 
17
+ # Morpheus (Mamba-2) — Basque Autocomplete
18
 
19
+ A 91M-parameter Mamba-2 language model for on-device Basque (Euskara) text autocompletion. Trained from scratch on a curated Basque corpus and deployed as a 55 MB quantized model running on consumer CPUs.
20
 
21
  ## Model Details
22
 
23
+ - **Architecture:** Mamba-2 (State Space Model, Structured State Space Duality)
24
+ - **Parameters:** 91M (only 3.4% in embeddings thanks to the 4K vocab)
25
  - **Embedding vocab:** 4,000 (Unigram SentencePiece)
26
  - **Hidden dimension:** 768
27
  - **Layers:** 24
 
29
  - **Head dimension:** 64
30
  - **Inner dimension:** 1,536
31
  - **Sequence length:** 1,024
32
+ - **Training:** ~10B tokens seen (~2.16 epochs over a 4.62B-token unique corpus)
33
+ - **Best checkpoint:** step 74,000 (held-out PPL 7.13)
34
+ - **Trained without BOS token** (`add_bos_token=false`)
 
35
 
36
  ## Tokenizer
37
 
38
+ A 4K Unigram SentencePiece tokenizer trained on the cleaned Basque corpus. The small vocabulary size was chosen based on a vocabulary-size ablation (paper §4.4) motivated by the **fertility paradox** in agglutinative languages:
39
+
40
+ | Vocab | Fertility (tok/word) | Morpheme Boundary Accuracy |
41
+ |------:|---------------------:|---------------------------:|
42
+ | 32,000 | 1.85 | 28.6% |
43
+ | 4,000 | 2.58 | **66.7%** |
44
+
45
+ Larger vocabularies fuse Basque roots and suffixes into opaque atomic tokens (e.g. `▁etxetik`, `▁etxera`), destroying the morphological boundaries the model needs to productively generate unseen inflections. The 4K vocabulary keeps individual case suffixes and pluralizers as reusable subwords (`etxe+tik` → `▁etxe tik`), which is decisive for an agglutinative language where a single verb can encode subject, object, indirect object, tense, mood, and aspect through suffix chains. This mirrors the QuechuaTok finding for Quechua.
46
 
47
  - `add_bos_token: false` (the model was trained without a BOS token)
48
  - EOS token: `</s>` (id=2)
49
  - UNK token: `<unk>` (id=0)
50
 
51
+ ## Usage (transformers)
52
+
53
+ ```python
54
+ import torch
55
+ from transformers import AutoModelForCausalLM, LlamaTokenizer
56
+
57
+ model = AutoModelForCausalLM.from_pretrained("itzune/morpheus", torch_dtype=torch.float32)
58
+ tokenizer = LlamaTokenizer.from_pretrained("itzune/morpheus")
59
+ # tokenizer_config.json already sets add_bos_token=False — matches no-BOS training
60
+
61
+ prompt = "Kaixo, zer moduz"
62
+ inputs = tokenizer(prompt, return_tensors="pt") # NO BOS is prepended (correct)
63
+ output = model.generate(**inputs, max_new_tokens=5, do_sample=False)
64
+ print(tokenizer.decode(output[0], skip_special_tokens=True))
65
+ ```
66
 
67
+ > With the `transformers` tokenizer, **string prompts are fine** `LlamaTokenizer` uses the reference `sentencepiece` library, so tokenization matches training exactly. The token-ID caveat below applies only to the **GGUF / `llama.cpp`** deployment path.
68
+
69
+ ## ⚠️ Deploying with llama.cpp? Use token-ID prompts
70
+
71
+ If you quantize this model to GGUF and serve it with `llama-server`/`llama-cli`, **do not send string prompts**. `llama.cpp`'s built-in SentencePiece tokenizer diverges from the reference library on this 4K vocabulary, and `llama-server` may auto-prepend a BOS token the model never saw in training. Combined, these drop character-saving rate from **~28% to ~4%** — a 7× degradation (paper §5.1).
72
+
73
+ The fix is to load `tokenizer.model` with the `sentencepiece` library, encode to token IDs (no BOS), and send the ID list to `llama-server`'s `/completion` endpoint. Pre-quantized GGUF models and a full token-ID usage example are at [itzune/morpheus-gguf](https://huggingface.co/itzune/morpheus-gguf).
74
 
75
  ## Training Data
76
 
77
+ Trained on a curated subset of the publicly available **Latxa Corpus v2** (`HiTZ/latxa-corpus-v2`; Etxaniz et al., 2024):
78
 
79
+ - **4.62 billion subword tokens** (~9 GB tokenized; ~15 GB raw text), of which **~10B tokens were seen** during training (~2.16 epochs).
80
+ - 11 of the 14 Latxa Corpus v2 sub-corpora were retained; 3 were omitted for quality reasons (`hplt-v1`: 83.8% duplicates; `BOG`: sentence-splitting destroyed legal text; `Aldizkariak`: 35% boilerplate). An LLM-based audit rated the retained sources 4.6/5 on average.
81
+ - Four-phase cleaning pipeline: document re-parsing, form regularity, content filtering (incl. validation-leakage removal), and MinHash-LSH deduplication. See paper §4.2.
82
 
83
+ ## Intended Use
84
+
85
+ On-device Basque text autocomplete and predictive keyboard input. The model is small enough to run on CPU via `llama.cpp` — see the GGUF quantized versions at [itzune/morpheus-gguf](https://huggingface.co/itzune/morpheus-gguf) (55 MB Q4_K_M). On a 2017 consumer laptop CPU (Intel i7-8550U) it achieves 318 tok/s decode and 97 ms end-to-end autocomplete latency (paper §5.2).
86
 
87
  ## Citation
88
 
89
  ```bibtex
90
+ @misc{morpheus_mamba,
91
+ author = {Xabier Ezpeleta},
92
+ title = {Morpheus: On-Device Basque Autocompletion with Mamba-2},
93
+ year = {2026},
94
+ howpublished = {\url{https://huggingface.co/itzune/morpheus}},
95
  }
96
  ```
97
+
98
+ See the accompanying paper (`morpheus-on-device-basque-autocompletion`) for full architecture, training, evaluation, and deployment details.