Update README.md
Browse files
README.md
CHANGED
|
@@ -89,22 +89,18 @@ Use the code below to get started with the model.
|
|
| 89 |
|
| 90 |
Install the Inference Code
|
| 91 |
|
| 92 |
-
|
|
|
|
|
|
|
| 93 |
|
| 94 |
Run the HDM-2 model
|
| 95 |
|
|
|
|
| 96 |
# Load the model from HuggingFace into the GPU
|
| 97 |
|
| 98 |
-
<!---->
|
| 99 |
-
|
| 100 |
from hdm2 import HallucinationDetectionModel
|
| 101 |
-
|
| 102 |
-
<!---->
|
| 103 |
-
|
| 104 |
hdm_model = HallucinationDetectionModel()
|
| 105 |
|
| 106 |
-
<!---->
|
| 107 |
-
|
| 108 |
prompt = "Explain how the heart functions"
|
| 109 |
context = """
|
| 110 |
The heart is a muscular organ that pumps blood throughout the body.
|
|
@@ -122,21 +118,19 @@ Run the HDM-2 model
|
|
| 122 |
# average heart weighs ~10 oz (not 5 pounds),
|
| 123 |
# and beats ~2.5 billion times (not 2 million) in a lifetime
|
| 124 |
|
| 125 |
-
<!---->
|
| 126 |
-
|
| 127 |
# Detect hallucinations with default parameters
|
| 128 |
results = hdm_model.apply(prompt, context, response)
|
|
|
|
| 129 |
|
| 130 |
Print the results
|
| 131 |
|
|
|
|
| 132 |
# Utility function to help with printing the model output
|
| 133 |
def print_results(results):
|
| 134 |
#print(results)
|
| 135 |
# Print results
|
| 136 |
print(f"\nHallucination severity: {results['adjusted_hallucination_severity']:.4f}")
|
| 137 |
|
| 138 |
-
<!---->
|
| 139 |
-
|
| 140 |
# Print hallucinated sentences
|
| 141 |
if results['candidate_sentences']:
|
| 142 |
print("\nPotentially hallucinated sentences:")
|
|
@@ -149,11 +143,10 @@ Print the results
|
|
| 149 |
print("No hallucinated sentences detected.")
|
| 150 |
else:
|
| 151 |
print("\nNo hallucinated sentences detected.")
|
| 152 |
-
|
| 153 |
-
<!---->
|
| 154 |
-
|
| 155 |
print_results(results)
|
| 156 |
|
|
|
|
|
|
|
| 157 |
```
|
| 158 |
OUTPUT:
|
| 159 |
|
|
|
|
| 89 |
|
| 90 |
Install the Inference Code
|
| 91 |
|
| 92 |
+
```bash
|
| 93 |
+
pip install hdm2 --quiet
|
| 94 |
+
```
|
| 95 |
|
| 96 |
Run the HDM-2 model
|
| 97 |
|
| 98 |
+
```python
|
| 99 |
# Load the model from HuggingFace into the GPU
|
| 100 |
|
|
|
|
|
|
|
| 101 |
from hdm2 import HallucinationDetectionModel
|
|
|
|
|
|
|
|
|
|
| 102 |
hdm_model = HallucinationDetectionModel()
|
| 103 |
|
|
|
|
|
|
|
| 104 |
prompt = "Explain how the heart functions"
|
| 105 |
context = """
|
| 106 |
The heart is a muscular organ that pumps blood throughout the body.
|
|
|
|
| 118 |
# average heart weighs ~10 oz (not 5 pounds),
|
| 119 |
# and beats ~2.5 billion times (not 2 million) in a lifetime
|
| 120 |
|
|
|
|
|
|
|
| 121 |
# Detect hallucinations with default parameters
|
| 122 |
results = hdm_model.apply(prompt, context, response)
|
| 123 |
+
```
|
| 124 |
|
| 125 |
Print the results
|
| 126 |
|
| 127 |
+
```python
|
| 128 |
# Utility function to help with printing the model output
|
| 129 |
def print_results(results):
|
| 130 |
#print(results)
|
| 131 |
# Print results
|
| 132 |
print(f"\nHallucination severity: {results['adjusted_hallucination_severity']:.4f}")
|
| 133 |
|
|
|
|
|
|
|
| 134 |
# Print hallucinated sentences
|
| 135 |
if results['candidate_sentences']:
|
| 136 |
print("\nPotentially hallucinated sentences:")
|
|
|
|
| 143 |
print("No hallucinated sentences detected.")
|
| 144 |
else:
|
| 145 |
print("\nNo hallucinated sentences detected.")
|
|
|
|
|
|
|
|
|
|
| 146 |
print_results(results)
|
| 147 |
|
| 148 |
+
```
|
| 149 |
+
|
| 150 |
```
|
| 151 |
OUTPUT:
|
| 152 |
|