Codes for "Developing a Domain-Specific Large Language Model for Energy Knowledge and Policy"
Since the entire pipeline involves numerous LLM API operations, and we allow users to configure different API services for each operation, please pay attention to several configurable API-related constants in the script for operations that require API calls.
BASE_URL specifies the base URL of your API service platform.API_KEY specifies your API key.MODEL_NAME specifies the model you wish to use with your API service, and it should follow the format required by the API service provider.Please first navigate to the train_energy_bonito directory by using the cd command: cd train_energy_bonito
By modifying variables RATIO and dir which represent the sample ratio and input JSON file directory respectively, you can sample the content chunk from the JSON file and generate a list which will be stored as an output JSON file with your defined SAVE_FILE_NAME by running:
python sample.py
By defining all the required constants including API settings and input/output file in generate_bonito_tuning_with_api.py, you can run the script to generate a structured JSON file with API generated QA pairs:
python generate_bonito_tuning_with_api.py
Defining input and output file directory then run:
python transfer.py
to transfer the JSON file into a QA pairs dataset with structures suitable for Bonito training. You can change the RATIO representing the dropping ratio of the negative cases. We preserve a small ratio of the negative cases to ensure robustness of our Energy-Bonito.
Please first navigate to the energy_bonito_inference directory by using the cd command: cd energy_bonito_inference
First, you need to define a YAML file for the trained Bonito model to configure your Energy-Bonito settings, using the checkpoint obtained in the previous step. You can specify the number of parallel processes, with each GPU assigned to one process by default. To set up the service, run the following command:
python bonito_service_setup.py
After setting up the model service, we can use the two scripts located at this path to generate MC and QA data based on the corpus, respectively.
python bonito_inferece_distributed_MC.py
python bonito_inference_distributed_QA.py
Please first navigate to the knowledge_network directory by using the cd command: cd knowledge_network
In this section, we break down the entire process sequentially, from the expert-derived knowledge network to the final knowledge network tuning data.
By default, we use XMind. You can provide the path to an XMind file and convert it into JSON by running the following command:
python read_xmind.py
python generate_syllubus_and_class_sessions.py
python generate_questions.py
python deduplication_questions.py
We build an RAGFlow system and expose an API to generate answers. However, you can use any RAG system and its API, as long as it is compatible with the OpenAI API style. To run the generation process, identify the RAG API and execute the following command:
python ragflow_api_generate_answer.py
python gather_knowledge_network_tuning.py
Please first navigate to the generate_based_on_graphrag directory by using the cd command: cd generate_based_on_graphrag
append_meta_data.py: Append metadata, including release time, district, or outline etc, to the data frame in the GraphRAG system.generate_qa_pairs.py: Request the GraphRAG system to generate QA pair data.Please first navigate to the bench_energy_llm directory by using the cd command: cd bench_energy_llm
After using the data generated from the previous processes to train your Energy-LLM, we provide a benchmark to evaluate the model's performance on knowledge in the new energy sector.
bench_multi_choice: This folder contains two scripts for testing API-based and local models on benchmark MC questions. For API-based models, you need to define the API settings. For local models, you can deploy the models in a llama-factory compatible style and expose a port to the script. Additionally, you can switch between Easy or Hard MC in the script.
bench_short_questions: In this folder, we provide a script for your models, either local or API-based, to answer benchmark subjective questions. You can then grade the answers using BERTScore by running:
python grade_short_answer.py
Python
75.8%
C++
13.7%
Shell
5.6%
Java
2.8%
Codes for "Developing a Domain-Specific Large Language Model for Energy Knowledge and Policy"
Since the entire pipeline involves numerous LLM API operations, and we allow users to configure different API services for each operation, please pay attention to several configurable API-related constants in the script for operations that require API calls.
BASE_URL specifies the base URL of your API service platform.API_KEY specifies your API key.MODEL_NAME specifies the model you wish to use with your API service, and it should follow the format required by the API service provider.Please first navigate to the train_energy_bonito directory by using the cd command: cd train_energy_bonito
By modifying variables RATIO and dir which represent the sample ratio and input JSON file directory respectively, you can sample the content chunk from the JSON file and generate a list which will be stored as an output JSON file with your defined SAVE_FILE_NAME by running:
python sample.py
By defining all the required constants including API settings and input/output file in generate_bonito_tuning_with_api.py, you can run the script to generate a structured JSON file with API generated QA pairs:
python generate_bonito_tuning_with_api.py
Defining input and output file directory then run:
python transfer.py
to transfer the JSON file into a QA pairs dataset with structures suitable for Bonito training. You can change the RATIO representing the dropping ratio of the negative cases. We preserve a small ratio of the negative cases to ensure robustness of our Energy-Bonito.
Please first navigate to the energy_bonito_inference directory by using the cd command: cd energy_bonito_inference
First, you need to define a YAML file for the trained Bonito model to configure your Energy-Bonito settings, using the checkpoint obtained in the previous step. You can specify the number of parallel processes, with each GPU assigned to one process by default. To set up the service, run the following command:
python bonito_service_setup.py
After setting up the model service, we can use the two scripts located at this path to generate MC and QA data based on the corpus, respectively.
python bonito_inferece_distributed_MC.py
python bonito_inference_distributed_QA.py
Please first navigate to the knowledge_network directory by using the cd command: cd knowledge_network
In this section, we break down the entire process sequentially, from the expert-derived knowledge network to the final knowledge network tuning data.
By default, we use XMind. You can provide the path to an XMind file and convert it into JSON by running the following command:
python read_xmind.py
python generate_syllubus_and_class_sessions.py
python generate_questions.py
python deduplication_questions.py
We build an RAGFlow system and expose an API to generate answers. However, you can use any RAG system and its API, as long as it is compatible with the OpenAI API style. To run the generation process, identify the RAG API and execute the following command:
python ragflow_api_generate_answer.py
python gather_knowledge_network_tuning.py
Please first navigate to the generate_based_on_graphrag directory by using the cd command: cd generate_based_on_graphrag
append_meta_data.py: Append metadata, including release time, district, or outline etc, to the data frame in the GraphRAG system.generate_qa_pairs.py: Request the GraphRAG system to generate QA pair data.Please first navigate to the bench_energy_llm directory by using the cd command: cd bench_energy_llm
After using the data generated from the previous processes to train your Energy-LLM, we provide a benchmark to evaluate the model's performance on knowledge in the new energy sector.
bench_multi_choice: This folder contains two scripts for testing API-based and local models on benchmark MC questions. For API-based models, you need to define the API settings. For local models, you can deploy the models in a llama-factory compatible style and expose a port to the script. Additionally, you can switch between Easy or Hard MC in the script.
bench_short_questions: In this folder, we provide a script for your models, either local or API-based, to answer benchmark subjective questions. You can then grade the answers using BERTScore by running:
python grade_short_answer.py
Python
75.8%
C++
13.7%
Shell
5.6%
Java
2.8%