Extract entities and relationships from biomedical text and build a knowledge graph.
Jupyter Notebook
3
28 commits
updated Sep 12, 2025
python3 text2knowledge.py classify-article --input-file ./classfication/example.json --output-file ./classfication/results/mixtral_8x22b.json -m mixtral:8x22b
Please refer to Prompts for more details.
If you want to extract all entities from the text, you can use the following command.
python3 text2knowledge.py extract-entities --text-file examples/text2knowledge/abstract.txt --output-file examples/text2knowledge/entities.json --model-name mistral:latest
If you want to extract all relations from the text, you can use the following command.
python3 text2knowledge.py extract-relations --text-file examples/text2knowledge/abstract.txt --output-file examples/text2knowledge/relationships.json --model-name mistral:latest
How to improve the accuracy of the entity extraction?
How to align the entities and relations? In current version, we extract entities and relations separately.
How to align all entities to the ontology items? Such as Hepatocellular carcinoma --> MONDO:0007256. You can access the BioPortal for learning more about the ontology items.
A new solution to convert text to knowledge graph
Extract all biomedical entities from the text by using a large language model (e.g. ChatGPT4, Vicuna, etc.)embeddingsMap all extracted entities to the ontology items by computing the similarity between the embeddings, and then pick up the top N similar ontology items for each entityre-rank the top N similar ontology items for each entity and pick up the top 1Generate questions from the mapped ontology items. If we have ten entities, we can generate C(10, 2) = 10! / [2!(10-2)!] = (10 _ 9) / (2 _ 1) = 45 questions. We can reduce the number of questions based on our needs, such as we only care about the specific entities.Pick up the answer for each question from the text by using a large language model (e.g. ChatGPT4, Vicuna, etc.)NOTE: Read the README.md in the chatbot folder for more detail [Not Ready Yet]. Or you can use another open source project Ollama or Ollama Github instead of our chatbot.
After you install the Ollama, you can run the following command to pull the models and launch the Ollama server.
ollama pull mistral-openorca:latest
# or
bash pull_models.sh
This step might not a required step for you. If you have installed the Ollama in macosx, you can also click the Ollama icon in the application folder to launch the Ollama server.
ollama serve
After you launch the Ollama server, you can open the following link in your browser to show all the availabel models.
http://127.0.0.1:11434/api/tags
If you have limited storage space in your computer, you can change the storage path to another disk. More details on how to change the storage path, please refer to the Ollama FAQs.
echo 'OLLAMA_MODELS=/path/to/your/disk' >> ~/.bashrc
source ~/.bashrc
Benchmarking Datasets and Tools for Biomedical NLP
You can refer to these papers/models/companies for more details.
We welcome and appreciate any contributions from the community members. If you wish to contribute to Text2Knowledge, please follow these steps:
Please ensure that your code adheres to the project's coding style and quality standards before submitting your contribution.
Text2Knowledge is released under the MIT License. For more details, please refer to the LICENSE.md file in the repository.
28 commits
Jupyter Notebook
69.8%
Python
24.4%
Rust
5.6%
Extract entities and relationships from biomedical text and build a knowledge graph.
Jupyter Notebook
3
28 commits
updated Sep 12, 2025
python3 text2knowledge.py classify-article --input-file ./classfication/example.json --output-file ./classfication/results/mixtral_8x22b.json -m mixtral:8x22b
Please refer to Prompts for more details.
If you want to extract all entities from the text, you can use the following command.
python3 text2knowledge.py extract-entities --text-file examples/text2knowledge/abstract.txt --output-file examples/text2knowledge/entities.json --model-name mistral:latest
If you want to extract all relations from the text, you can use the following command.
python3 text2knowledge.py extract-relations --text-file examples/text2knowledge/abstract.txt --output-file examples/text2knowledge/relationships.json --model-name mistral:latest
How to improve the accuracy of the entity extraction?
How to align the entities and relations? In current version, we extract entities and relations separately.
How to align all entities to the ontology items? Such as Hepatocellular carcinoma --> MONDO:0007256. You can access the BioPortal for learning more about the ontology items.
A new solution to convert text to knowledge graph
Extract all biomedical entities from the text by using a large language model (e.g. ChatGPT4, Vicuna, etc.)embeddingsMap all extracted entities to the ontology items by computing the similarity between the embeddings, and then pick up the top N similar ontology items for each entityre-rank the top N similar ontology items for each entity and pick up the top 1Generate questions from the mapped ontology items. If we have ten entities, we can generate C(10, 2) = 10! / [2!(10-2)!] = (10 _ 9) / (2 _ 1) = 45 questions. We can reduce the number of questions based on our needs, such as we only care about the specific entities.Pick up the answer for each question from the text by using a large language model (e.g. ChatGPT4, Vicuna, etc.)NOTE: Read the README.md in the chatbot folder for more detail [Not Ready Yet]. Or you can use another open source project Ollama or Ollama Github instead of our chatbot.
After you install the Ollama, you can run the following command to pull the models and launch the Ollama server.
ollama pull mistral-openorca:latest
# or
bash pull_models.sh
This step might not a required step for you. If you have installed the Ollama in macosx, you can also click the Ollama icon in the application folder to launch the Ollama server.
ollama serve
After you launch the Ollama server, you can open the following link in your browser to show all the availabel models.
http://127.0.0.1:11434/api/tags
If you have limited storage space in your computer, you can change the storage path to another disk. More details on how to change the storage path, please refer to the Ollama FAQs.
echo 'OLLAMA_MODELS=/path/to/your/disk' >> ~/.bashrc
source ~/.bashrc
Benchmarking Datasets and Tools for Biomedical NLP
You can refer to these papers/models/companies for more details.
We welcome and appreciate any contributions from the community members. If you wish to contribute to Text2Knowledge, please follow these steps:
Please ensure that your code adheres to the project's coding style and quality standards before submitting your contribution.
Text2Knowledge is released under the MIT License. For more details, please refer to the LICENSE.md file in the repository.
28 commits
Jupyter Notebook
69.8%
Python
24.4%
Rust
5.6%