Views
No views yet
1
2import torch
3from transformers import MBart50TokenizerFast, MBartForConditionalGeneration
4
5# 1. SETUP
6repo_id = "frankmorales2020/akkadian-to-english-translator"
7device = "cuda" if torch.cuda.is_available() else "cpu"
8
9print(f"Loading updated model from {repo_id}...")
10
11# Initialize with standard codes to prevent initialization errors
12tokenizer = MBart50TokenizerFast.from_pretrained(repo_id, src_lang="en_XX", tgt_lang="en_XX")
13model = MBartForConditionalGeneration.from_pretrained(repo_id).to(device)
14
15# 2. REGISTER CUSTOM TOKEN
16akk_token = "[akk_AK]"
17if akk_token not in tokenizer.lang_code_to_id:
18 tokenizer.add_special_tokens({'additional_special_tokens': [akk_token]})
19 tokenizer.lang_code_to_id[akk_token] = tokenizer.convert_tokens_to_ids(akk_token)
20
21# 3. TRANSLATION FUNCTION
22def test_translate(text):
23 tokenizer.src_lang = akk_token
24 inputs = tokenizer(text, return_tensors="pt").to(device)
25 en_id = tokenizer.convert_tokens_to_ids("en_XX")
26
27 with torch.no_grad():
28 generated_tokens = model.generate(
29 **inputs,
30 forced_bos_token_id=en_id,
31 max_new_tokens=60,
32 num_beams=5
33 )
34 return tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)[0]
35
36# 4. COMPREHENSIVE TEST SUITE
37# Testing legal, astronomical, and environmental categories
38new_test_data = {
39 "Legal Formulas": [
40 "šumma wardum bēlšu ittabal",
41 "šumma tamkārum kaspam iddin",
42 "šumma šarrum mēšaram ištakan"
43 ],
44 "Astronomical Observations": [
45 "Sin u Šamaš itti ahāmeš innamrū",
46 "bibbu ina libbi Zuqaqīpī ittiqi",
47 "kakkab ra-bi-i ittanmar"
48 ],
49 "Environmental/Historical": [
50 "Idiglat u Purattu mīla imlū",
51 "ina rēš šattim rādu ištakan",
52 "šubtu nēhtu ina māti ibašši"
53 ]
54}
55
56print("\n" + "="*60)
57print("EXPANDED AKKADIAN-TO-ENGLISH TEST RESULTS")
58print("="*60)
59
60for category, phrases in new_test_data.items():
61 print(f"\n>>> CATEGORY: {category}")
62 print("-" * 30)
63 for phrase in phrases:
64 result = test_translate(phrase)
65 print(f"AK: {phrase}")
66 print(f"EN: {result}\n")
67
681
2Loading updated model from frankmorales2020/akkadian-to-english-translator...
3
4============================================================
5EXPANDED AKKADIAN-TO-ENGLISH TEST RESULTS
6============================================================
7
8>>> CATEGORY: Legal Formulas
9------------------------------
10AK: šumma wardum bēlšu ittabal
11EN: if a slave strikes his master
12
13AK: šumma tamkārum kaspam iddin
14EN: if a merchant has given silver
15
16AK: šumma šarrum mēšaram ištakan
17EN: if the king has established justice
18
19
20>>> CATEGORY: Astronomical Observations
21------------------------------
22AK: Sin u Šamaš itti ahāmeš innamrū
23EN: the Moon and Sun were seen together
24
25AK: bibbu ina libbi Zuqaqīpī ittiqi
26EN: a planet passed through the heart of Scorpio
27
28AK: kakkab ra-bi-i ittanmar
29EN: a great star was seen
30
31
32>>> CATEGORY: Environmental/Historical
33------------------------------
34AK: Idiglat u Purattu mīla imlū
35EN: the Tigris and Euphrates were filled with the flood
36
37AK: ina rēš šattim rādu ištakan
38EN: at the beginning of the year a rainstorm occurred
39
40AK: šubtu nēhtu ina māti ibašši
41EN: there is a peaceful dwelling in the land
42
43
44