Aaron Thomas Mathew commited on
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,141 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: apache-2.0
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
base_model:
|
| 4 |
+
- CohereLabs/tiny-aya-base
|
| 5 |
+
pipeline_tag: translation
|
| 6 |
+
tags:
|
| 7 |
+
- Syriac
|
| 8 |
+
- transalation
|
| 9 |
+
- lora
|
| 10 |
+
- lark
|
| 11 |
+
language:
|
| 12 |
+
- en
|
| 13 |
+
- syr
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
# Malfono LARK – Syriac–English Translation LoRA Adapter
|
| 17 |
+
|
| 18 |
+
## Model Description
|
| 19 |
+
|
| 20 |
+
This is a **LoRA adapter** for `CohereLabs/tiny-aya-base` fine‑tuned to translate between English and Classical Syriac. The model was trained using the **LARK** (Language-Agnostic Rule-Guided Knowledge-Constrained Generation) framework, which adds a constraint‑aware loss to encourage grammatical correctness (subject‑verb agreement, construct state chains) based on a knowledge base of Syriac morphological rules extracted from a grammar textbook.
|
| 21 |
+
|
| 22 |
+
The adapter alone is small (~7 MB) and must be loaded on top of the base model.
|
| 23 |
+
|
| 24 |
+
## Intended Uses & Limitations
|
| 25 |
+
|
| 26 |
+
**Intended use:**
|
| 27 |
+
- Translation from English to Syriac and Syriac to English.
|
| 28 |
+
- Research on neuro‑symbolic methods for low‑resource languages.
|
| 29 |
+
- Demonstration of grammar‑aware fine‑tuning.
|
| 30 |
+
|
| 31 |
+
**Limitations:**
|
| 32 |
+
- Due to limited training (30% of the Peshitta, ~1400 steps on a Kaggle T4 GPU), translation fluency is still moderate (BLEU score not reported).
|
| 33 |
+
- The model sometimes produces repetitive or incomplete outputs.
|
| 34 |
+
- Syriac orthography uses a simplified ASCII‑to‑Syriac transliteration; diacritics are not preserved.
|
| 35 |
+
- The morphological analyzer is rule‑based and may produce occasional false positives.
|
| 36 |
+
|
| 37 |
+
## Training Data
|
| 38 |
+
|
| 39 |
+
- **Syriac text**: Peshitta Old Testament (ETCBC) – 49,455 verses.
|
| 40 |
+
- **English parallel**: eBible Corpus (English Standard Version).
|
| 41 |
+
- **Training split**: 30% of the aligned verses (≈ 15,000 examples).
|
| 42 |
+
- **Prompt format**: Alpaca‑style instruction:
|
| 43 |
+
```
|
| 44 |
+
### Instruction:
|
| 45 |
+
Translate the following English text to Syriac.
|
| 46 |
+
### Input:
|
| 47 |
+
{English sentence}
|
| 48 |
+
### Response:
|
| 49 |
+
{Syriac translation}
|
| 50 |
+
```
|
| 51 |
+
(Both translation directions were used.)
|
| 52 |
+
|
| 53 |
+
## Training Procedure
|
| 54 |
+
|
| 55 |
+
- **Base model**: `CohereLabs/tiny-aya-base` (3.35B parameters).
|
| 56 |
+
- **Quantization**: 4‑bit (QLoRA) via `unsloth`.
|
| 57 |
+
- **LoRA rank**: 16, applied to `q_proj`, `k_proj`, `v_proj`, `o_proj`.
|
| 58 |
+
- **Batch size**: 2 per GPU, gradient accumulation 4 (effective batch 8).
|
| 59 |
+
- **Sequence length**: 64 tokens.
|
| 60 |
+
- **Optimizer**: `paged_adamw_8bit`.
|
| 61 |
+
- **Learning rate**: 2e‑4.
|
| 62 |
+
- **Steps**: 1000 (resumed from a checkpoint trained for 700 steps).
|
| 63 |
+
- **Constraint loss weight (LARK)**: 0.1.
|
| 64 |
+
|
| 65 |
+
## Evaluation Results
|
| 66 |
+
|
| 67 |
+
The model was evaluated on 100 held‑out verses from the Peshitta using two grammar‑focused metrics:
|
| 68 |
+
|
| 69 |
+
| Metric | Score |
|
| 70 |
+
|--------|-------|
|
| 71 |
+
| **Subject‑verb agreement accuracy** (gender & number) | 36.0% |
|
| 72 |
+
| **Morphological violation rate** (percentage of tokens violating any rule in the KB) | 9.9% |
|
| 73 |
+
|
| 74 |
+
These numbers show that the LARK constraint reduces grammatical errors compared to a baseline fine‑tuned without constraints (baseline agreement accuracy ≈ 28%, violation rate ≈ 15%).
|
| 75 |
+
|
| 76 |
+
## How to Use
|
| 77 |
+
|
| 78 |
+
### Installation
|
| 79 |
+
|
| 80 |
+
```bash
|
| 81 |
+
pip install peft transformers torch
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
### Load the adapter (English → Syriac translation)
|
| 85 |
+
|
| 86 |
+
```python
|
| 87 |
+
import torch
|
| 88 |
+
from peft import PeftModel
|
| 89 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 90 |
+
|
| 91 |
+
base_model_name = "CohereLabs/tiny-aya-base"
|
| 92 |
+
adapter_name = "aaronmat1905/malfono-lark-lora"
|
| 93 |
+
|
| 94 |
+
base_model = AutoModelForCausalLM.from_pretrained(
|
| 95 |
+
base_model_name,
|
| 96 |
+
device_map="auto",
|
| 97 |
+
torch_dtype=torch.float16,
|
| 98 |
+
)
|
| 99 |
+
tokenizer = AutoTokenizer.from_pretrained(base_model_name)
|
| 100 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 101 |
+
|
| 102 |
+
model = PeftModel.from_pretrained(base_model, adapter_name)
|
| 103 |
+
model.eval()
|
| 104 |
+
```
|
| 105 |
+
|
| 106 |
+
### Translation function
|
| 107 |
+
|
| 108 |
+
```python
|
| 109 |
+
def translate_to_syriac(english_sentence: str, max_new_tokens: int = 60) -> str:
|
| 110 |
+
prompt = f"### Instruction:\nTranslate the following English text to Syriac.\n\n### Input:\n{english_sentence}\n\n### Response:\n"
|
| 111 |
+
inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=512).to(model.device)
|
| 112 |
+
with torch.no_grad():
|
| 113 |
+
outputs = model.generate(
|
| 114 |
+
**inputs,
|
| 115 |
+
max_new_tokens=max_new_tokens,
|
| 116 |
+
temperature=0.2,
|
| 117 |
+
do_sample=True,
|
| 118 |
+
top_p=0.9,
|
| 119 |
+
repetition_penalty=1.2,
|
| 120 |
+
pad_token_id=tokenizer.eos_token_id,
|
| 121 |
+
)
|
| 122 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 123 |
+
if "### Response:\n" in response:
|
| 124 |
+
response = response.split("### Response:\n")[-1].strip()
|
| 125 |
+
return response.split("\n")[0]
|
| 126 |
+
|
| 127 |
+
print(translate_to_syriac("Peace be with you."))
|
| 128 |
+
```
|
| 129 |
+
|
| 130 |
+
### Reverse direction (Syriac → English)
|
| 131 |
+
|
| 132 |
+
Replace the instruction with `"Translate the following Syriac text to English."` and swap input/output.
|
| 133 |
+
|
| 134 |
+
## Citation
|
| 135 |
+
|
| 136 |
+
If you use this model in your research, please cite the LARK project (see the [LARK repository](https://github.com/aaronmat1905/LARK) for details).
|
| 137 |
+
|
| 138 |
+
## Contact
|
| 139 |
+
|
| 140 |
+
For questions, please open an issue on the [Hugging Face community tab](https://huggingface.co/aaronmat1905/malfono-lark-lora/discussions) or the [GitHub repository](https://github.com/aaronmat1905/LARK).
|
| 141 |
+
```
|