Utilizing Large Language Models for Causal Discovery and Legal Text Interpretation: A Case Study on the German GoZ
This is the source code to "Utilizing Large Language Models for Causal Discovery and Legal Text Interpretation: A Case Study on the German GoZ" The paper can be found here and the presentation here.
The project is split into two parts. The first part is in causal_discovery where preliminary experiments were conducted. The second and most important part of this project is the Python application in legal_reasoning.
It is a application that uses the OpenAI API to translate and process rules from the German Dentist Fee Schedule (GOZ) into a logical programming language. The data is preprocessed and stored in CSV files. The application uses the LLMs (Language Model) from OpenAI to extract rules and translate them into Prolog.
The workflow of the application can be seen in the following image:
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
- Python 3.8 or higher
- pip
- SWI Prolog available via command line
- OpenAI API key
- Clone the repository
- cd into legal_reasoning
- Install the required Python packages with
pip install -r requirements.txt
cd into legal_reasoning
To run the whole translation pipeline, run run.sh. The script will prompt you for all necessary parameters.
For executing the pipeline step by step, run the following scripts in order:
python .\text_preprocessing.py --OPENAI_API_KEY="<OPENAI_API_KEY>" --file_path="<PATH_OF_GOZ>" --output_file_path="<OUTPUT_PATH_1>" --use_commentary
python .\rule_extraction.py --OPENAI_API_KEY="<OPENAI_API_KEY>" --file_path="<OUTPUT_PATH_1>/de" --output_file_path="<OUTPUT_PATH_2>"
python .\rule_translation.py --OPENAI_API_KEY="<OPENAI_API_KEY>" --file_path="<OUTPUT_PATH_2>" --output_file_path="<OUTPUT_PATH_3>" --use_commentary
- For collecting all translated rules in one file, run
python .\rule_collector.py --file_path='<OUTPUT_PATH_3>/<SPECIFIC_FOLDER> --output_file_path=<PROLOG_RULES_FILE>'
- For converting a dentist invoice from json to prolog, run
python .\invoice_json_to_prolog.py --invoice_json_file='<PATH_OF_INVOICE_JSON>' --prolog_output_file='<INVOICE_PROLOG_OUTPUT_FILE>'
A example for a dentist invoice can be found in example_invoice.json - For testing the prologs rules against the invoice run
swipl -g "consult('<PROLOG_RULES_FILE>')" -g "consult('<INVOICE_PROLOG_OUTPUT_FILE>')" -g "example_invoice(X), is_invoice_invalid(X)." -t halt
- Jonas Zausinger - zausin33
This project is licensed under the MIT License - see the LICENSE.md file for details