Update checking2.py
Browse files- checking2.py +5 -102
checking2.py
CHANGED
|
@@ -1,103 +1,6 @@
|
|
| 1 |
-
|
| 2 |
-
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
# ============================================================
|
| 7 |
-
|
| 8 |
-
MODEL_PATH = r"D:\path\to\v2_model"
|
| 9 |
-
|
| 10 |
-
# ============================================================
|
| 11 |
-
# LOAD MODEL
|
| 12 |
-
# ============================================================
|
| 13 |
-
|
| 14 |
-
print("Loading tokenizer...")
|
| 15 |
-
tokenizer = AutoTokenizer.from_pretrained(
|
| 16 |
-
MODEL_PATH,
|
| 17 |
-
trust_remote_code=True
|
| 18 |
-
)
|
| 19 |
-
|
| 20 |
-
print("Loading model...")
|
| 21 |
-
|
| 22 |
-
model = AutoModelForCausalLM.from_pretrained(
|
| 23 |
-
MODEL_PATH,
|
| 24 |
-
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
|
| 25 |
-
device_map="auto",
|
| 26 |
-
trust_remote_code=True
|
| 27 |
-
)
|
| 28 |
-
|
| 29 |
-
model.eval()
|
| 30 |
-
|
| 31 |
-
print("Model loaded successfully.\n")
|
| 32 |
-
|
| 33 |
-
# ============================================================
|
| 34 |
-
# PROMPT FORMAT
|
| 35 |
-
# ============================================================
|
| 36 |
-
|
| 37 |
-
def make_prompt(urdu_text):
|
| 38 |
-
return f"""### Instruction:
|
| 39 |
-
Transliterate the following Urdu text into Roman Urdu.
|
| 40 |
-
Output ONLY the Roman Urdu. No translation. No explanation.
|
| 41 |
-
|
| 42 |
-
### Input:
|
| 43 |
-
{urdu_text}
|
| 44 |
-
|
| 45 |
-
### Response:
|
| 46 |
-
"""
|
| 47 |
-
|
| 48 |
-
# ============================================================
|
| 49 |
-
# GENERATE
|
| 50 |
-
# ============================================================
|
| 51 |
-
|
| 52 |
-
def transliterate(urdu_text):
|
| 53 |
-
|
| 54 |
-
prompt = make_prompt(urdu_text)
|
| 55 |
-
|
| 56 |
-
inputs = tokenizer(
|
| 57 |
-
prompt,
|
| 58 |
-
return_tensors="pt"
|
| 59 |
-
).to(model.device)
|
| 60 |
-
|
| 61 |
-
with torch.no_grad():
|
| 62 |
-
outputs = model.generate(
|
| 63 |
-
**inputs,
|
| 64 |
-
max_new_tokens=256,
|
| 65 |
-
do_sample=False,
|
| 66 |
-
temperature=0.0,
|
| 67 |
-
top_p=1.0,
|
| 68 |
-
repetition_penalty=1.05,
|
| 69 |
-
eos_token_id=tokenizer.eos_token_id,
|
| 70 |
-
pad_token_id=tokenizer.eos_token_id
|
| 71 |
-
)
|
| 72 |
-
|
| 73 |
-
result = tokenizer.decode(
|
| 74 |
-
outputs[0],
|
| 75 |
-
skip_special_tokens=True
|
| 76 |
-
)
|
| 77 |
-
|
| 78 |
-
if "### Response:" in result:
|
| 79 |
-
result = result.split("### Response:")[-1].strip()
|
| 80 |
-
|
| 81 |
-
return result
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
# ============================================================
|
| 85 |
-
# INTERACTIVE LOOP
|
| 86 |
-
# ============================================================
|
| 87 |
-
|
| 88 |
-
print("=" * 70)
|
| 89 |
-
print("Tiny Aya V2 Transliteration Test")
|
| 90 |
-
print("Type 'exit' to quit.")
|
| 91 |
-
print("=" * 70)
|
| 92 |
-
|
| 93 |
-
while True:
|
| 94 |
-
|
| 95 |
-
urdu = input("\nUrdu: ").strip()
|
| 96 |
-
|
| 97 |
-
if urdu.lower() == "exit":
|
| 98 |
-
break
|
| 99 |
-
|
| 100 |
-
roman = transliterate(urdu)
|
| 101 |
-
|
| 102 |
-
print("\nRoman:")
|
| 103 |
-
print(roman)
|
|
|
|
| 1 |
+
عالم خان|لعل خان|لعل خان|محلہ لوہارانوالہ،کالا باغ،تحصیل عیسی خیل،ضلع میانوالی|محلہ لوہارانوالہ،کالا باغ،تحصیل عیسی خیل،ضلع میانوالی|عیسی خیل,میانوالی
|
| 2 |
+
v2: Roman:
|
| 3 |
+
ISI KHIL,MIANWALI
|
| 4 |
|
| 5 |
+
v3:
|
| 6 |
+
ALAM KHAN LAL KHAN LAL KHAN MOHALA LOHARAN WALA KALA BAGH TEHSIL EESSA KHAIL DISTRICT MIANWALI
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|