Pip package for VeriScore
Project description
VeriScore
This is introduction for pip package of VeriScore. It have two type of method to extract claims by
- Prompting
- Fine-tuned model
We have a preliminary Colab notebook for demo
VeriScore consists of three parts 1) claim extraction 2) evidence searching and 3) claim verification.
We provide an end-to-end pipeline to obtain the VeriScore, along with each of its components individually.
You can choose between a prompting-based approach and a fine-tuned model-based approach using the model_name option. If you specify the path to the checkpoint of a fine-tuned model, it will automatically access the local model to perform inference. If the model name is not in a directory format, it will use an API call instead.
Install
- Make a new Python 3.9+ environment using
virtualenvorconda. - Install
veriscorepacakge usingpip - Download
en_core_web_smusingspacylibrary - Our code supports inference using fine-tuned models based on the Unsloth library. To use this feature, you need to install the Unsloth library.
pip install --upgrade veriscore
python -m spacy download en_core_web_sm
Setup environment before running code
- Download
promptfolder that have txt file of prompt template (you can seepromptfolder VeriScore's repository) - Set OpenAI or Claude API key to environment variable of
bashfor prompting approach
export OPENAI_API_KEY_PERSONAL={your_openai_api_key}
export CLAUDE_API_KEY={your_claude_api_key}
- Set SERPER API key to environment variable of
bashfor searching evidence
export SERPER_KEY_PRIVATE={your_serper_api_key}
- For the prompt-based approach, you need to set
data_dir/demos/with few-shot examples.
Running VeriScore using a command line
This is an end-to-end pipeline for running VeriScore.
python3 -m veriscore.veriscore --data_dir {data_dir} --input_file {input_file} --model_name_extraction {model_name_extraction} --model_name_verification {model_name_verification}
data_dir: Directory containing input data../databy default.input_file: Name of input data file. It should bejsonlformat where each line containsquestion: query to askresponse: generated response from ofquestionmodel: name of model generate responseprompt_source: name of dataset providequestionlike FreshQA
model_name_extraction: Name of model used for claim extraction.gpt-4-0125-previewby default.model_name_verification: Name of model used for claim verification.gpt-4oby default.
Other optional flags:
output_dir: Directory for saving ouptut data../databy default.cache_dir: Directory for saving cache data../data/cacheby default.label_n: This is type of label for claim verification. It could be2(binary) ro3(trinary)2: query to ask binarysupportedandunsupported3: query to ask trinaylabels—supported,contradicted, andinconclusive
search_res_num: A Hyperparameter for number of search result.5by default.
Saving output:
input_file_name is file name removed jsonl from —-input_file
extracted claimswill be saved tooutput_dir/claims_{input_file_name}.jsonl.searched evidencewill be saved tooutput_dir/evidence_{input_file_name}.jsonl.verified claimswill be saved tooutput_dir/model_output/verification_{input_file_name}.jsonl.
Running individual part using a command line
Claim extraction:
python3 -m veriscore.extract_claims --data_dir {data_dir} --input_file {input_file} --model_name {model_name}
input_file: Name of input data file. It should bejsonlformat where each line containsquestion: query to askresponse: generated response from ofquestionmodel: name of model generate responseprompt_source: name of dataset providequestionlike FreshQA
model_name: Name of model used for claim extraction.gpt-4-0125-previewby default. output:
{
"question": question.strip(),
"prompt_source": prompt_source,
"response": response.strip(),
"prompt_tok_cnt": prompt_tok_cnt,
"response_tok_cnt": response_tok_cnt,
"model": model,
"abstained": False,
"claim_list": list of claims for each snippet,
"all_claims": list of all claims
}
Evidence searching:
python3 -m veriscore.retrieve_evidence --data_dir {data_dir} --input_file {input_file}
input_file: Name of input data file. It should bejsonlformat where each line contains the keys of the output dictionary from theClaim extraction. output:
{
...
"claim_snippets_dict": dictionary for claim and list of searched evidence. each evidence have dictionary of {"title": title, "snippet": snippet, "link": link}
}
Claim verification:
python3 -m veriscore.verify_claims --data_dir {data_dir} --input_file {input_file} --model_name {model_name}
input_file: Name of input data file. It should bejsonlformat where each line contains the keys of the output dictionary from theEvidence searching. output:
{
...
"response": result of claim verification
"clean_output": post-processed label
}
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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 veriscore-2.0.0.tar.gz.
File metadata
- Download URL: veriscore-2.0.0.tar.gz
- Upload date:
- Size: 16.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
848052e8a86be6124bc86821e5cf2de7602ee92a1be4202e0de07c9ca50f9d81
|
|
| MD5 |
0e96838ef42d001a37fbf205d9758a0b
|
|
| BLAKE2b-256 |
6af17aa7518229861ff857d041f3b6018b0cdeccd42748df21c158db218e1167
|
File details
Details for the file VeriScore-2.0.0-py3-none-any.whl.
File metadata
- Download URL: VeriScore-2.0.0-py3-none-any.whl
- Upload date:
- Size: 21.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32193329d329e73b70f29fab63776bd5081e3cb311bf57654ddae3c9548c99db
|
|
| MD5 |
468d44770d789d8d3475c45b9d978cf1
|
|
| BLAKE2b-256 |
1b982d8eaa0bde8d1480281a3a6844da8ab22284b934a4e4214366938fe17e67
|