Views
No views yet
Reasoning: followed by a concise conclusion under Final Answer:.
1from unsloth import FastLanguageModel
2
3model, tokenizer = FastLanguageModel.from_pretrained(
4 model_name="your-hf-username/llama3.1-8b-fincot",
5 max_seq_length=4096,
6 load_in_4bit=False,
7)
8FastLanguageModel.for_inference(model)
9
10SYSTEM_PROMPT = (
11 "You are a financial reasoning assistant. Work through the problem "
12 'step by step under "Reasoning:", then give the polished final answer '
13 'under "Final Answer:".'
14)
15
16messages = [
17 {"role": "system", "content": SYSTEM_PROMPT},
18 {"role": "user", "content": "Please answer the given financial question based on the context.\n\n[your context]\n\nQuestion: [your question]"},
19]
20inputs = tokenizer.apply_chat_template(
21 messages, tokenize=True, add_generation_prompt=True, return_tensors="pt"
22).to("cuda")
23out = model.generate(input_ids=inputs, max_new_tokens=512, use_cache=True)
24print(tokenizer.batch_decode(out))Reasoning:
<step-by-step working>
Final Answer:
<concise answer>Final Answer: marker to separate reasoning from the answer.