### Install EduStudio from source Source: https://edustudio.readthedocs.io/en/latest/_sources/get_started/install.md.txt Install the package in editable mode from the local directory. ```bash pip install -e . --verbose ``` -------------------------------- ### Hyper Parameter Tuning with HyperOpt Source: https://edustudio.readthedocs.io/en/latest/_sources/user_guide/usage/aht.md.txt Example of using HyperOpt to optimize EduStudio model parameters using the TPE algorithm. ```python from edustudio.quickstart import run_edustudio from hyperopt import hp from hyperopt import fmin, tpe, space_eval def deliver_cfg(args): g_args = { 'traintpl_cfg': {}, 'datatpl_cfg': {}, 'modeltpl_cfg': {}, 'evaltpl_cfg': {}, 'frame_cfg': {}, } for k,v in args.items(): g, k = k.split(".") assert g in g_args g_args[g][k] = v return g_args # objective function def objective_function(args): g_args = deliver_cfg(args) cfg, res = run_edustudio( dataset='FrcSub', cfg_file_name=None, traintpl_cfg_dict=g_args['traintpl_cfg'], datatpl_cfg_dict=g_args['datatpl_cfg'], modeltpl_cfg_dict=g_args['modeltpl_cfg'], evaltpl_cfg_dict=g_args['evaltpl_cfg'], frame_cfg_dict=g_args['frame_cfg'], return_cfg_and_result=True ) return res['auc'] space = { 'traintpl_cfg.cls': hp.choice('traintpl_cfg.cls', ['GeneralTrainTPL']), 'datatpl_cfg.cls': hp.choice('datapl_cfg.cls', ['CDInterExtendsQDataTPL']), 'modeltpl_cfg.cls': hp.choice('modeltpl_cfg.cls', ['KaNCD']), 'evaltpl_cfg.clses': hp.choice('evaltpl_cfg.clses', [['PredictionEvalTPL', 'InterpretabilityEvalTPL']]), 'traintpl_cfg.batch_size': hp.choice('traintpl_cfg.batch_size', [256,]), 'traintpl_cfg.epoch_num': hp.choice('traintpl_cfg.epoch_num', [2]), 'modeltpl_cfg.emb_dim': hp.choice('modeltpl_cfg.emb_dim', [20,40]) } best = fmin(objective_function, space, algo=tpe.suggest, max_evals=10, verbose=False) print("=="*10) print(best) print(space_eval(space, best)) ``` -------------------------------- ### Install EduStudio via pip Source: https://edustudio.readthedocs.io/en/latest/_sources/get_started/install.md.txt Use this command to install the latest version of EduStudio from the Python Package Index. ```bash pip install -U edustudio ``` -------------------------------- ### Load Dataset from Different Stages Source: https://edustudio.readthedocs.io/en/latest/_sources/features/dataset_folder_protocol.md.txt Examples demonstrating how to configure the run_edustudio function to load data from raw, middle, or cached stages. ```python from edustudio.quickstart import run_edustudio run_edustudio( dataset='FrcSub', cfg_file_name=None, traintpl_cfg_dict={ 'cls': 'GeneralTrainTPL', }, datatpl_cfg_dict={ 'cls': 'CDInterExtendsQDataTPL', 'load_data_from': "rawdata", # specify the loading stage of the dataset 'raw2mid_op': 'R2M_FrcSub' # specify the R2M atomic operation }, modeltpl_cfg_dict={ 'cls': 'KaNCD', }, evaltpl_cfg_dict={ 'clses': ['PredictionEvalTPL', 'InterpretabilityEvalTPL'], } ) ``` ```python from edustudio.quickstart import run_edustudio run_edustudio( dataset='FrcSub', cfg_file_name=None, traintpl_cfg_dict={ 'cls': 'GeneralTrainTPL', }, datatpl_cfg_dict={ 'cls': 'CDInterExtendsQDataTPL', 'load_data_from': "middata", # specify the loading stage of the dataset 'is_save_cache': True, # whether to save cache data 'cache_id': 'cache_default', # cache id, valid when is_save_cache=True }, modeltpl_cfg_dict={ 'cls': 'KaNCD', }, evaltpl_cfg_dict={ 'clses': ['PredictionEvalTPL', 'InterpretabilityEvalTPL'], } ) ``` ```python from edustudio.quickstart import run_edustudio run_edustudio( dataset='FrcSub', cfg_file_name=None, traintpl_cfg_dict={ 'cls': 'GeneralTrainTPL', }, datatpl_cfg_dict={ 'cls': 'CDInterExtendsQDataTPL', 'load_data_from': "cachedata", # specify the loading stage of the dataset 'is_save_cache': False, 'cache_id': 'cache_default', # cache id, valid when is_save_cache=True }, modeltpl_cfg_dict={ 'cls': 'KaNCD', }, evaltpl_cfg_dict={ 'clses': ['PredictionEvalTPL', 'InterpretabilityEvalTPL'], } ) ``` -------------------------------- ### Hyper Parameter Tuning with Ray.Tune Source: https://edustudio.readthedocs.io/en/latest/_sources/user_guide/usage/aht.md.txt Example of using Ray.Tune to optimize EduStudio model parameters via a grid search. ```python from edustudio.quickstart import run_edustudio from ray import tune import ray ray.init(num_cpus=4, num_gpus=1) def deliver_cfg(args): g_args = { 'traintpl_cfg': {}, 'datatpl_cfg': {}, 'modeltpl_cfg': {}, 'evaltpl_cfg': {}, 'frame_cfg': {}, } for k,v in args.items(): g, k = k.split(".") assert g in g_args g_args[g][k] = v return g_args # objective function def objective_function(args): g_args = deliver_cfg(args) print(g_args) cfg, res = run_edustudio( dataset='FrcSub', cfg_file_name=None, traintpl_cfg_dict=g_args['traintpl_cfg'], datatpl_cfg_dict=g_args['datatpl_cfg'], modeltpl_cfg_dict=g_args['modeltpl_cfg'], evaltpl_cfg_dict=g_args['evaltpl_cfg'], frame_cfg_dict=g_args['frame_cfg'], return_cfg_and_result=True ) return res search_space= { 'traintpl_cfg.cls': tune.grid_search(['GeneralTrainTPL']), 'datatpl_cfg.cls': tune.grid_search(['CDInterExtendsQDataTPL']), 'modeltpl_cfg.cls': tune.grid_search(['KaNCD']), 'evaltpl_cfg.clses': tune.grid_search([['PredictionEvalTPL', 'InterpretabilityEvalTPL']]), 'traintpl_cfg.batch_size': tune.grid_search([256,]), 'traintpl_cfg.epoch_num': tune.grid_search([2]), 'traintpl_cfg.device': tune.grid_search(["cpu"]), 'modeltpl_cfg.emb_dim': tune.grid_search([20,40]) } tuner = tune.Tuner( objective_function, param_space=search_space, tune_config=tune.TuneConfig(max_concurrent_trials=1) ) results = tuner.fit() print("=="*10) print(results.get_best_result(metric="auc", mode="max").config) ``` -------------------------------- ### Develop a traditional ModelTPL Source: https://edustudio.readthedocs.io/en/latest/_sources/developer_guide/customize_modeltpl.md.txt Example implementation of a custom model template inheriting from GDBaseModelTPL, defining configuration and required methods. ```python from ..gd_basemodeltpl import GDBaseModelTPL class NewModelTPL(GDBaseModelTPL): default_cfg = { 'dnn_units': [512, 256], 'dropout_rate': 0.5, 'activation': 'sigmoid', 'disc_scale': 10 } def __init__(self, cfg): super().__init__(cfg) def build_cfg(self): self.n_user = self.datafmt_cfg['dt_info']['stu_count'] ... def build_model(self): ... self.pd_net = PosMLP( input_dim=self.n_cpt, output_dim=1, activation=self.model_cfg['activation'], dnn_units=self.model_cfg['dnn_units'], dropout_rate=self.model_cfg['dropout_rate'] ) def forward(self, stu_id, exer_id, Q_mat, **kwargs): ... pd = self.pd_net(input_x).sigmoid() return pd @torch.no_grad() def predict(self, stu_id, exer_id, Q_mat, **kwargs): return { 'y_pd': self(stu_id, exer_id, Q_mat).flatten(), } def get_main_loss(self, **kwargs): ... pd = self(stu_id, exer_id, Q_mat).flatten() loss = F.binary_cross_entropy(input=pd, target=label) return { 'loss_main': loss } def get_loss_dict(self, **kwargs): return self.get_main_loss(**kwargs) ``` -------------------------------- ### Dataset Folder Structure Example Source: https://edustudio.readthedocs.io/en/latest/_sources/features/dataset_folder_protocol.md.txt The required directory layout for a dataset, showing the organization of raw, middle, and cached data folders. ```text data/ ├── FrcSub │ ├── cachedata │ │ ├── FrcSub_five_fold │ │ │ ├── datatpl_cfg.json │ │ │ ├── df_exer.pkl │ │ │ ├── df_stu.pkl │ │ │ ├── dict_test_folds.pkl │ │ │ ├── dict_train_folds.pkl │ │ │ ├── dict_valid_folds.pkl │ │ │ └── final_kwargs.pkl │ │ └── FrcSub_one_fold │ │ ├── datatpl_cfg.json │ │ ├── df_exer.pkl │ │ ├── df_stu.pkl │ │ ├── dict_test_folds.pkl │ │ ├── dict_train_folds.pkl │ │ ├── dict_valid_folds.pkl │ │ └── final_kwargs.pkl │ ├── middata │ │ ├── FrcSub.exer.csv │ │ └── FrcSub.inter.csv │ └── rawdata │ ├── data.txt │ ├── problemdesc.txt │ ├── qnames.txt │ └── q.txt ``` -------------------------------- ### Implement M2C_RandomDataSplit4CD Atomic Operation Source: https://edustudio.readthedocs.io/en/latest/_sources/developer_guide/customize_atomic_op.md.txt Example implementation of a data splitting operation for cognitive diagnosis inheriting from BaseMid2Cache. ```python class M2C_RandomDataSplit4CD(BaseMid2Cache): default_cfg = { 'seed': 2023, "divide_scale_list": [7,1,2], } def _check_params(self): super()._check_params() assert 2 <= len(self.m2c_cfg['divide_scale_list']) <= 3 assert sum(self.m2c_cfg['divide_scale_list']) == 10 def process(self, **kwargs): df = kwargs['df'] if self.n_folds == 1: assert kwargs.get("df_train", None) is None assert kwargs.get("df_valid", None) is None assert kwargs.get("df_test", None) is None df_train, df_valid, df_test = self.one_fold_split(df) kwargs['df_train_folds'] = [df_train] kwargs['df_valid_folds'] = [df_valid] if df_valid is not None else [] kwargs['df_test_folds'] = [df_test] else: df_train_list, df_test_list = self.multi_fold_split(df) kwargs['df_train_folds'] = df_train_list kwargs['df_test_folds'] = df_test_list return kwargs def set_dt_info(self, dt_info, **kwargs): if 'stu_id:token' in kwargs['df'].columns: dt_info['stu_count'] = int(kwargs['df']['stu_id:token'].max() + 1) ``` -------------------------------- ### Implement BaseRaw2Mid Subclass Source: https://edustudio.readthedocs.io/en/latest/_sources/developer_guide/customize_atomic_op.md.txt Example of a custom class inheriting from BaseRaw2Mid to process raw dataset files into standardized middle data files. ```python class R2M_ASSIST_0910(BaseRaw2Mid): def process(self): df = pd.read_csv(f"{self.rawpath}/skill_builder_data.csv", encoding='ISO-8859-1') ...... df_inter.to_csv(f"{self.midpath}/{self.dt}.inter.csv", index=False, encoding='utf-8') df_user.to_csv(f"{self.midpath}/{self.dt}.stu.csv", index=False, encoding='utf-8') df_exer.to_csv(f"{self.midpath}/{self.dt}.exer.csv", index=False, encoding='utf-8') ``` -------------------------------- ### Define Inheritable Data Templates Source: https://edustudio.readthedocs.io/en/latest/_sources/features/inheritable_config.md.txt Example of three data template classes (BaseDataTPL, GeneralDataTPL, and EduDataTPL) inheriting from each other with nested default_cfg dictionaries. ```python class BaseDataTPL(Dataset): default_cfg = {'seed': 2023} class GeneralDataTPL(BaseDataTPL): default_cfg = { 'seperator': ',', 'n_folds': 1, 'is_dataset_divided': False, 'is_save_cache': False, 'cache_id': 'cache_default', 'load_data_from': 'middata', # ['rawdata', 'middata', 'cachedata'] 'inter_exclude_feat_names': (), 'raw2mid_op': None, 'mid2cache_op_seq': [] } class EduDataTPL(GeneralDataTPL): default_cfg = { 'exer_exclude_feat_names': (), 'stu_exclude_feat_names': (), } ``` -------------------------------- ### Execute with YAML Configuration Source: https://edustudio.readthedocs.io/en/latest/_sources/user_guide/usage/run_edustudio.md.txt Run the experiment by pointing to a specific YAML configuration file. ```bash cd examples python run.py -dt ASSIST_0910 -f NCDM.yaml ``` -------------------------------- ### Initialize EduStudio with run_edustudio Source: https://edustudio.readthedocs.io/en/latest/_sources/get_started/quick_start.md.txt Configures the dataset, training, data, model, and evaluation templates for an EduStudio run. ```python from edustudio.quickstart import run_edustudio run_edustudio( dataset='FrcSub', cfg_file_name=None, traintpl_cfg_dict={ 'cls': 'GeneralTrainTPL', }, datatpl_cfg_dict={ 'cls': 'CDInterExtendsQDataTPL' }, modeltpl_cfg_dict={ 'cls': 'KaNCD', }, evaltpl_cfg_dict={ 'clses': ['PredictionEvalTPL', 'InterpretabilityEvalTPL'], } ) ``` -------------------------------- ### Run with YAML Configuration File Source: https://edustudio.readthedocs.io/en/latest/user_guide/usage/run_edustudio.html Define experiment parameters in a YAML file and execute using the -f flag. ```yaml datatpl_cfg: cls: CDInterDataTPL traintpl_cfg: cls: GeneralTrainTPL batch_size: 512 modeltpl_cfg: cls: NCDM evaltpl_cfg: clses: [PredictionEvalTPL, InterpretabilityEvalT] ``` ```bash cd examples python run.py -dt ASSIST_0910 -f NCDM.yaml ``` -------------------------------- ### Clone EduStudio repository Source: https://edustudio.readthedocs.io/en/latest/_sources/get_started/install.md.txt Download the source code from GitHub to your local machine. ```bash git clone https://github.com/HFUT-LEC/EduStudio.git && cd EduStudio ``` -------------------------------- ### Define Configuration via YAML Source: https://edustudio.readthedocs.io/en/latest/_sources/user_guide/usage/run_edustudio.md.txt Create a YAML file to specify experiment settings for data, training, model, and evaluation templates. ```yaml datatpl_cfg: cls: CDInterDataTPL traintpl_cfg: cls: GeneralTrainTPL batch_size: 512 modeltpl_cfg: cls: NCDM evaltpl_cfg: clses: [PredictionEvalTPL, InterpretabilityEvalT] ``` -------------------------------- ### Complete Custom TrainTPL Implementation Source: https://edustudio.readthedocs.io/en/latest/_sources/developer_guide/customize_traintpl.md.txt A full implementation of a custom training template including initialization and the complete training loop with custom loss logic. ```python from .edu_traintpl import GeneralTrainTPL class NewTrainTPL(GeneralTrainTPL): default_cfg = { 'epoch_to_change': 10, } def __init__(self, cfg: UnifyConfig): super().__init__(cfg) def fit(self, train_loader, val_loader): self.model.train() self.optimizer = self._get_optim() self.callback_list.on_train_begin() for epoch in range(self.trainfmt_cfg['epoch_num']): self.callback_list.on_epoch_begin(epoch + 1) logs = defaultdict(lambda: np.full((len(train_loader),), np.nan, dtype=np.float32)) for batch_id, batch_dict in enumerate( tqdm(train_loader, ncols=self.frame_cfg['TQDM_NCOLS'], desc="[EPOCH={:03d}]".format(epoch + 1)) ): batch_dict = self.batch_dict2device(batch_dict) loss_dict = self.model.get_loss_dict(**batch_dict) ############ This part is revised ############ if epoch < self.traintpl_cfg['epoch_to_change']: loss = torch.hstack([i for i in loss_dict.values() if i is not None]).sum() else: loss = loss_dict['main_loss'] ############ This part is revised ############ self.optimizer.zero_grad() loss.backward() self.optimizer.step() for k in loss_dict: logs[k][batch_id] = loss_dict[k].item() if loss_dict[k] is not None else np.nan for name in logs: logs[name] = float(np.nanmean(logs[name])) if val_loader is not None: val_metrics = self.evaluate(val_loader) logs.update({f"{metric}": val_metrics[metric] for metric in val_metrics}) self.callback_list.on_epoch_end(epoch + 1, logs=logs) if self.model.share_callback_dict.get('stop_training', False): break self.callback_list.on_train_end() ``` -------------------------------- ### Execute the Python script Source: https://edustudio.readthedocs.io/en/latest/_sources/get_started/quick_start.md.txt Runs the previously created Python file from the command line. ```bash python run.py ``` -------------------------------- ### Configure evaluation metrics via run_edustudio Source: https://edustudio.readthedocs.io/en/latest/_sources/user_guide/usage/use_case_of_config.md.txt Demonstrates how to restrict evaluation metrics by overriding the use_metrics setting in the evaltpl_cfg_dict. ```python from edustudio.quickstart import run_edustudio run_edustudio( dataset='FrcSub', cfg_file_name=None, traintpl_cfg_dict={ 'cls': 'GeneralTrainTPL', }, datatpl_cfg_dict={ 'cls': 'CDInterExtendsQDataTPL', 'M2C_FilterRecords4CD': { "stu_least_records": 20, } }, modeltpl_cfg_dict={ 'cls': 'KaNCD', }, evaltpl_cfg_dict={ 'clses': ['PredictionEvalTPL', 'InterpretabilityEvalTPL'], 'InterpretabilityEvalTPL': { 'use_metrics': {"auc"} # look here } } ) ``` -------------------------------- ### Load Dataset from Raw Data Source: https://edustudio.readthedocs.io/en/latest/features/dataset_folder_protocol.html Configuration for initializing a dataset from the rawdata stage, requiring the specification of an R2M atomic operation. ```python from edustudio.quickstart import run_edustudio run_edustudio( dataset='FrcSub', cfg_file_name=None, traintpl_cfg_dict={ 'cls': 'GeneralTrainTPL', }, datatpl_cfg_dict={ 'cls': 'CDInterExtendsQDataTPL', 'load_data_from': "rawdata", # specify the loading stage of the dataset 'raw2mid_op': 'R2M_FrcSub' # specify the R2M atomic operation }, modeltpl_cfg_dict={ 'cls': 'KaNCD', }, evaltpl_cfg_dict={ 'clses': ['PredictionEvalTPL', 'InterpretabilityEvalTPL'], } ) ``` -------------------------------- ### Load Dataset from Middle Data Source: https://edustudio.readthedocs.io/en/latest/features/dataset_folder_protocol.html Configuration for initializing a dataset from the middata stage, with options to save the processed data as cache. ```python from edustudio.quickstart import run_edustudio run_edustudio( dataset='FrcSub', cfg_file_name=None, traintpl_cfg_dict={ 'cls': 'GeneralTrainTPL', }, datatpl_cfg_dict={ 'cls': 'CDInterExtendsQDataTPL', 'load_data_from': "middata", # specify the loading stage of the dataset 'is_save_cache': True, # whether to save cache data 'cache_id': 'cache_default', # cache id, valid when is_save_cache=True }, modeltpl_cfg_dict={ 'cls': 'KaNCD', }, evaltpl_cfg_dict={ 'clses': ['PredictionEvalTPL', 'InterpretabilityEvalTPL'], } ) ``` -------------------------------- ### Develop a backbone-style ModelTPL Source: https://edustudio.readthedocs.io/en/latest/_sources/developer_guide/customize_modeltpl.md.txt Extends BaseProxyModelTPL to define a custom backbone model and loss calculation logic. ```python from ..basemodeltpl import BaseProxyModelTPL class NewBackboneModelTPL(BaseProxyModelTPL): default_cfg = { "backbone_model_cls": "IRT", } def __init__(self, cfg): super().__init__(cfg) def build_model(self): super().build_model() self.irr_pair_loss = PairSCELoss() def get_main_loss(self, **kwargs): pair_exer = kwargs['pair_exer'] pair_pos_stu = kwargs['pair_pos_stu'] pair_neg_stu = kwargs['pair_neg_stu'] kwargs['exer_id'] = pair_exer kwargs['stu_id'] = pair_pos_stu pos_pd = self(**kwargs).flatten() kwargs['stu_id'] = pair_neg_stu neg_pd = self(**kwargs).flatten() return { 'loss_main': self.irr_pair_loss(pos_pd, neg_pd) } class PairSCELoss(nn.Module): ... ``` -------------------------------- ### Define a Custom TrainTPL Class Source: https://edustudio.readthedocs.io/en/latest/_sources/developer_guide/customize_traintpl.md.txt Inherit from GeneralTrainTPL and define a custom configuration dictionary to manage training parameters. ```python from .edu_traintpl import GeneralTrainTPL class NewTrainTPL(GeneralTrainTPL): default_cfg = { 'epoch_to_change': 10, } def __init__(self, cfg: UnifyConfig): super().__init__(cfg) ``` -------------------------------- ### Override Configuration via CLI Source: https://edustudio.readthedocs.io/en/latest/_sources/user_guide/usage/run_edustudio.md.txt Pass parameters directly through the command line to override default settings. ```bash cd examples python run.py -dt ASSIST_0910 --modeltpl_cfg.cls NCDM --traintpl_cfg.batch_size 512 ``` -------------------------------- ### Load Dataset from Cached Data Source: https://edustudio.readthedocs.io/en/latest/features/dataset_folder_protocol.html Configuration for initializing a dataset directly from the cachedata stage for faster model loading. ```python from edustudio.quickstart import run_edustudio run_edustudio( dataset='FrcSub', cfg_file_name=None, traintpl_cfg_dict={ 'cls': 'GeneralTrainTPL', }, datatpl_cfg_dict={ 'cls': 'CDInterExtendsQDataTPL', 'load_data_from': "cachedata", # specify the loading stage of the dataset 'is_save_cache': False, 'cache_id': 'cache_default', # cache id, valid when is_save_cache=True }, modeltpl_cfg_dict={ 'cls': 'KaNCD', }, evaltpl_cfg_dict={ 'clses': ['PredictionEvalTPL', 'InterpretabilityEvalTPL'], } ) ``` -------------------------------- ### Read Experimental Results Source: https://edustudio.readthedocs.io/en/latest/_sources/user_guide/usage/aht.md.txt Utility function to load the result.json file generated by EduStudio after an experiment. ```python def read_exp_result(cfg): with open(f"{cfg.frame_cfg.archive_folder_path}/{cfg.frame_cfg.ID}/result.json", 'r', encoding='utf-8') as f: import json return json.load(f) ``` -------------------------------- ### Define PredictionEvalTPL default configuration Source: https://edustudio.readthedocs.io/en/latest/_sources/user_guide/usage/use_case_of_config.md.txt Shows the default configuration dictionary for the PredictionEvalTPL class. ```python class PredictionEvalTPL(BaseEvalTPL): default_cfg = { 'use_metrics': ['auc', 'acc', 'rmse'] } ``` -------------------------------- ### Resulting Merged Configuration Source: https://edustudio.readthedocs.io/en/latest/_sources/features/inheritable_config.md.txt The final default_cfg dictionary resulting from the inheritance hierarchy of EduDataTPL. ```python default_cfg = { 'exer_exclude_feat_names': (), 'stu_exclude_feat_names': (), 'seperator': ',', 'n_folds': 1, 'is_dataset_divided': False, 'is_save_cache': False, 'cache_id': 'cache_default', 'load_data_from': 'middata', # ['rawdata', 'middata', 'cachedata'] 'inter_exclude_feat_names': (), 'raw2mid_op': None, 'mid2cache_op_seq': [], 'seed': 2023 } ``` -------------------------------- ### Configure M2C_FilterRecords4CD via run_edustudio Source: https://edustudio.readthedocs.io/en/latest/_sources/user_guide/usage/use_case_of_config.md.txt Demonstrates overriding the stu_least_records parameter within the datatpl_cfg_dict. ```python from edustudio.quickstart import run_edustudio run_edustudio( dataset='FrcSub', cfg_file_name=None, traintpl_cfg_dict={ 'cls': 'GeneralTrainTPL', }, datatpl_cfg_dict={ 'cls': 'CDInterExtendsQDataTPL', 'M2C_FilterRecords4CD': { "stu_least_records": 20, # look here } }, modeltpl_cfg_dict={ 'cls': 'KaNCD', }, evaltpl_cfg_dict={ 'clses': ['PredictionEvalTPL', 'InterpretabilityEvalTPL'], } ) ``` -------------------------------- ### Define M2C_FilterRecords4CD default configuration Source: https://edustudio.readthedocs.io/en/latest/_sources/user_guide/usage/use_case_of_config.md.txt Shows the default configuration dictionary for the M2C_FilterRecords4CD class. ```python class M2C_FilterRecords4CD(BaseMid2Cache): default_cfg = { "stu_least_records": 10, "exer_least_records": 0, } ``` -------------------------------- ### Configure Atomic Operation Sequence in EduStudio Source: https://edustudio.readthedocs.io/en/latest/_sources/features/dataset_folder_protocol.md.txt Use the mid2cache_op_seq option within datatpl_cfg_dict to define the sequence of data processing operations. ```python from edustudio.quickstart import run_edustudio run_edustudio( dataset='FrcSub', cfg_file_name=None, traintpl_cfg_dict={ 'cls': 'GeneralTrainTPL', }, datatpl_cfg_dict={ 'cls': 'CDInterExtendsQDataTPL', 'load_data_from': "rawdata", # specify the loading stage of the dataset 'raw2mid_op': 'R2M_FrcSub', # the 'mid2cache_op_seq' option specify the atomic operation sequence 'mid2cache_op_seq': ['M2C_Label2Int', 'M2C_FilterRecords4CD', 'M2C_ReMapId', 'M2C_RandomDataSplit4CD', 'M2C_GenQMat'], }, modeltpl_cfg_dict={ 'cls': 'KaNCD', }, evaltpl_cfg_dict={ 'clses': ['PredictionEvalTPL', 'InterpretabilityEvalTPL'], } ) ``` -------------------------------- ### Run R2M process for FrcSub dataset Source: https://edustudio.readthedocs.io/en/latest/_sources/user_guide/usage/atomic_cmds.md.txt Executes the R2M transformation for the FrcSub dataset, specifying raw and mid-data paths. ```bash edustudio r2m R2M_FrcSub --dt FrcSub --rawpath data/FrcSub/rawdata --midpath data/FrcSub/middata ``` -------------------------------- ### Implement Custom Fit Logic Source: https://edustudio.readthedocs.io/en/latest/_sources/developer_guide/customize_traintpl.md.txt Override the fit method to inject custom training behavior, such as conditional loss selection based on the current epoch. ```python def fit(self, train_loader, val_loader): ... for epoch in range(self.trainfmt_cfg['epoch_num']): ... for batch_id, batch_dict in enumerate( tqdm(train_loader, ncols=self.frame_cfg['TQDM_NCOLS'], desc="[EPOCH={:03d}]".format(epoch + 1)) ): batch_dict = self.batch_dict2device(batch_dict) loss_dict = self.model.get_loss_dict(**batch_dict) ############ This part is revised ############ if epoch < self.traintpl_cfg['epoch_to_change']: loss = torch.hstack([i for i in loss_dict.values() if i is not None]).sum() else: loss = loss_dict['main_loss'] ############ This part is revised ############ ... ... ... ``` -------------------------------- ### Implement a custom EvalTPL Source: https://edustudio.readthedocs.io/en/latest/_sources/developer_guide/customize_evaltpl.md.txt Create a new evaluation template by inheriting from BaseEvalTPL and overriding the eval method to define custom metric calculations. ```python from .base_evaltpl import BaseEvalTPL from sklearn.metrics import accuracy_score, coverage_error class NewEvalFmt(BaseEvalFmt): default_cfg = { 'use_metrics': ['acc', 'coverage_error'] } def __init__(self, cfg): super().__init__(cfg) def eval(self, y_pd, y_gt, **kwargs): if not isinstance(y_pd, np.ndarray): y_pd = tensor2npy(y_pd) if not isinstance(y_gt, np.ndarray): y_gt = tensor2npy(y_gt) metric_result = {} ignore_metrics = kwargs.get('ignore_metrics', {}) for metric_name in self.evalfmt_cfg[self.__class__.__name__]['use_metrics']: if metric_name not in ignore_metrics: metric_result[metric_name] = self._get_metrics(metric_name)(y_gt, y_pd) return metric_result def _get_metrics(self, metric): if metric == "acc": return lambda y_gt, y_pd: accuracy_score(y_gt, np.where(y_pd >= 0.5, 1, 0)) elif metric == 'coverage_error': return lambda y_gt, y_pd: coverage_error(y_gt, y_pd) else: raise NotImplementedError ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.