BrightBlueCheese
commited on
Commit
•
4253818
1
Parent(s):
f21a2a6
app
Browse files
.ipynb_checkpoints/auto_evaluator_sl-checkpoint.py
CHANGED
@@ -18,9 +18,9 @@ import chemllama_mtr
|
|
18 |
import datamodule_finetune_sl
|
19 |
# from .model_finetune import CustomFinetuneModel
|
20 |
import model_finetune_sl
|
21 |
-
import
|
22 |
|
23 |
-
def
|
24 |
dir_model_mtr,
|
25 |
# dir_model_mtr_ep_to_save:str,
|
26 |
dir_model_ft_to_save:str,
|
@@ -68,7 +68,7 @@ def auto_evaluator_level_2_sol(
|
|
68 |
name_model_ft = f"SolLlama_{solute_or_solvent}"
|
69 |
|
70 |
# array_level_1, model_ft, data_loader_test
|
71 |
-
array_level_1 =
|
72 |
model_mtr=model_mtr,
|
73 |
dir_model_ft=dir_model_ft,
|
74 |
name_model_ft=name_model_ft,
|
@@ -93,7 +93,7 @@ def auto_evaluator_level_2_sol(
|
|
93 |
|
94 |
# return array_level_2
|
95 |
|
96 |
-
def
|
97 |
model_mtr,
|
98 |
dir_model_ft:str,
|
99 |
name_model_ft:str,
|
@@ -141,7 +141,7 @@ def auto_evaluator_level_1_sol(
|
|
141 |
batch_size_for_train = batch_size_pair[0]
|
142 |
batch_size_for_valid = batch_size_pair[1]
|
143 |
|
144 |
-
data_module =
|
145 |
solute_or_solvent=solute_or_solvent,
|
146 |
tokenizer=tokenizer,
|
147 |
max_seq_length=max_length,
|
@@ -157,7 +157,7 @@ def auto_evaluator_level_1_sol(
|
|
157 |
# Load model and optimizer for finetune
|
158 |
learning_rate = lr
|
159 |
|
160 |
-
model_ft =
|
161 |
model_mtr=model_mtr,
|
162 |
steps_per_epoch=steps_per_epoch,
|
163 |
warmup_epochs=1,
|
@@ -222,7 +222,7 @@ def auto_evaluator_level_1_sub_sol(
|
|
222 |
{dir_folder}/{name_model_ft}_ep_000
|
223 |
"""
|
224 |
|
225 |
-
array_loss_ranking =
|
226 |
list_value=list_validation_loss,
|
227 |
# dataset_dict=dataset_dict,
|
228 |
is_loss=True,
|
@@ -235,7 +235,7 @@ def auto_evaluator_level_1_sub_sol(
|
|
235 |
list_level_1 = list()
|
236 |
for ep in range(len(list_validation_loss)):
|
237 |
|
238 |
-
local_model_ft =
|
239 |
class_model_ft=class_model_ft,
|
240 |
target_epoch=ep,
|
241 |
dir_model_ft=dir_model_ft,
|
@@ -249,7 +249,7 @@ def auto_evaluator_level_1_sub_sol(
|
|
249 |
result_pred.append(result[bat][0].squeeze())
|
250 |
result_label.append(result[bat][1])
|
251 |
|
252 |
-
list_local_model_ft_result =
|
253 |
array_predictions=np.vstack(result_pred),
|
254 |
array_labels=np.vstack(result_label),
|
255 |
# dataset_dict=dataset_dict,
|
@@ -270,7 +270,7 @@ def auto_evaluator_level_1_sub_sol(
|
|
270 |
# to get the metric_1 ranking
|
271 |
array_level_1 = np.array(list_level_1)
|
272 |
array_metric_1 = array_level_1[:, 2].astype('float32')
|
273 |
-
array_metric_1_ranking =
|
274 |
# dataset_dict=dataset_dict,
|
275 |
is_loss=False)
|
276 |
|
|
|
18 |
import datamodule_finetune_sl
|
19 |
# from .model_finetune import CustomFinetuneModel
|
20 |
import model_finetune_sl
|
21 |
+
import utils_sl
|
22 |
|
23 |
+
def auto_evaluator_level_2_sl(
|
24 |
dir_model_mtr,
|
25 |
# dir_model_mtr_ep_to_save:str,
|
26 |
dir_model_ft_to_save:str,
|
|
|
68 |
name_model_ft = f"SolLlama_{solute_or_solvent}"
|
69 |
|
70 |
# array_level_1, model_ft, data_loader_test
|
71 |
+
array_level_1 = auto_evaluator_level_1_sl(
|
72 |
model_mtr=model_mtr,
|
73 |
dir_model_ft=dir_model_ft,
|
74 |
name_model_ft=name_model_ft,
|
|
|
93 |
|
94 |
# return array_level_2
|
95 |
|
96 |
+
def auto_evaluator_level_1_sl(
|
97 |
model_mtr,
|
98 |
dir_model_ft:str,
|
99 |
name_model_ft:str,
|
|
|
141 |
batch_size_for_train = batch_size_pair[0]
|
142 |
batch_size_for_valid = batch_size_pair[1]
|
143 |
|
144 |
+
data_module = datamodule_finetune_sl.CustomFinetuneDataModule(
|
145 |
solute_or_solvent=solute_or_solvent,
|
146 |
tokenizer=tokenizer,
|
147 |
max_seq_length=max_length,
|
|
|
157 |
# Load model and optimizer for finetune
|
158 |
learning_rate = lr
|
159 |
|
160 |
+
model_ft = model_finetune_sl.CustomFinetuneModel(
|
161 |
model_mtr=model_mtr,
|
162 |
steps_per_epoch=steps_per_epoch,
|
163 |
warmup_epochs=1,
|
|
|
222 |
{dir_folder}/{name_model_ft}_ep_000
|
223 |
"""
|
224 |
|
225 |
+
array_loss_ranking = utils_sl.rank_value_sol(
|
226 |
list_value=list_validation_loss,
|
227 |
# dataset_dict=dataset_dict,
|
228 |
is_loss=True,
|
|
|
235 |
list_level_1 = list()
|
236 |
for ep in range(len(list_validation_loss)):
|
237 |
|
238 |
+
local_model_ft = utils_sl.load_model_ft_with_epoch(
|
239 |
class_model_ft=class_model_ft,
|
240 |
target_epoch=ep,
|
241 |
dir_model_ft=dir_model_ft,
|
|
|
249 |
result_pred.append(result[bat][0].squeeze())
|
250 |
result_label.append(result[bat][1])
|
251 |
|
252 |
+
list_local_model_ft_result = utils_sl.model_evalulator_sol(
|
253 |
array_predictions=np.vstack(result_pred),
|
254 |
array_labels=np.vstack(result_label),
|
255 |
# dataset_dict=dataset_dict,
|
|
|
270 |
# to get the metric_1 ranking
|
271 |
array_level_1 = np.array(list_level_1)
|
272 |
array_metric_1 = array_level_1[:, 2].astype('float32')
|
273 |
+
array_metric_1_ranking = utils_sl.rank_value_sol(list_value=array_metric_1,
|
274 |
# dataset_dict=dataset_dict,
|
275 |
is_loss=False)
|
276 |
|
auto_evaluator_sl.py
CHANGED
@@ -18,9 +18,9 @@ import chemllama_mtr
|
|
18 |
import datamodule_finetune_sl
|
19 |
# from .model_finetune import CustomFinetuneModel
|
20 |
import model_finetune_sl
|
21 |
-
import
|
22 |
|
23 |
-
def
|
24 |
dir_model_mtr,
|
25 |
# dir_model_mtr_ep_to_save:str,
|
26 |
dir_model_ft_to_save:str,
|
@@ -68,7 +68,7 @@ def auto_evaluator_level_2_sol(
|
|
68 |
name_model_ft = f"SolLlama_{solute_or_solvent}"
|
69 |
|
70 |
# array_level_1, model_ft, data_loader_test
|
71 |
-
array_level_1 =
|
72 |
model_mtr=model_mtr,
|
73 |
dir_model_ft=dir_model_ft,
|
74 |
name_model_ft=name_model_ft,
|
@@ -93,7 +93,7 @@ def auto_evaluator_level_2_sol(
|
|
93 |
|
94 |
# return array_level_2
|
95 |
|
96 |
-
def
|
97 |
model_mtr,
|
98 |
dir_model_ft:str,
|
99 |
name_model_ft:str,
|
@@ -141,7 +141,7 @@ def auto_evaluator_level_1_sol(
|
|
141 |
batch_size_for_train = batch_size_pair[0]
|
142 |
batch_size_for_valid = batch_size_pair[1]
|
143 |
|
144 |
-
data_module =
|
145 |
solute_or_solvent=solute_or_solvent,
|
146 |
tokenizer=tokenizer,
|
147 |
max_seq_length=max_length,
|
@@ -157,7 +157,7 @@ def auto_evaluator_level_1_sol(
|
|
157 |
# Load model and optimizer for finetune
|
158 |
learning_rate = lr
|
159 |
|
160 |
-
model_ft =
|
161 |
model_mtr=model_mtr,
|
162 |
steps_per_epoch=steps_per_epoch,
|
163 |
warmup_epochs=1,
|
@@ -222,7 +222,7 @@ def auto_evaluator_level_1_sub_sol(
|
|
222 |
{dir_folder}/{name_model_ft}_ep_000
|
223 |
"""
|
224 |
|
225 |
-
array_loss_ranking =
|
226 |
list_value=list_validation_loss,
|
227 |
# dataset_dict=dataset_dict,
|
228 |
is_loss=True,
|
@@ -235,7 +235,7 @@ def auto_evaluator_level_1_sub_sol(
|
|
235 |
list_level_1 = list()
|
236 |
for ep in range(len(list_validation_loss)):
|
237 |
|
238 |
-
local_model_ft =
|
239 |
class_model_ft=class_model_ft,
|
240 |
target_epoch=ep,
|
241 |
dir_model_ft=dir_model_ft,
|
@@ -249,7 +249,7 @@ def auto_evaluator_level_1_sub_sol(
|
|
249 |
result_pred.append(result[bat][0].squeeze())
|
250 |
result_label.append(result[bat][1])
|
251 |
|
252 |
-
list_local_model_ft_result =
|
253 |
array_predictions=np.vstack(result_pred),
|
254 |
array_labels=np.vstack(result_label),
|
255 |
# dataset_dict=dataset_dict,
|
@@ -270,7 +270,7 @@ def auto_evaluator_level_1_sub_sol(
|
|
270 |
# to get the metric_1 ranking
|
271 |
array_level_1 = np.array(list_level_1)
|
272 |
array_metric_1 = array_level_1[:, 2].astype('float32')
|
273 |
-
array_metric_1_ranking =
|
274 |
# dataset_dict=dataset_dict,
|
275 |
is_loss=False)
|
276 |
|
|
|
18 |
import datamodule_finetune_sl
|
19 |
# from .model_finetune import CustomFinetuneModel
|
20 |
import model_finetune_sl
|
21 |
+
import utils_sl
|
22 |
|
23 |
+
def auto_evaluator_level_2_sl(
|
24 |
dir_model_mtr,
|
25 |
# dir_model_mtr_ep_to_save:str,
|
26 |
dir_model_ft_to_save:str,
|
|
|
68 |
name_model_ft = f"SolLlama_{solute_or_solvent}"
|
69 |
|
70 |
# array_level_1, model_ft, data_loader_test
|
71 |
+
array_level_1 = auto_evaluator_level_1_sl(
|
72 |
model_mtr=model_mtr,
|
73 |
dir_model_ft=dir_model_ft,
|
74 |
name_model_ft=name_model_ft,
|
|
|
93 |
|
94 |
# return array_level_2
|
95 |
|
96 |
+
def auto_evaluator_level_1_sl(
|
97 |
model_mtr,
|
98 |
dir_model_ft:str,
|
99 |
name_model_ft:str,
|
|
|
141 |
batch_size_for_train = batch_size_pair[0]
|
142 |
batch_size_for_valid = batch_size_pair[1]
|
143 |
|
144 |
+
data_module = datamodule_finetune_sl.CustomFinetuneDataModule(
|
145 |
solute_or_solvent=solute_or_solvent,
|
146 |
tokenizer=tokenizer,
|
147 |
max_seq_length=max_length,
|
|
|
157 |
# Load model and optimizer for finetune
|
158 |
learning_rate = lr
|
159 |
|
160 |
+
model_ft = model_finetune_sl.CustomFinetuneModel(
|
161 |
model_mtr=model_mtr,
|
162 |
steps_per_epoch=steps_per_epoch,
|
163 |
warmup_epochs=1,
|
|
|
222 |
{dir_folder}/{name_model_ft}_ep_000
|
223 |
"""
|
224 |
|
225 |
+
array_loss_ranking = utils_sl.rank_value_sol(
|
226 |
list_value=list_validation_loss,
|
227 |
# dataset_dict=dataset_dict,
|
228 |
is_loss=True,
|
|
|
235 |
list_level_1 = list()
|
236 |
for ep in range(len(list_validation_loss)):
|
237 |
|
238 |
+
local_model_ft = utils_sl.load_model_ft_with_epoch(
|
239 |
class_model_ft=class_model_ft,
|
240 |
target_epoch=ep,
|
241 |
dir_model_ft=dir_model_ft,
|
|
|
249 |
result_pred.append(result[bat][0].squeeze())
|
250 |
result_label.append(result[bat][1])
|
251 |
|
252 |
+
list_local_model_ft_result = utils_sl.model_evalulator_sol(
|
253 |
array_predictions=np.vstack(result_pred),
|
254 |
array_labels=np.vstack(result_label),
|
255 |
# dataset_dict=dataset_dict,
|
|
|
270 |
# to get the metric_1 ranking
|
271 |
array_level_1 = np.array(list_level_1)
|
272 |
array_metric_1 = array_level_1[:, 2].astype('float32')
|
273 |
+
array_metric_1_ranking = utils_sl.rank_value_sol(list_value=array_metric_1,
|
274 |
# dataset_dict=dataset_dict,
|
275 |
is_loss=False)
|
276 |
|