curiousily
commited on
Commit
•
1353d63
1
Parent(s):
66a486c
Update README.md
Browse files
README.md
CHANGED
@@ -14,4 +14,92 @@ pipeline_tag: text-generation
|
|
14 |
# Llama 3 8B Instruct (Financial RAG)
|
15 |
|
16 |
This model is a fine-tuned version of the original [Llama 3 8B Instruct](https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct) model
|
17 |
-
on 4000 examples from the [virattt/financial-qa-10K](https://huggingface.co/datasets/virattt/financial-qa-10K) dataset.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
# Llama 3 8B Instruct (Financial RAG)
|
15 |
|
16 |
This model is a fine-tuned version of the original [Llama 3 8B Instruct](https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct) model
|
17 |
+
on 4000 examples from the [virattt/financial-qa-10K](https://huggingface.co/datasets/virattt/financial-qa-10K) dataset.
|
18 |
+
|
19 |
+
The model is fine-tuned using a LoRA adapter for RAG use cases. It is optimized to answer a question based on a context:
|
20 |
+
|
21 |
+
```txt
|
22 |
+
Answer the question:
|
23 |
+
{question}
|
24 |
+
|
25 |
+
Using the information:
|
26 |
+
{context}
|
27 |
+
```
|
28 |
+
|
29 |
+
## Example Usage
|
30 |
+
|
31 |
+
Load the model:
|
32 |
+
|
33 |
+
```py
|
34 |
+
MODEL_NAME = "curiousily/Llama-3-8B-Instruct-Finance-RAG"
|
35 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, use_fast=True)
|
36 |
+
model = AutoModelForCausalLM.from_pretrained(
|
37 |
+
MODEL_NAME,
|
38 |
+
device_map="auto"
|
39 |
+
)
|
40 |
+
|
41 |
+
pipe = pipeline(
|
42 |
+
task="text-generation",
|
43 |
+
model=model,
|
44 |
+
tokenizer=tokenizer,
|
45 |
+
max_new_tokens=128,
|
46 |
+
return_full_text=False,
|
47 |
+
)
|
48 |
+
```
|
49 |
+
|
50 |
+
Format the prompt (uses the original Instruct prompt format):
|
51 |
+
|
52 |
+
````py
|
53 |
+
prompt = """
|
54 |
+
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
|
55 |
+
|
56 |
+
Use only the information to answer the question<|eot_id|><|start_header_id|>user<|end_header_id|>
|
57 |
+
|
58 |
+
How much did the company's net earnings amount to in fiscal 2022?
|
59 |
+
|
60 |
+
Information:
|
61 |
+
|
62 |
+
```
|
63 |
+
Net earnings were $17.1 billion in fiscal 2022.
|
64 |
+
```<|eot_id|><|start_header_id|>assistant<|end_header_id|>
|
65 |
+
"""
|
66 |
+
````
|
67 |
+
|
68 |
+
And make a prediction:
|
69 |
+
|
70 |
+
```py
|
71 |
+
print(outputs[0]["generated_text"])
|
72 |
+
```
|
73 |
+
|
74 |
+
```
|
75 |
+
$17.1 billion
|
76 |
+
```
|
77 |
+
|
78 |
+
Here's a helper function to build your prompts:
|
79 |
+
|
80 |
+
```py
|
81 |
+
def create_test_prompt(data_row):
|
82 |
+
prompt = dedent(f"""
|
83 |
+
{data_row["question"]}
|
84 |
+
|
85 |
+
Information:
|
86 |
+
|
87 |
+
```
|
88 |
+
{data_row["context"]}
|
89 |
+
```
|
90 |
+
""")
|
91 |
+
messages = [
|
92 |
+
{"role": "system", "content": "Use only the information to answer the question"},
|
93 |
+
{"role": "user", "content": prompt},
|
94 |
+
]
|
95 |
+
return tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
96 |
+
```
|
97 |
+
|
98 |
+
Where `data_row` must be a dict:
|
99 |
+
|
100 |
+
```
|
101 |
+
data_row = {
|
102 |
+
"question": "...",
|
103 |
+
"context": "..."
|
104 |
+
}
|
105 |
+
```
|