This is the source code for the paper "Can LLMs Lie? Investigation beyond Hallucination".
Get a quick overview of the project at: https://llm-liar.github.io/.
Install with pip install -e ".[all]".
Then all env vars needed to be set are:
data/counterfact-qa.[Optional] Reproduce data/combination_results.pt by running python steer_scripts/multi.py.
Evaluate how the steering vectors controls different types of lying, by running python steer_scripts/type_eval.py.
Evaluate derived steering vectors on the multiround salesperson setting: python steer_scripts/pareto.py.
You can test the model with 0/1/2/4/8/16/20 lying heads disabled on free generation: cd scripts2 && python head_demo.py.
If you want to search for heads yourself follow these steps:
unzip data/counterfact-qa.zipcd scripts2 && python head_search_v3.py. This shall generate results.yaml in the specified output pathresults.yaml, and overwrite the hardcoded HEADS_TO_DISABLE in scripts2/head_demo.pyIn case of insufficient VRAM, run python head_search_v3.py search.batch_size=1.
You need to set up API keys for evaluation. There are two options:
mech_interp_scripts/gpt_rater.py: Change API_KEY = "FAKE_API_KEY" to your OpenRouter API keymech_interp_scripts/openrouter_eval.py: Set your OpenRouter API keyAlternatively, you can use OpenAI's API by uncommenting the OpenAI client configuration in mech_interp_scripts/gpt_rater.py and setting:
This section contains two main scripts for evaluation and visualization:
Use openrouter_eval.py to run the evaluation with the following parameters:
--model_name: Name of the model to evaluate (default: "meta-llama--Llama-3.1-8B-Instruct")--output_root: Root directory for results (default: "results")--output_dir: Output directory name (default: "openrouter_eval")--n_data: Number of data points to evaluate (default: 100)--lie_suffix_path: Path to lie suffixes file (default: "lie_suffixes.yaml")--use_cot: Enable/disable chain of thought reasoning (optional flag)Run plot_liar_eval.py to visualize the evaluation results. The script reads data from the results directory by default and generates visualization plots for the liar score comparison.
This section contains scripts for generating baseline data using the counterfact dataset:
eval_llama_8b.py: Generates baseline data for LLaMA modelseval_qwen.py: Generates baseline data for Qwen modelseval_data_analysis.py: Analyzes the deception scores for each lie suffixThese scripts:
--model_name # Model to evaluate (e.g., "meta-llama--Llama-3.1-8B-Instruct")
--n_data # Number of examples to process
--output_root # Root directory for results (default: "results")
--output_dir # Output directory name
--eval_model # Model for evaluation ("gpt-4o" or "gpt-4o-mini")
--lie_suffix_path # Path to the file containing lie-inducing prompts
The scripts will generate a YAML file containing:
This section contains various experiments for analyzing model behavior by zeroing out different components:
intent_all_zero_gpt.py: Zeros out attention scores from intent tokens to the end of the intent sentence in the last k tokens (by default, masks 4 dummy tokens [-5:-1], excluding the final prediction token)
intent_subject_zero_gpt.py: Zeros out attention scores or key/value from intent/subject/both tokens in the last k tokens (by default, masks 4 dummy tokens [-5:-1], excluding the final prediction token)
intent2all_last_zero_gpt.py: Zeros out attention scores from intent/subject tokens to the last k tokens in the last token's query (by default, masks 4 dummy tokens [-5:-1], excluding the final prediction token)
intent2all_zero_gpt.py: Similar to above but for last k tokens' query (by default, masks 4 dummy tokens [-5:-1], excluding the final prediction token)
last_token_zero_gpt.py: Zeros out residual/attention/MLP outputs for the last token
last_token_zero_head_gpt.py: Zeros out specific attention heads in a given layer for the last token
token_attn_zero_gpt.py: Zeros out attention scores or key/value for the last k tokens in the last token's query (by default, masks 4 dummy tokens [-5:-1], excluding the final prediction token)
token_zero_gpt.py: Zeros out various components (residual/attention/MLP) for the last k tokens (by default, masks 4 dummy tokens [-5:-1], excluding the final prediction token)
Most scripts share these common parameters:
--model_name # Model to evaluate (e.g., "meta-llama--Llama-3.1-8B-Instruct")
--n_data # Number of examples to process
--output_root # Root directory for results (default: "results")
--output_dir # Output directory name
--eval_model # Model for evaluation ("gpt-4o" or "gpt-4o-mini")
--window_size # Window size for zeroing (default: 1)
--recorded_data_dir # Directory containing recorded data
python scripts/token_zero_gpt.py \
--model_name meta-llama--Llama-3.1-8B-Instruct \
--n_data 200 \
--output_dir experiment_results \
--eval_model gpt-4o \
--layer_type mlp \
--window_size 5 \
--recorded_data_dir eval_data
Each script will generate:
Special thanks to https://github.com/kmeng01/rome that inspired the earliest versions of this code.
6 commits
HTML
99.8%
This is the source code for the paper "Can LLMs Lie? Investigation beyond Hallucination".
Get a quick overview of the project at: https://llm-liar.github.io/.
Install with pip install -e ".[all]".
Then all env vars needed to be set are:
data/counterfact-qa.[Optional] Reproduce data/combination_results.pt by running python steer_scripts/multi.py.
Evaluate how the steering vectors controls different types of lying, by running python steer_scripts/type_eval.py.
Evaluate derived steering vectors on the multiround salesperson setting: python steer_scripts/pareto.py.
You can test the model with 0/1/2/4/8/16/20 lying heads disabled on free generation: cd scripts2 && python head_demo.py.
If you want to search for heads yourself follow these steps:
unzip data/counterfact-qa.zipcd scripts2 && python head_search_v3.py. This shall generate results.yaml in the specified output pathresults.yaml, and overwrite the hardcoded HEADS_TO_DISABLE in scripts2/head_demo.pyIn case of insufficient VRAM, run python head_search_v3.py search.batch_size=1.
You need to set up API keys for evaluation. There are two options:
mech_interp_scripts/gpt_rater.py: Change API_KEY = "FAKE_API_KEY" to your OpenRouter API keymech_interp_scripts/openrouter_eval.py: Set your OpenRouter API keyAlternatively, you can use OpenAI's API by uncommenting the OpenAI client configuration in mech_interp_scripts/gpt_rater.py and setting:
This section contains two main scripts for evaluation and visualization:
Use openrouter_eval.py to run the evaluation with the following parameters:
--model_name: Name of the model to evaluate (default: "meta-llama--Llama-3.1-8B-Instruct")--output_root: Root directory for results (default: "results")--output_dir: Output directory name (default: "openrouter_eval")--n_data: Number of data points to evaluate (default: 100)--lie_suffix_path: Path to lie suffixes file (default: "lie_suffixes.yaml")--use_cot: Enable/disable chain of thought reasoning (optional flag)Run plot_liar_eval.py to visualize the evaluation results. The script reads data from the results directory by default and generates visualization plots for the liar score comparison.
This section contains scripts for generating baseline data using the counterfact dataset:
eval_llama_8b.py: Generates baseline data for LLaMA modelseval_qwen.py: Generates baseline data for Qwen modelseval_data_analysis.py: Analyzes the deception scores for each lie suffixThese scripts:
--model_name # Model to evaluate (e.g., "meta-llama--Llama-3.1-8B-Instruct")
--n_data # Number of examples to process
--output_root # Root directory for results (default: "results")
--output_dir # Output directory name
--eval_model # Model for evaluation ("gpt-4o" or "gpt-4o-mini")
--lie_suffix_path # Path to the file containing lie-inducing prompts
The scripts will generate a YAML file containing:
This section contains various experiments for analyzing model behavior by zeroing out different components:
intent_all_zero_gpt.py: Zeros out attention scores from intent tokens to the end of the intent sentence in the last k tokens (by default, masks 4 dummy tokens [-5:-1], excluding the final prediction token)
intent_subject_zero_gpt.py: Zeros out attention scores or key/value from intent/subject/both tokens in the last k tokens (by default, masks 4 dummy tokens [-5:-1], excluding the final prediction token)
intent2all_last_zero_gpt.py: Zeros out attention scores from intent/subject tokens to the last k tokens in the last token's query (by default, masks 4 dummy tokens [-5:-1], excluding the final prediction token)
intent2all_zero_gpt.py: Similar to above but for last k tokens' query (by default, masks 4 dummy tokens [-5:-1], excluding the final prediction token)
last_token_zero_gpt.py: Zeros out residual/attention/MLP outputs for the last token
last_token_zero_head_gpt.py: Zeros out specific attention heads in a given layer for the last token
token_attn_zero_gpt.py: Zeros out attention scores or key/value for the last k tokens in the last token's query (by default, masks 4 dummy tokens [-5:-1], excluding the final prediction token)
token_zero_gpt.py: Zeros out various components (residual/attention/MLP) for the last k tokens (by default, masks 4 dummy tokens [-5:-1], excluding the final prediction token)
Most scripts share these common parameters:
--model_name # Model to evaluate (e.g., "meta-llama--Llama-3.1-8B-Instruct")
--n_data # Number of examples to process
--output_root # Root directory for results (default: "results")
--output_dir # Output directory name
--eval_model # Model for evaluation ("gpt-4o" or "gpt-4o-mini")
--window_size # Window size for zeroing (default: 1)
--recorded_data_dir # Directory containing recorded data
python scripts/token_zero_gpt.py \
--model_name meta-llama--Llama-3.1-8B-Instruct \
--n_data 200 \
--output_dir experiment_results \
--eval_model gpt-4o \
--layer_type mlp \
--window_size 5 \
--recorded_data_dir eval_data
Each script will generate:
Special thanks to https://github.com/kmeng01/rome that inspired the earliest versions of this code.
6 commits
HTML
99.8%