Views
No views yet
{"confidence": "UNVERIFIABLE"} instead of hallucinating when data is not present in the textsource_quote field grounding the answer in the original text1from transformers import AutoTokenizer, AutoModelForCausalLM
2from peft import PeftModel
3import torch
4
5base_model = AutoModelForCausalLM.from_pretrained(
6 "mistralai/Mistral-7B-Instruct-v0.3",
7 torch_dtype=torch.float16,
8 device_map="auto"
9)
10model = PeftModel.from_pretrained(base_model, "ratnasekhar/earnings-copilot-mistral-7b")
11tokenizer = AutoTokenizer.from_pretrained("ratnasekhar/earnings-copilot-mistral-7b")
12
13prompt = """<s>[INST] You are a financial KPI extraction model. Extract metrics from SEC filing chunks as JSON. If a metric cannot be verified from the text, output {"confidence": "UNVERIFIABLE"}. Never invent numbers.
14
15Filing chunk:
16Net sales for Q1 FY2024 were $119.6 billion, an increase of 2% compared to Q1 FY2023.
17
18Extract: What was total revenue and its YoY change? [/INST]"""
19
20inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
21outputs = model.generate(**inputs, max_new_tokens=150, do_sample=False)
22print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))1{
2 "metric": "Revenue",
3 "value": 119.6,
4 "unit": "billion USD",
5 "period": "Q1 FY2024",
6 "yoy_change": "+2%",
7 "source_quote": "Net sales for Q1 FY2024 were $119.6 billion",
8 "confidence": "HIGH"
9}