An open-source implementation for the research paper investigating the effects of structured versus unstructured reasoning in Large Language Models using instance-level Self-Discover.
This repository contains the code and experimental setup for the research paper titled "Effects of structure on reasoning in instance-level Self-Discover". The project introduces iSELF-DISCOVER, an instance-level adaptation of the SELF-DISCOVER framework, to empirically evaluate the performance of dynamically generated structured JSON reasoning against its unstructured, natural language counterpart.
Our findings, particularly on benchmarks like MATH, BBH, and a replicated T4D, suggest a consistent advantage for unstructured reasoning plans. This work aims to provide insights into optimal plan generation granularity (instance-level vs. task-level) and the nuanced reliance on structured formats for complex LLM problem-solving.
MISTRAL_API_KEYLAMBDA_LABS_API_KEYClone the repository:
git clone https://github.com/sachith-gunasekara/self-discover.git
cd self-discover
Set up your Python virtual environment: It's recommended to create and activate a virtual environment. For example:
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
Install dependencies using Poetry:
poetry install
Set up API Keys:
Create a .env file in the root of the project with your API keys:
MISTRAL_API_KEY="YOUR_MISTRAL_API_KEY"
LAMBDA_LABS_API_KEY="YOUR_LAMBDA_LABS_API_KEY"
Experiments are primarily configured via evals/config.toml.
Key parameters in evals/config.toml:
[MODEL]
# Specifies the model family to use.
# "mistral" will use "mistral-large-2407".
# "llama" will use "llama3.1-405b-instruct-fp8".
model_type = "mistral"
[EVAL]
# batch_size controls the number of instances processed in a single batch.
# This is useful for managing API rate limits or resource usage.
batch_size = 5
# wait_time is the duration (in seconds) to wait if any Exceptions arises during the evaluation process (Can allow breathing room if unexpected API errors occur).
wait_time = 1
To reproduce the experiments presented in the paper:
Ensure your Poetry environment is active: If you haven't already, activate it:
source .venv/bin/activate # Or your chosen environment activation command
# Alternatively, you can prefix commands with `poetry run`
Prepare Log Directory:
The evaluation scripts are designed to check for current progress in evals/logs and resume. If you want to run experiments from scratch, ensure the evals/logs directory is deleted or empty.
Run evaluation scripts (from the project root directory):
To evaluate the iSELF-DISCOVER approach (our proposed method):
Use evals/iself_discover_eval.py. Key arguments include:
--structured: (Flag, no value) Use structured JSON reasoning. If omitted, defaults to unstructured.--few_shot_examples <N>: Number of few-shot examples to use (e.g., 0 for zero-shot, 5 for five-shot). Defaults to 0.--stream: (Flag, no value) Stream LangGraph steps one by one and log debug messages for each output from every stage. Defaults to False.Example (unstructured, 0-shot, run from root):
python evals/iself_discover_eval.py
Example (structured, 5-shot, with streaming, run from root):
python evals/iself_discover_eval.py --structured --few_shot_examples 5 --stream
To evaluate the original SELF-DISCOVER approach (baseline):
Use evals/self_discover_eval.py. Key arguments include:
--phase <PHASE_VALUE>: (Required for research experiments) Specify the stage of the SELF-DISCOVER framework to run.
1 to run Phase I (e.g., task-specific reasoning structure discovery).2 to run Phase II (e.g., solving instances using a discovered structure).
While the script might default to running both if this argument is omitted, for research evaluation purposes, you must explicitly specify either 1 or 2.--stream: (Flag, no value) Stream LangGraph steps and log debug messages. Defaults to False.Example (running Phase I, no streaming, run from root):
python evals/self_discover_eval.py --phase 1
Example (running Phase II with streaming, run from root):
python evals/self_discover_eval.py --phase 2 --stream
The necessary datasets (BBH, replicated T4D, MATH subsample) are expected to be handled by the scripts, potentially by downloading from sources mentioned in the paper (e.g., Hugging Face sachithgunasekara/framework-MATH-subsample and sachithgunasekara/t4d). No manual dataset placement should be required.
Experimental results, detailed logs, and any generated reasoning traces will be stored in the evals/logs directory. The structure within this directory should allow for identification of results based on the benchmark, model, and experimental configuration.
Distributed under the MIT License. See LICENSE file for more information.
56 commits
Jupyter Notebook
98.2%
Python
1.7%
An open-source implementation for the research paper investigating the effects of structured versus unstructured reasoning in Large Language Models using instance-level Self-Discover.
This repository contains the code and experimental setup for the research paper titled "Effects of structure on reasoning in instance-level Self-Discover". The project introduces iSELF-DISCOVER, an instance-level adaptation of the SELF-DISCOVER framework, to empirically evaluate the performance of dynamically generated structured JSON reasoning against its unstructured, natural language counterpart.
Our findings, particularly on benchmarks like MATH, BBH, and a replicated T4D, suggest a consistent advantage for unstructured reasoning plans. This work aims to provide insights into optimal plan generation granularity (instance-level vs. task-level) and the nuanced reliance on structured formats for complex LLM problem-solving.
MISTRAL_API_KEYLAMBDA_LABS_API_KEYClone the repository:
git clone https://github.com/sachith-gunasekara/self-discover.git
cd self-discover
Set up your Python virtual environment: It's recommended to create and activate a virtual environment. For example:
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
Install dependencies using Poetry:
poetry install
Set up API Keys:
Create a .env file in the root of the project with your API keys:
MISTRAL_API_KEY="YOUR_MISTRAL_API_KEY"
LAMBDA_LABS_API_KEY="YOUR_LAMBDA_LABS_API_KEY"
Experiments are primarily configured via evals/config.toml.
Key parameters in evals/config.toml:
[MODEL]
# Specifies the model family to use.
# "mistral" will use "mistral-large-2407".
# "llama" will use "llama3.1-405b-instruct-fp8".
model_type = "mistral"
[EVAL]
# batch_size controls the number of instances processed in a single batch.
# This is useful for managing API rate limits or resource usage.
batch_size = 5
# wait_time is the duration (in seconds) to wait if any Exceptions arises during the evaluation process (Can allow breathing room if unexpected API errors occur).
wait_time = 1
To reproduce the experiments presented in the paper:
Ensure your Poetry environment is active: If you haven't already, activate it:
source .venv/bin/activate # Or your chosen environment activation command
# Alternatively, you can prefix commands with `poetry run`
Prepare Log Directory:
The evaluation scripts are designed to check for current progress in evals/logs and resume. If you want to run experiments from scratch, ensure the evals/logs directory is deleted or empty.
Run evaluation scripts (from the project root directory):
To evaluate the iSELF-DISCOVER approach (our proposed method):
Use evals/iself_discover_eval.py. Key arguments include:
--structured: (Flag, no value) Use structured JSON reasoning. If omitted, defaults to unstructured.--few_shot_examples <N>: Number of few-shot examples to use (e.g., 0 for zero-shot, 5 for five-shot). Defaults to 0.--stream: (Flag, no value) Stream LangGraph steps one by one and log debug messages for each output from every stage. Defaults to False.Example (unstructured, 0-shot, run from root):
python evals/iself_discover_eval.py
Example (structured, 5-shot, with streaming, run from root):
python evals/iself_discover_eval.py --structured --few_shot_examples 5 --stream
To evaluate the original SELF-DISCOVER approach (baseline):
Use evals/self_discover_eval.py. Key arguments include:
--phase <PHASE_VALUE>: (Required for research experiments) Specify the stage of the SELF-DISCOVER framework to run.
1 to run Phase I (e.g., task-specific reasoning structure discovery).2 to run Phase II (e.g., solving instances using a discovered structure).
While the script might default to running both if this argument is omitted, for research evaluation purposes, you must explicitly specify either 1 or 2.--stream: (Flag, no value) Stream LangGraph steps and log debug messages. Defaults to False.Example (running Phase I, no streaming, run from root):
python evals/self_discover_eval.py --phase 1
Example (running Phase II with streaming, run from root):
python evals/self_discover_eval.py --phase 2 --stream
The necessary datasets (BBH, replicated T4D, MATH subsample) are expected to be handled by the scripts, potentially by downloading from sources mentioned in the paper (e.g., Hugging Face sachithgunasekara/framework-MATH-subsample and sachithgunasekara/t4d). No manual dataset placement should be required.
Experimental results, detailed logs, and any generated reasoning traces will be stored in the evals/logs directory. The structure within this directory should allow for identification of results based on the benchmark, model, and experimental configuration.
Distributed under the MIT License. See LICENSE file for more information.
56 commits
Jupyter Notebook
98.2%
Python
1.7%