A tool for reference-free hallucination detection in LLM-generated responses
Project description
Installation
pip install hallucounter
Hallucounter Usage
### Import
from hallucounter.detector import load_classifier, get_predictions, get_pipeline_output
from hallucounter.nli_scores import load_nli_model, get_nli_scores
### Load Classifier
clf = load_classifier('path_to_classification_model_file')
### Load NLI Cross-Encoder
nli_model, nli_tokenizer = load_nli_model() # takes optional parameter model_name. Unless specified, it uses nli-deberta-v3-large by default
### Define Query and Responses
query = "Which British athlete won the 100 m. at the 1924 Olympics?"
responses = ["Harold Abrahams.", "Harold Abrahams.","Harold Abrahams.","Harold Abrahams.","Harold Abrahams."] # Here, K=5
nli_scores = get_nli_scores(query, responses, nli_model, nli_tokenizer)
### Get the Hallucounter pipeline output
overall_prediction, confidence_score, optimal_response = get_pipeline_output(nli_scores, clf, responses)
print("Overall Prediction:", overall_prediction)
print("Optimal Response:", optimal_response)
print("Confidence Score:", confidence_score)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
hallucounter-1.0.0.tar.gz
(3.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hallucounter-1.0.0.tar.gz.
File metadata
- Download URL: hallucounter-1.0.0.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2b6e0da509718dc4a18afdc0e2d9087847da8540fb11ce69d4289a0b4687d97
|
|
| MD5 |
c9e415c2d5ab7f6ff920e26dbbe41249
|
|
| BLAKE2b-256 |
cc80baaee74d3a0a21b3fd41f0f83c80e29f0969766e26d0fab13d08fe4368ac
|
File details
Details for the file hallucounter-1.0.0-py3-none-any.whl.
File metadata
- Download URL: hallucounter-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eaf2cab067a2ef3e0b30b07df830dbf981db814fc3b591f69a53aabda764d9de
|
|
| MD5 |
ae9d9c1bf658019031091162f1323eab
|
|
| BLAKE2b-256 |
58e3d001fd32710a12c5296c576837c1622169942b5964036c253c075a8b4a1d
|