### Install EduStudio from source Source: https://github.com/hfut-lec/edustudio/blob/main/docs/source/get_started/install.md Install the package in editable mode from the local directory with verbose output enabled. ```bash pip install -e . --verbose ``` -------------------------------- ### Hyper Parameter Tuning with HyperOpt Source: https://github.com/hfut-lec/edustudio/blob/main/docs/source/user_guide/usage/aht.md Example demonstrating how to use HyperOpt to optimize Edustudio model configurations. ```python import sys import os from edustudio.quickstart import run_edustudio from hyperopt import hp from hyperopt import fmin, tpe, space_eval from edustudio.utils.common import IDUtil as idUtil import uuid def deliver_cfg(args): g_args = { 'traintpl_cfg': {}, 'datatpl_cfg': {}, 'modeltpl_cfg': {}, 'evaltpl_cfg': {}, } for k,v in args.items(): g, k = k.split(".") assert g in g_args g_args[g][k] = v g_args['frame_cfg'] = { 'ID': idUtil.get_random_id_bytime() + str(uuid.uuid4()).split("-")[-1] } 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)) ``` -------------------------------- ### Hyper Parameter Tuning with Ray.Tune Source: https://github.com/hfut-lec/edustudio/blob/main/docs/source/user_guide/usage/aht.md Example demonstrating how to use Ray.Tune to optimize Edustudio model configurations. ```python # run following after installed edustudio from edustudio.quickstart import run_edustudio from ray import tune import ray ray.init(num_cpus=4, num_gpus=1) from edustudio.utils.common import IDUtil as idUtil import uuid 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 g_args['frame_cfg'] = { 'ID': idUtil.get_random_id_bytime() + str(uuid.uuid4()).split("-")[-1] } 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(["cuda:0"]), 'modeltpl_cfg.emb_dim': tune.grid_search([20,40]), 'frame_cfg.DISABLE_LOG_STDOUT': tune.grid_search([False]), } tuner = tune.Tuner( tune.with_resources(objective_function, {"gpu": 1}), 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) ``` -------------------------------- ### Install EduStudio via pip Source: https://github.com/hfut-lec/edustudio/blob/main/docs/source/get_started/install.md Use this command to install the latest version of EduStudio from the Python Package Index. ```bash pip install -U edustudio ``` -------------------------------- ### Load Dataset from Cached Data Source: https://github.com/hfut-lec/edustudio/blob/main/docs/source/features/dataset_folder_protocol.md Configure the quickstart runner to load pre-processed model-friendly cached data. ```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'], } ) ``` -------------------------------- ### Load Dataset from Raw Data Source: https://github.com/hfut-lec/edustudio/blob/main/docs/source/features/dataset_folder_protocol.md Configure the quickstart runner to process raw data into middle data using a specified 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://github.com/hfut-lec/edustudio/blob/main/docs/source/features/dataset_folder_protocol.md Configure the quickstart runner to load standardized middle data and optionally save it as cached data. ```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'], } ) ``` -------------------------------- ### Clone EduStudio source repository Source: https://github.com/hfut-lec/edustudio/blob/main/docs/source/get_started/install.md Download the source code from the official GitHub repository to prepare for local installation. ```bash git clone https://github.com/HFUT-LEC/EduStudio.git && cd EduStudio ``` -------------------------------- ### Dataset Folder Structure Example Source: https://github.com/hfut-lec/edustudio/blob/main/docs/source/features/dataset_folder_protocol.md The required directory layout for a dataset, showing the organization of raw, middle, and cached data files. ```default 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 ``` -------------------------------- ### Run NCDM Model Source: https://github.com/hfut-lec/edustudio/blob/main/README.md Example usage of the run_edustudio function to execute the NCDM model with specified training, data, and evaluation templates. ```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': 'NCDM', }, evaltpl_cfg_dict={ 'clses': ['PredictionEvalTPL', 'InterpretabilityEvalTPL'], } ) ``` -------------------------------- ### Complete Custom TrainTPL Implementation Source: https://github.com/hfut-lec/edustudio/blob/main/docs/source/developer_guide/customize_traintpl.md A full example of a custom training template that overrides the fit method to switch loss functions after a specific epoch. ```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() ``` -------------------------------- ### Implement BaseRaw2Mid Subclass Source: https://github.com/hfut-lec/edustudio/blob/main/docs/source/developer_guide/customize_atomic_op.md Example implementation of a BaseRaw2Mid subclass for the Assistment 2019-2010 dataset, demonstrating reading from raw paths and saving to middle paths. ```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') ``` -------------------------------- ### Implement M2C_RandomDataSplit4CD Atomic Operation Source: https://github.com/hfut-lec/edustudio/blob/main/docs/source/developer_guide/customize_atomic_op.md Example implementation of a data splitting operation for cognitive diagnosis, demonstrating configuration validation and dataset processing. ```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) ``` -------------------------------- ### Run EduStudio Experiment Source: https://github.com/hfut-lec/edustudio/blob/main/docs/source/get_started/quick_start.md Initializes and executes an experiment using specific dataset, model, and evaluation templates. ```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://github.com/hfut-lec/edustudio/blob/main/docs/source/user_guide/usage/run_edustudio.md 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 ``` -------------------------------- ### Run with command-line parameters Source: https://github.com/hfut-lec/edustudio/blob/main/docs/source/user_guide/usage/run_edustudio.md Override configuration settings directly from the command line when executing the script. ```bash cd examples python run.py -dt ASSIST_0910 --modeltpl_cfg.cls NCDM --traintpl_cfg.batch_size 512 ``` -------------------------------- ### Develop a backbone-style ModelTPL Source: https://github.com/hfut-lec/edustudio/blob/main/docs/source/developer_guide/customize_modeltpl.md Inherit from BaseProxyModelTPL and specify the backbone_model_cls in the default configuration. ```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): ... ``` -------------------------------- ### Develop a traditional ModelTPL Source: https://github.com/hfut-lec/edustudio/blob/main/docs/source/developer_guide/customize_modeltpl.md Inherit from GDBaseModelTPL and implement abstract methods for configuration, model construction, prediction, and loss calculation. ```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) ``` -------------------------------- ### Define Inheritable Data Template Classes Source: https://github.com/hfut-lec/edustudio/blob/main/docs/source/features/inheritable_config.md Demonstrates defining three data template classes that inherit from each other, each with its own default_cfg dictionary. ```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': (), } ``` -------------------------------- ### Override M2C_FilterRecords4CD configuration Source: https://github.com/hfut-lec/edustudio/blob/main/docs/source/user_guide/usage/use_case_of_config.md Demonstrates how to pass a custom configuration dictionary to the datatpl_cfg_dict parameter in run_edustudio. ```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 a Custom TrainTPL Class Source: https://github.com/hfut-lec/edustudio/blob/main/docs/source/developer_guide/customize_traintpl.md 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) ``` -------------------------------- ### Resulting Merged Configuration Source: https://github.com/hfut-lec/edustudio/blob/main/docs/source/features/inheritable_config.md Shows the final merged default_cfg dictionary when EduDataTPL is selected as the data template. ```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 } ``` -------------------------------- ### Read Experimental Results Source: https://github.com/hfut-lec/edustudio/blob/main/docs/source/user_guide/usage/aht.md Utility function to load the result.json file generated by an Edustudio 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://github.com/hfut-lec/edustudio/blob/main/docs/source/user_guide/usage/use_case_of_config.md Shows the default configuration structure for the PredictionEvalTPL class. ```python class PredictionEvalTPL(BaseEvalTPL): default_cfg = { 'use_metrics': ['auc', 'acc', 'rmse'] } ``` -------------------------------- ### EduStudio Citation Source: https://github.com/hfut-lec/edustudio/blob/main/README.md BibTeX entry for citing the EduStudio library. ```bibtex @article{Le WU:198342, author = {Le WU, Xiangzhi CHEN, Fei LIU, Junsong XIE, Chenao XIA, Zhengtao TAN, Mi TIAN, Jinglong LI, Kun ZHANG, Defu LIAN, Richang HONG, Meng WANG}, title = {EduStudio: towards a unified library for student cognitive modeling}, publisher = {Front. Comput. Sci.}, year = {2025}, journal = {Frontiers of Computer Science}, volume = {19}, number = {8}, eid = {198342}, numpages = {0}, pages = {198342}, keywords = {open-source library;student cognitive modeling;intelligence education}, url = {https://journal.hep.com.cn/fcs/EN/abstract/article_47994.shtml}, doi = {10.1007/s11704-024-40372-3} } ``` -------------------------------- ### Configure Atomic Operation Sequence in EduStudio Source: https://github.com/hfut-lec/edustudio/blob/main/docs/source/features/dataset_folder_protocol.md Defines the data processing pipeline using 'mid2cache_op_seq' within the datatpl_cfg_dict to transform raw data into a cache-ready format. ```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'], } ) ``` -------------------------------- ### Override evaluation template configuration Source: https://github.com/hfut-lec/edustudio/blob/main/docs/source/user_guide/usage/use_case_of_config.md Demonstrates how to customize evaluation metrics by passing a specific configuration to the evaltpl_cfg_dict parameter. ```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 } } ) ``` -------------------------------- ### Define M2C_FilterRecords4CD default configuration Source: https://github.com/hfut-lec/edustudio/blob/main/docs/source/user_guide/usage/use_case_of_config.md Shows the default configuration structure for the M2C_FilterRecords4CD class. ```python class M2C_FilterRecords4CD(BaseMid2Cache): default_cfg = { "stu_least_records": 10, "exer_least_records": 0, } ``` -------------------------------- ### Run R2M process for FrcSub dataset Source: https://github.com/hfut-lec/edustudio/blob/main/docs/source/user_guide/usage/atomic_cmds.md Executes the R2M process to convert raw data to mid-level data for the FrcSub dataset. ```bash edustudio r2m R2M_FrcSub --dt FrcSub --rawpath data/FrcSub/rawdata --midpath data/FrcSub/middata ``` -------------------------------- ### Implement a custom EvalTPL in Python Source: https://github.com/hfut-lec/edustudio/blob/main/docs/source/developer_guide/customize_evaltpl.md Create a new evaluation template by inheriting from BaseEvalTPL and defining the eval method and default configuration. ```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 ``` -------------------------------- ### Execute Python Script Source: https://github.com/hfut-lec/edustudio/blob/main/docs/source/get_started/quick_start.md Command to execute the previously created Python script from the terminal. ```bash python run.py ``` -------------------------------- ### Override the fit Method Source: https://github.com/hfut-lec/edustudio/blob/main/docs/source/developer_guide/customize_traintpl.md Implement custom loss calculation logic within the fit method to modify training behavior based on epoch counts. ```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 ############ ... ... ... ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.