projects
/
culture.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Update.
[culture.git]
/
quiz_machine.py
diff --git
a/quiz_machine.py
b/quiz_machine.py
index
8ab5696
..
eab41dc
100755
(executable)
--- a/
quiz_machine.py
+++ b/
quiz_machine.py
@@
-241,7
+241,7
@@
class QuizMachine:
self.train_c_quizzes = []
self.test_c_quizzes = []
self.train_c_quizzes = []
self.test_c_quizzes = []
- def save_quiz
ze
s(
+ def save_quiz
_illustration
s(
self,
result_dir,
filename_prefix,
self,
result_dir,
filename_prefix,
@@
-266,7
+266,7
@@
class QuizMachine:
predicted_prompts *= 2
predicted_answers *= 2
predicted_prompts *= 2
predicted_answers *= 2
- self.problem.save_quiz
ze
s(
+ self.problem.save_quiz
_illustration
s(
result_dir,
filename_prefix,
quizzes[:, 1 : 1 + self.prompt_len],
result_dir,
filename_prefix,
quizzes[:, 1 : 1 + self.prompt_len],
@@
-368,16
+368,12
@@
class QuizMachine:
backward_nb_total = correct[n_backward].size(0)
self.logger(
backward_nb_total = correct[n_backward].size(0)
self.logger(
- f"{log_prefix}_forward_accuracy {n_epoch} model {model.id} nb_correct {forward_nb_correct} / {forward_nb_total} ({forward_nb_correct*100/forward_nb_total} %)"
- )
-
- self.logger(
- f"{log_prefix}_backward_accuracy {n_epoch} model {model.id} nb_correct {backward_nb_correct} / {backward_nb_total} ({backward_nb_correct*100/backward_nb_total} %)"
+ f"{log_prefix}_accuracy {n_epoch} model {model.id} forward {forward_nb_correct} / {forward_nb_total} backward {backward_nb_correct} / {backward_nb_total}"
)
return result, correct
)
return result, correct
- compute_accuracy(model.train_w_quizzes[:nmax], log_prefix="train")
+
#
compute_accuracy(model.train_w_quizzes[:nmax], log_prefix="train")
test_result, test_correct = compute_accuracy(
model.test_w_quizzes[:nmax], log_prefix="test"
test_result, test_correct = compute_accuracy(
model.test_w_quizzes[:nmax], log_prefix="test"
@@
-388,7
+384,7
@@
class QuizMachine:
##############################
##############################
- self.save_quiz
ze
s(
+ self.save_quiz
_illustration
s(
result_dir,
f"culture_prediction_{n_epoch:04d}_{model.id:02d}",
quizzes=test_result[:72],
result_dir,
f"culture_prediction_{n_epoch:04d}_{model.id:02d}",
quizzes=test_result[:72],
@@
-416,11
+412,17
@@
class QuizMachine:
else:
self.test_c_quizzes.append(new_c_quizzes.to("cpu"))
else:
self.test_c_quizzes.append(new_c_quizzes.to("cpu"))
+ def save_c_quizzes(self, filename):
+ torch.save((self.train_c_quizzes, self.test_c_quizzes), filename)
+
+ def load_c_quizzes(self, filename):
+ self.train_c_quizzes, self.test_c_quizzes = torch.load(filename)
+
######################################################################
def logproba_of_solutions(self, models, c_quizzes):
logproba = c_quizzes.new_zeros(
######################################################################
def logproba_of_solutions(self, models, c_quizzes):
logproba = c_quizzes.new_zeros(
- c_quizzes.size(0), len(models), device=self.device
+ c_quizzes.size(0), len(models), device=self.device
, dtype=torch.float32
)
for model in models:
)
for model in models: