Add example running a local hallucination detection
Browse files
README.md
CHANGED
@@ -184,7 +184,7 @@ docker run \
|
|
184 |
```
|
185 |
|
186 |
We validated the model on arm64 with [vLLM](https://github.com/vllm-project/vllm) on Nvidia GH200 as well with max outputs up to 64k tokens:
|
187 |
-
```
|
188 |
docker run \
|
189 |
--gpus all \
|
190 |
--ipc=host \
|
@@ -199,6 +199,92 @@ docker run \
|
|
199 |
--enable_prefix_caching
|
200 |
```
|
201 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
# 4. Model Details
|
203 |
|
204 |
## 4.1 Overview
|
|
|
184 |
```
|
185 |
|
186 |
We validated the model on arm64 with [vLLM](https://github.com/vllm-project/vllm) on Nvidia GH200 as well with max outputs up to 64k tokens:
|
187 |
+
```bash
|
188 |
docker run \
|
189 |
--gpus all \
|
190 |
--ipc=host \
|
|
|
199 |
--enable_prefix_caching
|
200 |
```
|
201 |
|
202 |
+
Detect hallucinations from context, example uses halubench:
|
203 |
+
```python
|
204 |
+
decompose_system_instruction = """
|
205 |
+
<TASK>
|
206 |
+
You are a fair judge that detects hallucinations and unjustified assumptions from question-document-answer triplets provided by the user.
|
207 |
+
Always follow the instructions below and provide your reasoning and verdict in the format specified.
|
208 |
+
</TASK>
|
209 |
+
|
210 |
+
<INSTRUCTIONS>
|
211 |
+
#1. Identify key elements in the question.
|
212 |
+
#2. List all relevant facts provided in the document.
|
213 |
+
#3. Break down the answer into its component claims.
|
214 |
+
#4. For each claim in the answer:
|
215 |
+
#a. Is it explicitly supported by the document? If yes, quote the relevant part.
|
216 |
+
#b. Is it a reasonable inference from the document? If yes, explain the reasoning.
|
217 |
+
#c. Is it unsupported or contradicted by the document? If yes, explain why.
|
218 |
+
#5. Check for any information in the answer that's present in the question but not in the document.
|
219 |
+
#6. Verify that no additional information is introduced in the answer that isn't in the document or question.
|
220 |
+
#7. Assess if the answer makes any unjustified connections or assumptions.
|
221 |
+
</INSTRUCTIONS>
|
222 |
+
|
223 |
+
<OUTPUT_EXAMPLE>
|
224 |
+
{"REASONING": "Your reasoning here where you cite the instruction step by number and provide your reasoning", "VERDICT": "PASS" or "FAIL"}
|
225 |
+
</OUTPUT_EXAMPLE>
|
226 |
+
"""
|
227 |
+
|
228 |
+
decompose_prompt = """
|
229 |
+
<QUESTION>: {question} </QUESTION>
|
230 |
+
<DOCUMENT>: {document} </DOCUMENT>
|
231 |
+
<ANSWER>: {answer} </ANSWER>
|
232 |
+
""".strip()
|
233 |
+
|
234 |
+
import os
|
235 |
+
import json
|
236 |
+
import pandas as pd
|
237 |
+
from openai import OpenAI
|
238 |
+
from pprint import pprint
|
239 |
+
from pydantic import BaseModel
|
240 |
+
|
241 |
+
testset_df = pd.read_parquet("hf://datasets/PatronusAI/HaluBench/data/test-00000-of-00001.parquet")
|
242 |
+
testset_df = testset_df.sample(frac=1).reset_index(drop=True)
|
243 |
+
|
244 |
+
class DecomposeResponse(BaseModel):
|
245 |
+
REASONING: str
|
246 |
+
VERDICT: str
|
247 |
+
|
248 |
+
client = OpenAI(base_url="http://localhost:8000/v1") # export a different one for e.g. sglang, openrouter, etc.
|
249 |
+
|
250 |
+
response = client.beta.chat.completions.parse(
|
251 |
+
model="root-signals/RootSignals-Judge-Llama-70B", # or `RootJudge` if you are using the RootSignals API
|
252 |
+
messages=[
|
253 |
+
{"role": "system", "content": decompose_system_instruction},
|
254 |
+
{"role": "user", "content": decompose_prompt.format(
|
255 |
+
question=example_row["question"],
|
256 |
+
document=example_row["passage"],
|
257 |
+
answer=example_row["answer"])},
|
258 |
+
],
|
259 |
+
response_format=DecomposeResponse,
|
260 |
+
).choices[0].message.parsed
|
261 |
+
|
262 |
+
pprint(response.REASONING)
|
263 |
+
pprint(response.VERDICT)
|
264 |
+
```
|
265 |
+
|
266 |
+
```
|
267 |
+
> ('Following the instructions: #1, the key element in the question is the '
|
268 |
+
"nationality of the magazines. #2, the document states that 'The Woman's "
|
269 |
+
"Viewpoint was a woman's magazine founded in Texas in 1923' and 'Pick Me Up! "
|
270 |
+
"is a British weekly women's magazine'. #3, the answer claims both magazines "
|
271 |
+
'are British. #4, checking each claim in the answer: a) The document does not '
|
272 |
+
"support the claim that The Woman's Viewpoint is British, instead, it says "
|
273 |
+
"the magazine was founded in Texas. b) There's no reasonable inference from "
|
274 |
+
"the document that would suggest The Woman's Viewpoint is British. c) The "
|
275 |
+
"claim about The Woman's Viewpoint is contradicted by the document. #5, the "
|
276 |
+
'answer introduces information (both being British) not supported by the '
|
277 |
+
'document. #6, additional information about both magazines being British is '
|
278 |
+
'introduced in the answer without being present in the document or question. '
|
279 |
+
'#7, the answer makes an unjustified assumption by stating both magazines are '
|
280 |
+
"British despite the document clearly stating The Woman's Viewpoint was "
|
281 |
+
'founded in Texas, implying it is not British. Therefore, the answer fails to '
|
282 |
+
'accurately reflect the information provided in the document and makes '
|
283 |
+
'unjustified assumptions based on the information given in the question and '
|
284 |
+
"document.', ")
|
285 |
+
'FAIL'
|
286 |
+
```
|
287 |
+
|
288 |
# 4. Model Details
|
289 |
|
290 |
## 4.1 Overview
|