Views
No views yet
[] for unanswerable questions.unsloth/llama-3-8b-bnb-4bit1from transformers import AutoModelForCausalLM, AutoTokenizer
2from peft import PeftModel
3
4# Load base model and adapter
5base_model = AutoModelForCausalLM.from_pretrained(
6 "meta-llama/Meta-Llama-3-8B",
7 device_map="auto",
8 torch_dtype="auto"
9)
10model = PeftModel.from_pretrained(base_model, "YOUR_USERNAME/squad-v2-llama3-lora-improved")
11tokenizer = AutoTokenizer.from_pretrained("YOUR_USERNAME/squad-v2-llama3-lora-improved")
12
13# Format prompt
14prompt = """<|begin_of_text|><|start_header_id|>system<|end_header_id|>
15
16You are an EXPERT answer-span extractor. Extract the SHORTEST EXACT SPAN from the context that answers the question. Output [] if unanswerable.<|eot_id|><|start_header_id|>user<|end_header_id|>
17
18Context: The Normans were the people who gave their name to Normandy, a region in France.
19Question: In what country is Normandy located?<|eot_id|><|start_header_id|>assistant<|end_header_id|>
20
21"""
22
23inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
24outputs = model.generate(**inputs, max_new_tokens=50, do_sample=False)
25answer = tokenizer.decode(outputs[0], skip_special_tokens=True)
26# Output: "France"