|
| 1 | +# Configure logging |
| 2 | +import logging |
| 3 | + |
| 4 | +logging.basicConfig( |
| 5 | + level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s" |
| 6 | +) |
| 7 | +logger = logging.getLogger() |
| 8 | + |
| 9 | +from folde.campaign import simulate_campaigns_with_config_checkpoints |
| 10 | +from folde.types import FolDEModelConfig, ModelDiff |
| 11 | +from folde.util import apply_diff_list_to_config |
| 12 | + |
| 13 | +folde_train_dms_ids = [ |
| 14 | + "ANCSZ_Hobbs_2022", |
| 15 | + "BLAT_ECOLX_Firnberg_2014", |
| 16 | + "CBS_HUMAN_Sun_2020", |
| 17 | + "HEM3_HUMAN_Loggerenberg_2023", |
| 18 | + "HSP82_YEAST_Flynn_2019", |
| 19 | + "HXK4_HUMAN_Gersing_2022_activity", |
| 20 | + "OXDA_RHOTO_Vanella_2023_activity", |
| 21 | + "PPM1D_HUMAN_Miller_2022", |
| 22 | + "SHOC2_HUMAN_Kwon_2022", |
| 23 | +] |
| 24 | + |
| 25 | +# Example configuration |
| 26 | +NAME = "250917_zero_shot_cl" |
| 27 | + |
| 28 | +random_config = FolDEModelConfig( |
| 29 | + name="Random", |
| 30 | + naturalness_model_id="600m", |
| 31 | + embedding_model_id="300m", |
| 32 | + zero_shot_model_name="RandomZeroShotModel", |
| 33 | + zero_shot_model_params={}, |
| 34 | + few_shot_model_name="RandomFewShotModel", |
| 35 | + few_shot_model_params={}, |
| 36 | +) |
| 37 | + |
| 38 | +random_forest_config = FolDEModelConfig( |
| 39 | + name="RandomToRandomForest", |
| 40 | + naturalness_model_id="600m", |
| 41 | + embedding_model_id="300m", |
| 42 | + zero_shot_model_name="RandomZeroShotModel", |
| 43 | + zero_shot_model_params={}, |
| 44 | + few_shot_model_name="RandomForestFewShotModel", |
| 45 | + few_shot_model_params={ |
| 46 | + "n_estimators": 100, |
| 47 | + "criterion": "friedman_mse", |
| 48 | + "max_depth": None, |
| 49 | + "min_samples_split": 2, |
| 50 | + "min_samples_leaf": 1, |
| 51 | + "min_weight_fraction_leaf": 0.0, |
| 52 | + "max_features": 1.0, |
| 53 | + "max_leaf_nodes": None, |
| 54 | + "min_impurity_decrease": 0.0, |
| 55 | + "bootstrap": True, |
| 56 | + "oob_score": False, |
| 57 | + "n_jobs": None, |
| 58 | + "verbose": 0, |
| 59 | + "warm_start": False, |
| 60 | + "ccp_alpha": 0.0, |
| 61 | + "max_samples": None, |
| 62 | + }, |
| 63 | +) |
| 64 | + |
| 65 | +folde_config = FolDEModelConfig( |
| 66 | + name="FolDE", |
| 67 | + # Required parameters |
| 68 | + naturalness_model_id="600m", # ESM-2 650M model |
| 69 | + embedding_model_id="300m", # Same model for embeddings |
| 70 | + zero_shot_model_name="NaturalnessZeroShotModel", |
| 71 | + zero_shot_model_params={}, |
| 72 | + # Few-shot model configuration (used after first round) |
| 73 | + few_shot_model_name="TorchMLPFewShotModel", |
| 74 | + few_shot_model_params={ |
| 75 | + "pretrain": True, |
| 76 | + "pretrain_epochs": 50, |
| 77 | + "ensemble_size": 5, |
| 78 | + "embedding_dim": 960, |
| 79 | + "hidden_dims": [100, 50], |
| 80 | + "dropout": 0.2, |
| 81 | + "learning_rate": 3e-4, |
| 82 | + "weight_decay": 1e-5, |
| 83 | + "train_epochs": 200, |
| 84 | + "train_patience": 40, |
| 85 | + "val_frequency": 10, |
| 86 | + "do_validation_with_pair_fraction": 0.2, |
| 87 | + "decision_mode": "constantliar", |
| 88 | + "lie_noise_stddev_multiplier": 0.25, |
| 89 | + }, |
| 90 | +) |
| 91 | + |
| 92 | +mlp_config_list = apply_diff_list_to_config( |
| 93 | + folde_config, |
| 94 | + [ |
| 95 | + ModelDiff(name="no-constantliar", diffs={"few_shot_model_params.decision_mode": "mean"}), |
| 96 | + ModelDiff(name="with-esmv1", diffs={ |
| 97 | + "naturalness_model_id": "1v", |
| 98 | + "naturalness_columns": ['wt_marginal_1', 'wt_marginal_2', 'wt_marginal_3', 'wt_marginal_4', 'wt_marginal_5'], |
| 99 | + }), |
| 100 | + ModelDiff(name="with-esmv1-zsclS025", diffs={ |
| 101 | + "naturalness_model_id": "1v", |
| 102 | + "naturalness_columns": ['wt_marginal_1', 'wt_marginal_2', 'wt_marginal_3', 'wt_marginal_4', 'wt_marginal_5'], |
| 103 | + |
| 104 | + "zero_shot_model_params.decision_mode": "constantliar", |
| 105 | + "zero_shot_model_params.lie_noise_stddev_multiplier": 0.25, |
| 106 | + }), |
| 107 | + ], |
| 108 | +) |
| 109 | + |
| 110 | +config_list = [random_config, random_forest_config] + mlp_config_list |
| 111 | + |
| 112 | +print(f"Config 1/{len(config_list)}:") |
| 113 | +print(config_list[0].model_dump_json(indent=2)) |
| 114 | + |
| 115 | +results = simulate_campaigns_with_config_checkpoints( |
| 116 | + eval_prefix=NAME, |
| 117 | + dms_ids=folde_train_dms_ids, |
| 118 | + config_list=config_list, |
| 119 | + checkpoint_dir="notebooks/jacob/model_evals", |
| 120 | + round_size=16, |
| 121 | + number_of_simulations=10, |
| 122 | + activity_column="DMS_score", |
| 123 | + max_rounds=6, |
| 124 | + random_seed=42, |
| 125 | + num_workers=10, |
| 126 | +) |
0 commit comments