This repository contains code for generating causal graphs from natural language textual data and performing counterfactual reasoning with large language models.
Run the following command to install the required packages:
pip install -r requirements.txtYou can install the packages ina virtual environment by running the following commands:
python -m venv venv
source venv/bin/activate
pip install -r requirements.txtFor evaluation, we use data from the Cladder dataset. The data is downloaded automatically from the Huggingface hub.
We also use real-world data from news article via EventRegistry. the dataset is not publicly available as of now but th raw data can be downloaded from here.
You can build a causal graph from text data by running the following command. Use the provided template to create your own configuration file.
python build_graph.py config/build_graph.yamlYou can perform counterfactual reasoning by running the following command. Load a generated causal graph and use the provided template to create your own configuration file.
python compute_counterfactuals.py config/counterfactual.yamlYou can perform end-to-end inference by running the following command. Use the provided template to create your own configuration file.
python end_to_end.py config/end_to_end.yamlEvaluate the model on the Cladder dataset by running the following command:
python evaluate.py config/cladder_evaluate.yamlThe built causal graphs have the following attributes:
Nodes:
description: [str] A description of the causal variabletype: [str] The type of the causal variablevalues: [str] The possible values of the causal variablecurrent_value: [str] The current value of the causal variablecontext: [str] The context in which the causal variable is definedobserved: [bool] Whether the causal variable is observed or notlayer: [int] (Optional) The layer of the causal variable in the topological causal graph (used for visualisation)updated_value: [str] (Optional) The updated value of the causal variable after inference
Edges:
description: [str] A description of the causal relationshipdetails: [str] Additional details about the causal relationshipobserved: [bool] Whether the causal relationship is observed or not