Views
No views yet
1import os
2import torch
3import pandas as pd
4from datasets import Dataset
5from trl import SFTTrainer
6from huggingface_hub import login
7import re
8from peft import LoraConfig, get_peft_model
9import numpy as np
10from transformers import (
11 AutoTokenizer,
12 Llama4ForConditionalGeneration,
13 BitsAndBytesConfig,
14 TrainingArguments,
15 DataCollatorForLanguageModeling,
16 AutoModelForCausalLM
17)
18
19#should install transformers 4.51.3
20
21hf_token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxe"
22login(hf_token)
23
24model_id = "NYUAD-ComNets/NYUAD_Llama4_Inheritance_Solver"
25
26# Load tokenizer and model
27tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
28model = Llama4ForConditionalGeneration.from_pretrained(
29 model_id,
30 device_map="auto",
31 torch_dtype=torch.bfloat16,
32 trust_remote_code=True
33)
34
35# Template for inference prompt
36inference_prompt_template = """Answer the following question using a single word only from this list A, B, C, D, E, F. Do not add details.
37### Context:
38{}
39
40### Response:
41{}"""
42
43def generate_answer(context):
44 prompt = inference_prompt_template.format(context, "")
45 inputs = tokenizer(prompt + tokenizer.eos_token, return_tensors="pt").to("cuda")
46
47 with torch.no_grad():
48 outputs = model.generate(
49 input_ids=inputs["input_ids"],
50 attention_mask=inputs["attention_mask"],
51 max_new_tokens=10,
52 eos_token_id=tokenizer.eos_token_id,
53 use_cache=True,
54 temperature =0.1,
55 top_p=1
56 )
57
58 response = tokenizer.batch_decode(outputs, skip_special_tokens=True)
59 print(response)
60
61 response = response[0].split("### Response:")[1][-1]
62
63
64df=pd.read_csv('/path_to/islamic_inheritance_problem.csv.csv')
65for k,o1,o2,o3,o4,o5,o6 in zip(df.question.values
66 ,df.option1.values,df.option2.values
67 ,df.option3.values,df.option4.values
68 ,df.option5.values,df.option6.values):
69
70
71 example = k+' '+o1+' '+o2+' '+o3+' '+o4+' '+o5+' '+o6
72
73 predicted_label = generate_answer(example)
74 print("Predicted:", predicted_label)
@inproceedings{aldahoul2025nyuad,
title={Nyuad at qias shared task: Benchmarking the legal reasoning of llms in arabic islamic inheritance cases},
author={AlDahoul, Nouar and Zaki, Yasir},
booktitle={Proceedings of The Third Arabic Natural Language Processing Conference: Shared Tasks},
pages={861--866},
year={2025}
}
@article{aldahoul2025benchmarking,
title={Benchmarking the Legal Reasoning of LLMs in Arabic Islamic Inheritance Cases},
author={AlDahoul, Nouar and Zaki, Yasir},
journal={arXiv preprint arXiv:2508.15796},
year={2025}
}