Views
No views yet
transformers library without needing any extra complex frameworks:1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch
3
4# 1. Define model repository
5model_name = "Ahmed792/llama-3.1-8b-egyptian-legal"
6
7# 2. Load the tokenizer and the 16-bit merged model
8tokenizer = AutoTokenizer.from_pretrained(model_name)
9model = AutoModelForCausalLM.from_pretrained(
10 model_name,
11 torch_dtype=torch.float16,
12 device_map="auto"
13)
14
15# 3. Formulate the prompt in Egyptian Arabic
16messages = [
17 {"role": "user", "content": "لو سمحت، إيه هي الإجراءات القانونية لتأسيس شركة في مصر؟"}
18]
19
20# 4. Apply the Llama-3 conversational chat template
21inputs = tokenizer.apply_chat_template(messages, tokenize=True, return_tensors="pt").to("cuda")
22
23# 5. Generate the response
24outputs = model.generate(inputs, max_new_tokens=256, temperature=0.5)
25
26# 6. Decode and print the clean output
27print(tokenizer.decode(outputs[0], skip_special_tokens=True))