File size: 3,802 Bytes
a4462f5
 
bac26dd
8d1be51
cf5dfba
 
 
 
 
 
 
 
 
a4462f5
11632a3
a4462f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f472732
a4462f5
 
f472732
a4462f5
 
11632a3
 
 
a4462f5
 
 
 
 
bac26dd
a4462f5
 
 
bac26dd
 
 
 
a4462f5
 
bac26dd
 
 
 
 
 
11632a3
 
 
 
 
bac26dd
a4462f5
 
 
 
 
 
 
 
 
cf5dfba
a4462f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11632a3
1
2
3
4
5
6
7
8
9
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
from transformers import AutoTokenizer, T5ForConditionalGeneration, pipeline

# HF Hub path config
model_path = "crossroderick/aramt5"

# Unicode directional formatting for RTL text (Syriac)
RLI = "\u2067"  # Right-to-Left Isolate
PDI = "\u2069"  # Pop Directional Isolate


def rtl(text: str) -> str:
    """Wrap text in RTL isolate markers for correct terminal display."""
    return f"{RLI}{text}{PDI}"


# Load model and tokeniser
print("Loading model and tokeniser...")
tokeniser = AutoTokenizer.from_pretrained(model_path)
model = T5ForConditionalGeneration.from_pretrained(model_path)
pipe = pipeline("text2text-generation", model=model, tokenizer=tokeniser)
print("Model loaded successfully.\n")


def transliterate(text: str, dialect: str = "west") -> str:
    """
    Transliterate Syriac text to Latin script.

    Args:
        text: Syriac text to transliterate
        dialect: 'west' for West Syriac (Serto) or 'east' for East Syriac (Madnḥaya)

    Returns:
        Transliterated Latin text
    """
    if dialect == "east":
        prefix = "Syriac2EastLatin: "
    else:
        prefix = "Syriac2WestLatin: "

    input_prompt = f"{prefix}{text}"
    # Simple generation - let model decide length naturally
    output = pipe(
        input_prompt,
        max_new_tokens=128,
        num_beams=4,
        do_sample=False,
    )[
        0
    ]["generated_text"]
    return output


# Test examples - mix of words and sentences
test_samples = [
    # Single words - West Syriac
    {"text": "ܫܠܡܐ", "dialect": "west", "description": "Peace (West)"},
    {"text": "ܐܠܗܐ", "dialect": "west", "description": "God (West)"},
    {"text": "ܡܫܝܚܐ", "dialect": "west", "description": "Messiah/Christ (West)"},
    {"text": "ܡܠܟܐ", "dialect": "west", "description": "King (West)"},
    {"text": "ܒܝܬܐ", "dialect": "west", "description": "House (West)"},
    # Single words - East Syriac
    {"text": "ܫܠܡܐ", "dialect": "east", "description": "Peace (East)"},
    {"text": "ܐܠܗܐ", "dialect": "east", "description": "God (East)"},
    {"text": "ܡܫܝܚܐ", "dialect": "east", "description": "Messiah/Christ (East)"},
    # Proclitic examples
    {"text": "ܒܒܝܬܐ", "dialect": "west", "description": "In the house (West)"},
    {"text": "ܘܡܠܟܐ", "dialect": "west", "description": "And the king (West)"},
    {"text": "ܕܐܠܗܐ", "dialect": "west", "description": "Of God (West)"},
    {"text": "ܠܡܠܟܐ", "dialect": "west", "description": "To the king (West)"},
    # Short phrases
    {
        "text": "ܐܒܘܢ ܕܒܫܡܝܐ",
        "dialect": "west",
        "description": "Our Father in heaven (West)",
    },
    {"text": "ܫܠܡܐ ܥܡܟ", "dialect": "west", "description": "Peace be with you (West)"},
]

print("=" * 50)
print("AramT5 Syriac Transliteration Test")
print("=" * 50)

for sample in test_samples:
    result = transliterate(sample["text"], sample["dialect"])
    print(f"\n{sample['description']}:")
    print(f"  Syriac: {rtl(sample['text'])}")
    print(f"  Latin:  {result}")

print("\n" + "=" * 50)
print("Interactive mode - enter Syriac text to transliterate")
print("Format: [e/w] text (e=east, w=west, default=west)")
print("Enter 'q' to quit")
print("=" * 50)

while True:
    user_input = input("\n> ").strip()
    if user_input.lower() == "q":
        break

    # Parse dialect prefix
    if user_input.startswith("e "):
        dialect = "east"
        text = user_input[2:]
    elif user_input.startswith("w "):
        dialect = "west"
        text = user_input[2:]
    else:
        dialect = "west"
        text = user_input

    if text:
        result = transliterate(text, dialect)
        dialect_name = "East" if dialect == "east" else "West"
        print(f"  [{dialect_name}] {rtl(text)}{result}")