MathBite commited on
Commit
a034249
·
verified ·
1 Parent(s): 1af334e

readme update

Browse files
Files changed (1) hide show
  1. README.md +44 -8
README.md CHANGED
@@ -1,22 +1,46 @@
1
  ---
2
  license: llama3.1
3
  language: en
4
- base_model: meta-llama/Llama-3.1-8B-Instruct
5
  ---
6
 
7
- # MathBite/self_corrective_llama_3.1_8B_end
8
 
9
- This is a fine-tuned version of `meta-llama/Llama-3.1-8B-Instruct`. The LoRA adapter has been merged into the base model. This model includes a custom hallucination detection head that can intervene during generation to insert corrective instructions.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
  ## How to Use
12
 
13
  Because this model uses a custom architecture with a modified `generate` method, you **must** use `trust_remote_code=True` when loading it. The required `modeling.py` file is included in this repository.
14
 
 
 
15
  ```python
16
  from transformers import AutoModelForCausalLM, AutoTokenizer
17
  import torch
18
 
19
- model_name = "MathBite/self_corrective_llama_3.1_8B_end"
20
  tokenizer = AutoTokenizer.from_pretrained(model_name)
21
 
22
  # Important: You must trust the remote code
@@ -26,8 +50,20 @@ model = AutoModelForCausalLM.from_pretrained(
26
  torch_dtype=torch.bfloat16 # or your preferred dtype
27
  ).to("cuda") # move model to GPU
28
 
29
- # You can now use the model's custom generate method
30
- prompt = "YOUR PROMPT HERE" # your prompt here
 
 
 
 
 
 
 
 
 
 
 
 
31
  inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
32
 
33
  # The custom generate method requires the tokenizer instance
@@ -44,6 +80,6 @@ print(generated_text)
44
 
45
  ## Model Details
46
 
47
- This model was programmatically merged and uploaded using a deployment script. The custom class `SelfCorrectiveLlama` can be found in the `modeling.py` file.
48
 
49
- The code in `modeling.py` is licensed under the Apache 2.0 License. The model weights are subject to the original license of the base model.
 
1
  ---
2
  license: llama3.1
3
  language: en
4
+ base_model: meta-llama/Meta-Llama-3.1-8B-Instruct
5
  ---
6
 
7
+ # Self-Corrective Llama 3.1 8B
8
 
9
+ This is a fine-tuned version of `meta-llama/Meta-Llama-3.1-8B-Instruct`, augmented with a novel self-correction mechanism designed to mitigate hallucinations. The LoRA adapter has been merged into the base model for easy deployment.
10
+
11
+ This model features a custom **hallucination detection head** that works in parallel with the main language model. When it detects a potential error in its own generated text, it can insert special instructions like `[rewrite sentence]` or `[rewrite response]` into the output, effectively flagging its own mistakes for correction. This makes the model more reliable for tasks requiring factual accuracy.
12
+
13
+ ## How it Works
14
+
15
+ The model, an instance of the custom `SelfCorrectiveLlama` class, adds a small, efficient hallucination detection module to the standard Llama architecture. This module analyzes the model's internal states (hidden states) at each generation step to predict the likelihood of a hallucination.
16
+
17
+ The model's custom `generate` method then uses these predictions. If a hallucination is likely, it overrides the standard token generation process to insert a corrective instruction. This entire process happens in a single forward pass, making it significantly more efficient than multi-step, agent-based correction pipelines that require multiple LLM calls.
18
+
19
+ ## Intended Use & Prompting
20
+
21
+ This model is intended for tasks where factual accuracy and faithfulness to a source context are critical, such as question answering or summarization.
22
+
23
+ While it can be used with standard prompts, its self-correction behavior was reinforced during training using a specific instruction. To achieve the best results and fully leverage the self-correction mechanism, you should include the following note in your system prompt or at the beginning of your input:
24
+
25
+ <br>
26
+
27
+ > **Note on Self-Correction**: As you generate your response, you may encounter an automated instruction. This indicates a potential error was detected.
28
+ > - If you see the instruction `[rewrite sentence]`, it means the preceding sentence is incorrect. You must immediately provide a new, corrected version of that sentence.
29
+ > - If you see the instruction `[rewrite response]`, it means the entire preceding response is incorrect. You must immediately provide a new, complete response from the beginning.
30
+
31
+ <br>
32
 
33
  ## How to Use
34
 
35
  Because this model uses a custom architecture with a modified `generate` method, you **must** use `trust_remote_code=True` when loading it. The required `modeling.py` file is included in this repository.
36
 
37
+ **Note:** The custom `generate` method currently only supports a **batch size of 1**.
38
+
39
  ```python
40
  from transformers import AutoModelForCausalLM, AutoTokenizer
41
  import torch
42
 
43
+ model_name = "MathBite/self_corrective_llama_3.1_8B"
44
  tokenizer = AutoTokenizer.from_pretrained(model_name)
45
 
46
  # Important: You must trust the remote code
 
50
  torch_dtype=torch.bfloat16 # or your preferred dtype
51
  ).to("cuda") # move model to GPU
52
 
53
+ # Example prompt with the self-correction instruction
54
+ prompt = """
55
+ ...
56
+ Note on Self-Correction: As you generate your response, you may encounter an automated instruction. This indicates a potential error was detected.
57
+ - If you see the instruction `[rewrite sentence]`, it means the preceding sentence is incorrect. You must immediately provide a new, corrected version of that sentence.
58
+ - If you see the instruction `[rewrite response]`, it means the entire preceding response is incorrect. You must immediately provide a new, complete response from the beginning.
59
+
60
+ ---
61
+
62
+ Context: The Eiffel Tower is a wrought-iron lattice tower on the Champ de Mars in Paris, France. It is named after the engineer Gustave Eiffel, whose company designed and built the tower.
63
+
64
+ Question: Who was the first person to climb the Eiffel Tower?
65
+ """
66
+
67
  inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
68
 
69
  # The custom generate method requires the tokenizer instance
 
80
 
81
  ## Model Details
82
 
83
+ This model was programmatically merged and uploaded using a deployment script. The custom class `SelfCorrectiveLlama` can be found in the `modeling.py` file included in this repository.
84
 
85
+ The code in `modeling.py` is licensed under the Apache 2.0 License. The model weights are subject to the original license of the base model.