{"id":29133338,"url":"https://github.com/rose-stl-lab/adapting-while-learning","last_synced_at":"2025-06-30T07:03:16.847Z","repository":{"id":299808461,"uuid":"830756679","full_name":"Rose-STL-Lab/Adapting-While-Learning","owner":"Rose-STL-Lab","description":"Grounding LLMs with physics","archived":false,"fork":false,"pushed_at":"2025-06-18T11:24:53.000Z","size":1448,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-18T12:36:26.523Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Rose-STL-Lab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-07-18T23:46:46.000Z","updated_at":"2025-06-18T11:24:56.000Z","dependencies_parsed_at":"2025-06-18T12:40:48.258Z","dependency_job_id":null,"html_url":"https://github.com/Rose-STL-Lab/Adapting-While-Learning","commit_stats":null,"previous_names":["rose-stl-lab/adapting-while-learning"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Rose-STL-Lab/Adapting-While-Learning","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rose-STL-Lab%2FAdapting-While-Learning","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rose-STL-Lab%2FAdapting-While-Learning/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rose-STL-Lab%2FAdapting-While-Learning/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rose-STL-Lab%2FAdapting-While-Learning/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Rose-STL-Lab","download_url":"https://codeload.github.com/Rose-STL-Lab/Adapting-While-Learning/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rose-STL-Lab%2FAdapting-While-Learning/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262727722,"owners_count":23354666,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-30T07:03:16.098Z","updated_at":"2025-06-30T07:03:16.830Z","avatar_url":"https://github.com/Rose-STL-Lab.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Adapting While Learning: Grounding LLMs for Scientific Problems with Tool Usage Adaptation\n\nCode for paper \"Adapting While Learning: Grounding LLMs for Scientific Problems with Tool Usage Adaptation\", presented at ICML2025.\n\n## Abstract\n\nLarge Language Models (LLMs) demonstrate promising capabilities in solving simple scientific problems but, even with domain-specific fine-tuning, often produce hallucinations for complex ones. While integrating LLMs with tools can mitigate this reliability issue, models finetuned on tool usage only often over-rely on them, incurring unnecessary costs from resource-intensive scientific tools even for simpler problems.\nInspired by how human experts assess the complexity of the problem before choosing the solutions, we propose a novel two-component fine-tuning method, AWL (Adapting while Learning). In the first component World Knowledge Learning (WKL), LLMs internalize scientific knowledge by learning from tools-generated solutions. In the second component Tool Usage Adaptation (TUA), we classify questions as easy or hard based on the model's accuracy, and train it to maintain direct reasoning for simple problems while switching to tools for challenging ones.\nWe validate our method on 6 scientific benchmark datasets in climate science, epidemiology, physics, etc. Compared to the base 8B model, our trained models achieve 29.11\\% higher answer accuracy and 12.72\\% better tool usage accuracy, even surpassing state-of-the-art models including GPT-4o and Claude-3.5 on 4 custom-created datasets.\n\n## Installation\n\nTo set up the environment, you'll need Python 3.9 and the required dependencies. You can create the environment and install the required packages using the following commands:\n\n```bash\nconda create -n awl python=3.9.19\nconda activate awl\npip install -r requirements.txt\n```\n\nThe emulators used in climate and epidemiology scenarios are respectively adapted from [MFRNP](https://github.com/Rose-STL-Lab/MFRNP) and [INP](https://github.com/Rose-STL-Lab/Interactive-Neural-Process). You can download the pre-trained surrogate neural nets from [this link](https://drive.google.com/drive/folders/1Q-KwQnrxME3txfut0sGgbiRhJy9PCWPp?usp=share_link), and put the tools for climate and epidemiology respectively under `src/Climate` and `src/Epidemiology`. Note that the device of the climate emulator is configured in `src/Climate/tools/Climate_online/model/tas_reanalysis.yaml`.\n\nThe tool-calling in this work is achieved through Llama-3.1-8B-Instruct's [chat template](https://huggingface.co/docs/transformers/main/chat_templating), except open problems in Epidemiology. It means that, if you are using a model whose chat template doesn't support tool usage, then currect pipeline might can't be applied directly.\n\n## Data Preparation and Training\n\n![pipeline](assets/pipeline.png)\n\nThe workflow for training and evaluating the model, as illustrated in the paper and above figure, includes the following steps:\n\n1. LLMs interact with external tools to solve scientific problems\n2. Based on the interaction with tools, a solution is generated.\n3. The LLMs are evaluated on the questions to categorize the dataset into easy and hard problems.\n4. The World Knowledge Learning (WKL) and Tool Usage Adaptation (TUA) data are combined to further train the model.\n\nEach sub-folder in the repository corresponds to a dataset, and each sub-folder contains scripts that execute these components in sequence.\n\n```bash\n# Generate a set of problems for training and testing.\npython make_problems.py\n\n# Use an LLM-Agent to answer the generated questions.\npython answer_agent.py\n\n# Generate solutions for the questions\npython generate_solution.py\n\n# Create training data based on the input file and model\npython make_training_data.py\n\n# Generate answers using the LLM for the given input questions.\npython answer_llm.py\n```\n\nAdditionally, the Climate and Epidemiology folders include code related to open-ended questions.\n\n## Evaluation\n\nWe provide the testing data in the `test_set` folder. For Questions with Definite Answers we provide a standard answers along with the questions. For open-ended questions, we provide corresponding evaluation scripts (`Climate/evaluate_open.py` and `Epidemiology/eval_open.py`).\n\n## Utils\n\nThe `utils` folder contains utility scripts related to the following components:\n\n1. **Model utilities**: Scripts for loading and interacting with open-source and closed-source (proprietary) language models. You should replace the `API_KEY` with your own one.\n2. **Dataset construction**: Tools for preprocessing, formatting, and generating datasets used in training and evaluation.\n3. **Mathematical evaluation**: Utilities to assess and evaluate mathematical outputs.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frose-stl-lab%2Fadapting-while-learning","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frose-stl-lab%2Fadapting-while-learning","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frose-stl-lab%2Fadapting-while-learning/lists"}