-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Feature selection v3 to support all actions (#280)
* Update feedback.py to support all actions Feedback.py is updated to support all actions. * Update prompts.yaml to support all actions * Revised for CI * CI * fix a ci bug * fix a ci bug --------- Co-authored-by: WinstonLiye <[email protected]>
- Loading branch information
1 parent
83058c8
commit 0047641
Showing
2 changed files
with
120 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,12 +46,37 @@ def process_results(current_result, sota_result): | |
|
||
|
||
class KGHypothesisExperiment2Feedback(HypothesisExperiment2Feedback): | ||
def get_available_features(self, exp: Experiment): | ||
features = [] | ||
|
||
for feature_info in exp.experiment_workspace.data_description: | ||
task_info, feature_shape = feature_info | ||
This comment has been minimized.
Sorry, something went wrong. |
||
features.append( | ||
{"name": task_info.factor_name, "description": task_info.factor_description, "shape": feature_shape} | ||
This comment has been minimized.
Sorry, something went wrong.
WinstonLiyt
Author
Collaborator
|
||
) | ||
|
||
return features | ||
|
||
def get_model_code(self, exp: Experiment): | ||
model_type = exp.sub_tasks[0].model_type if exp.sub_tasks else None | ||
if model_type == "XGBoost": | ||
return exp.sub_workspace_list[0].code_dict.get( | ||
"model_xgb.py" | ||
) # TODO Check if we need to replace this by using RepoAnalyzer | ||
elif model_type == "RandomForest": | ||
return exp.sub_workspace_list[0].code_dict.get("model_rf.py") | ||
elif model_type == "LightGBM": | ||
return exp.sub_workspace_list[0].code_dict.get("model_lgb.py") | ||
elif model_type == "NN": | ||
return exp.sub_workspace_list[0].code_dict.get("model_nn.py") | ||
else: | ||
return None | ||
|
||
def generate_feedback(self, exp: Experiment, hypothesis: Hypothesis, trace: Trace) -> HypothesisFeedback: | ||
""" | ||
The `ti` should be executed and the results should be included, as well as the comparison between previous results (done by LLM). | ||
For example: `mlflow` of Qlib will be included. | ||
""" | ||
|
||
""" | ||
Generate feedback for the given experiment and hypothesis. | ||
Args: | ||
|
@@ -84,28 +109,44 @@ def generate_feedback(self, exp: Experiment, hypothesis: Hypothesis, trace: Trac | |
combined_result = process_results(current_result, current_result) # Compare with itself | ||
print("Warning: No previous experiments to compare against. Using current result as baseline.") | ||
|
||
available_features = self.get_available_features(exp) | ||
# Get the appropriate model code | ||
model_code = self.get_model_code(exp) | ||
This comment has been minimized.
Sorry, something went wrong.
WinstonLiyt
Author
Collaborator
|
||
|
||
# Generate the user prompt based on the action type | ||
if hypothesis.action == "Model tuning": | ||
prompt_key = "model_tuning_feedback_generation" | ||
elif hypothesis.action == "Model feature selection": | ||
prompt_key = "feature_selection_feedback_generation" | ||
else: | ||
prompt_key = "factor_feedback_generation" | ||
|
||
# Generate the system prompt | ||
sys_prompt = ( | ||
Environment(undefined=StrictUndefined) | ||
.from_string(prompt_dict["factor_feedback_generation"]["system"]) | ||
.from_string(prompt_dict[prompt_key]["system"]) | ||
.render(scenario=self.scen.get_scenario_all_desc()) | ||
) | ||
|
||
# Generate the user prompt based on the action type | ||
if hypothesis.action == "Model Tuning": # TODO Add other prompts here | ||
prompt_key = "model_feedback_generation" | ||
else: | ||
prompt_key = "factor_feedback_generation" | ||
# Prepare render dictionary | ||
render_dict = { | ||
"context": self.scen.get_scenario_all_desc(), | ||
"last_hypothesis": trace.hist[-1][0] if trace.hist else None, | ||
"last_task": trace.hist[-1][1] if trace.hist else None, | ||
"last_code": self.get_model_code(trace.hist[-1][1]) if trace.hist else None, | ||
"last_result": trace.hist[-1][1].result if trace.hist else None, | ||
"hypothesis": hypothesis, | ||
"exp": exp, | ||
"model_code": model_code, | ||
"available_features": available_features, | ||
"combined_result": combined_result, | ||
"hypothesis_text": hypothesis_text, | ||
"task_details": tasks_factors, | ||
} | ||
|
||
# Generate the user prompt | ||
usr_prompt = ( | ||
Environment(undefined=StrictUndefined) | ||
.from_string(prompt_dict[prompt_key]["user"]) | ||
.render( | ||
hypothesis_text=hypothesis_text, | ||
task_details=tasks_factors, | ||
combined_result=combined_result, | ||
) | ||
Environment(undefined=StrictUndefined).from_string(prompt_dict[prompt_key]["user"]).render(**render_dict) | ||
) | ||
|
||
# Call the APIBackend to generate the response for hypothesis feedback | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
It should not be
.factor_name
astask_info
is a string.