This project aims to generate a knowledge graph from PDF files by extracting text and identifying relations within the text. The generated knowledge graph can be visualized through a Streamlit-based frontend application. This project is an enhancement of work carried out in 2023-2024, available at the following link: KG-generation Repository.
The knowledge graph generation process involves extracting text from PDF files, identifying relationships within the text, and visualizing the relationships in a graph. This README provides a comprehensive guide on setting up the project and running the application.
Clone the repository to your local machine:
git clone https://github.com/blatrie/KG_generation_2.0.git
cd KG-generation_2.0
Install the required packages using pip :
pip3 install -r requirements.txt
Ensure the following Python packages are installed:
To obtain the fine-tuned models required for running the pipeline, which will be stored in the ./models directory, follow these steps:
Run the notebooks:
./src/finetuning/all_mini_finetuning.ipynb: This performs fine-tuning on two embedding models, all-Mini and bge-small, for a classification task../src/finetuning/finetuning_usable_text.ipynb: This fine-tunes bge-small for a different classification task.Run the following commands:
cd src/finetuning
Then:
python3 mrebel_finetuning.py
This script fine-tunes MRebel, a model used to extract triplets from text, specializing it in the economic domain.
Finally, the ./src/finetuning/data directory contains the training data required for fine-tuning. Most of this data was generated using the scripts generate_article_triples.py and generate_text_chunks.py, located in the ./src/finetuning directory.
Install Docker if not already installed. Refer to the official documentation for installation instructions.
Start Docker by running the following command:
sudo service docker start
sudo docker run -p 7687:7687 -p 7444:7444 -p 3000:3000 --name memgraph memgraph/memgraph-platform
sudo docker start memgraph
The pipeline consists of the following steps:
This pipeline automates the transformation of unstructured text into a structured knowledge graph, enabling efficient knowledge extraction and visualization.
Both the admin and user interfaces need memgraph to be running. Ensure that memgraph is running before proceeding (refer to the Memgraph Installation section for instructions).
Run the main.py file for the first time to build streamlit web-app and to execute the knowledge graph generation process :
python3 src/pipeline/main.py
Then run the streamlit web-app :
streamlit run src/pipeline/main.py
If you encounter any issues, run the following command in the terminal and run the Streamlit app again.
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
Visit http://localhost:8501 in your web browser to access the admin web-app.
To run the UI interface :
cd src/web-app
python3 app.py
:warning: DO NOT run python3 src/web-app directly: otherwise you won't be able to use radius search in the graph
├── KGG_2024.pdf
├── KGG_Presentation.pdf
├── README.md
├── articles_KGG
├── docker-compose.yml
├── dockerfile
├── documentation.html
├── generate_doc.py
├── requirements.txt
└── src
├── evaluation
│ ├── pykeen_metrics.py
│ └── tf_idf.py
├── finetuning
│ ├── all_mini_finetuning.ipynb
│ ├── data
│ ├── finetuning_usable_text.ipynb
│ ├── generate_article_triples.py
│ ├── generate_text_chunks.py
│ └── mrebel_finetuning.py
├── pipeline
│ ├── KB_generation.py
│ ├── clustering_merge.py
│ ├── llama.py
│ ├── main.py
│ ├── params.py
│ ├── pre_merge.py
│ ├── semantic_segmentation.py
│ ├── text_selection.py
│ └── translation.py
└── web-app
├── app.py
├── assets
├── forms
├── game_of_thrones.html
├── graph.html
├── index.html
└── lib
1 commits
Jupyter Notebook
50.5%
HTML
28.4%
Python
15.0%
JavaScript
3.2%
CSS
2.8%
This project aims to generate a knowledge graph from PDF files by extracting text and identifying relations within the text. The generated knowledge graph can be visualized through a Streamlit-based frontend application. This project is an enhancement of work carried out in 2023-2024, available at the following link: KG-generation Repository.
The knowledge graph generation process involves extracting text from PDF files, identifying relationships within the text, and visualizing the relationships in a graph. This README provides a comprehensive guide on setting up the project and running the application.
Clone the repository to your local machine:
git clone https://github.com/blatrie/KG_generation_2.0.git
cd KG-generation_2.0
Install the required packages using pip :
pip3 install -r requirements.txt
Ensure the following Python packages are installed:
To obtain the fine-tuned models required for running the pipeline, which will be stored in the ./models directory, follow these steps:
Run the notebooks:
./src/finetuning/all_mini_finetuning.ipynb: This performs fine-tuning on two embedding models, all-Mini and bge-small, for a classification task../src/finetuning/finetuning_usable_text.ipynb: This fine-tunes bge-small for a different classification task.Run the following commands:
cd src/finetuning
Then:
python3 mrebel_finetuning.py
This script fine-tunes MRebel, a model used to extract triplets from text, specializing it in the economic domain.
Finally, the ./src/finetuning/data directory contains the training data required for fine-tuning. Most of this data was generated using the scripts generate_article_triples.py and generate_text_chunks.py, located in the ./src/finetuning directory.
Install Docker if not already installed. Refer to the official documentation for installation instructions.
Start Docker by running the following command:
sudo service docker start
sudo docker run -p 7687:7687 -p 7444:7444 -p 3000:3000 --name memgraph memgraph/memgraph-platform
sudo docker start memgraph
The pipeline consists of the following steps:
This pipeline automates the transformation of unstructured text into a structured knowledge graph, enabling efficient knowledge extraction and visualization.
Both the admin and user interfaces need memgraph to be running. Ensure that memgraph is running before proceeding (refer to the Memgraph Installation section for instructions).
Run the main.py file for the first time to build streamlit web-app and to execute the knowledge graph generation process :
python3 src/pipeline/main.py
Then run the streamlit web-app :
streamlit run src/pipeline/main.py
If you encounter any issues, run the following command in the terminal and run the Streamlit app again.
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
Visit http://localhost:8501 in your web browser to access the admin web-app.
To run the UI interface :
cd src/web-app
python3 app.py
:warning: DO NOT run python3 src/web-app directly: otherwise you won't be able to use radius search in the graph
├── KGG_2024.pdf
├── KGG_Presentation.pdf
├── README.md
├── articles_KGG
├── docker-compose.yml
├── dockerfile
├── documentation.html
├── generate_doc.py
├── requirements.txt
└── src
├── evaluation
│ ├── pykeen_metrics.py
│ └── tf_idf.py
├── finetuning
│ ├── all_mini_finetuning.ipynb
│ ├── data
│ ├── finetuning_usable_text.ipynb
│ ├── generate_article_triples.py
│ ├── generate_text_chunks.py
│ └── mrebel_finetuning.py
├── pipeline
│ ├── KB_generation.py
│ ├── clustering_merge.py
│ ├── llama.py
│ ├── main.py
│ ├── params.py
│ ├── pre_merge.py
│ ├── semantic_segmentation.py
│ ├── text_selection.py
│ └── translation.py
└── web-app
├── app.py
├── assets
├── forms
├── game_of_thrones.html
├── graph.html
├── index.html
└── lib
1 commits
Jupyter Notebook
50.5%
HTML
28.4%
Python
15.0%
JavaScript
3.2%
CSS
2.8%