mirror of
https://github.com/NicolasBohn/NexQuant.git
synced 2026-08-01 09:27:43 +00:00
68d47e1f1f
* Init todo * Evaluation & dataset * Generate new data * dataset generation * add the result * Analysis * Factor update * Updates * Reformat analysis.py * CI fix * Revised Preprocessing & Supported Random Forest * Revised to support three models with feature * Further revised prompts * Slight Revision * docs: update contributors (#230) * Revised to support three models with feature * Further revised prompts * Slight Revision * feat: kaggle model and feature (#238) * update first version code * make hypothesis_gen and experiment_builder fit for both feature and model * feat: continue kaggle feature and model coder (#239) * use qlib docker to run qlib models * feature coder ready * model coder ready * fix CI * finish the first round of runner (#240) * Optimized the factor scenario and added the front-end. * fix a small bug * fix a typo * update the kaggle scenario * delete model_template folder * use experiment to run data preprocess script * add source data to scenarios * minor fix * minor bug fix * train.py debug * fixed a bug in train.py and added some TODOs * For Debugging * fix two small bugs in based_exp * fix some bugs * update preprocess * fix a bug in preprocess * fix a bug in train.py * reformat * Follow-up * fix a bug in train.py * fix a bug in workspace * fix a bug in feature duplication * fix a bug in feedback * fix a bug in preprocessed data * fix a bug om feature engineering * fix a ci error * Debugged & Connected * Fixed error on feedback & added other fixes * fix CI errors * fix a CI bug * fix: fix_dotenv_error (#257) * fix_dotenv_error * format with isort * Update rdagent/app/cli.py --------- Co-authored-by: you-n-g <you-n-g@users.noreply.github.com> * chore(main): release 0.2.1 (#249) Release-As: 0.2.1 * init a scenario for kaggle feature engineering * delete error codes * Delete rdagent/app/kaggle_feature/conf.py --------- Co-authored-by: Young <afe.young@gmail.com> Co-authored-by: Taozhi Wang <taozhi.mark.wang@gmail.com> Co-authored-by: you-n-g <you-n-g@users.noreply.github.com> Co-authored-by: cyncyw <47289405+taozhiwang@users.noreply.github.com> Co-authored-by: Xisen-Wang <xisen_application@163.com> Co-authored-by: Haotian Chen <113661982+Hytn@users.noreply.github.com> Co-authored-by: WinstonLiye <1957922024@qq.com> Co-authored-by: WinstonLiyt <104308117+WinstonLiyt@users.noreply.github.com> Co-authored-by: Linlang <30293408+SunsetWolf@users.noreply.github.com>
114 lines
4.3 KiB
Python
114 lines
4.3 KiB
Python
import json
|
|
from pathlib import Path
|
|
from typing import List, Tuple
|
|
|
|
from jinja2 import Environment, StrictUndefined
|
|
|
|
from rdagent.components.coder.model_coder.model import ModelExperiment, ModelTask
|
|
from rdagent.components.proposal.model_proposal import (
|
|
ModelHypothesis,
|
|
ModelHypothesis2Experiment,
|
|
ModelHypothesisGen,
|
|
)
|
|
from rdagent.core.prompts import Prompts
|
|
from rdagent.core.proposal import Hypothesis, Scenario, Trace
|
|
from rdagent.scenarios.data_mining.experiment.model_experiment import DMModelExperiment
|
|
|
|
prompt_dict = Prompts(file_path=Path(__file__).parent.parent.parent / "qlib" / "prompts.yaml")
|
|
|
|
DMModelHypothesis = ModelHypothesis
|
|
|
|
|
|
class DMModelHypothesisGen(ModelHypothesisGen):
|
|
"""
|
|
# NOTE: we can share this class across different data mining scenarios
|
|
# It may better to move the class into components folder like `rdagent/components/proposal/model_proposal.py`
|
|
# Here is the use case:
|
|
|
|
.. code-block:: python
|
|
|
|
class XXXDMModelHypothesisGen(DMModelHypothesisGen):
|
|
prompts: Prompts = a_specifc_prompt_dict
|
|
"""
|
|
|
|
def __init__(self, scen: Scenario) -> Tuple[dict, bool]:
|
|
super().__init__(scen)
|
|
|
|
def prepare_context(self, trace: Trace) -> Tuple[dict, bool]:
|
|
hypothesis_feedback = (
|
|
Environment(undefined=StrictUndefined)
|
|
.from_string(prompt_dict["hypothesis_and_feedback"])
|
|
.render(trace=trace)
|
|
)
|
|
context_dict = {
|
|
"hypothesis_and_feedback": hypothesis_feedback,
|
|
"RAG": "",
|
|
"hypothesis_output_format": prompt_dict["hypothesis_output_format"],
|
|
"hypothesis_specification": prompt_dict["model_hypothesis_specification"],
|
|
}
|
|
return context_dict, True
|
|
|
|
def convert_response(self, response: str) -> ModelHypothesis:
|
|
response_dict = json.loads(response)
|
|
hypothesis = DMModelHypothesis(
|
|
hypothesis=response_dict["hypothesis"],
|
|
reason=response_dict["reason"],
|
|
concise_reason=response_dict["concise_reason"],
|
|
concise_observation=response_dict["concise_observation"],
|
|
concise_justification=response_dict["concise_justification"],
|
|
concise_knowledge=response_dict["concise_knowledge"],
|
|
)
|
|
return hypothesis
|
|
|
|
|
|
class DMModelHypothesis2Experiment(ModelHypothesis2Experiment):
|
|
def prepare_context(self, hypothesis: Hypothesis, trace: Trace) -> Tuple[dict, bool]:
|
|
scenario = trace.scen.get_scenario_all_desc()
|
|
experiment_output_format = prompt_dict["model_experiment_output_format"]
|
|
|
|
hypothesis_and_feedback = (
|
|
Environment(undefined=StrictUndefined)
|
|
.from_string(prompt_dict["hypothesis_and_feedback"])
|
|
.render(trace=trace)
|
|
)
|
|
|
|
experiment_list: List[ModelExperiment] = [t[1] for t in trace.hist]
|
|
|
|
model_list = []
|
|
for experiment in experiment_list:
|
|
model_list.extend(experiment.sub_tasks)
|
|
|
|
return {
|
|
"target_hypothesis": str(hypothesis),
|
|
"scenario": scenario,
|
|
"hypothesis_and_feedback": hypothesis_and_feedback,
|
|
"experiment_output_format": experiment_output_format,
|
|
"target_list": model_list,
|
|
"RAG": ...,
|
|
}, True
|
|
|
|
def convert_response(self, response: str, trace: Trace) -> ModelExperiment:
|
|
response_dict = json.loads(response)
|
|
tasks = []
|
|
for model_name in response_dict:
|
|
description = response_dict[model_name]["description"]
|
|
formulation = response_dict[model_name]["formulation"]
|
|
architecture = response_dict[model_name]["architecture"]
|
|
variables = response_dict[model_name]["variables"]
|
|
hyperparameters = response_dict[model_name]["hyperparameters"]
|
|
model_type = response_dict[model_name]["model_type"]
|
|
tasks.append(
|
|
ModelTask(
|
|
name=model_name,
|
|
description=description,
|
|
formulation=formulation,
|
|
architecture=architecture,
|
|
variables=variables,
|
|
hyperparameters=hyperparameters,
|
|
model_type=model_type,
|
|
)
|
|
)
|
|
exp = DMModelExperiment(tasks)
|
|
exp.based_experiments = [t[1] for t in trace.hist if t[2]]
|
|
return exp
|