-
Notifications
You must be signed in to change notification settings - Fork 186
Update keras, tf and new model usage, numpy 2.0 updates #1206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 14 commits
d6b1ec1
9920fab
7592895
a3592fb
3ecaf6b
0a2efd3
fb321a2
2207920
96344db
0458e73
2fe4ddd
c41303e
0615268
f08af16
e5f4041
052d058
3965667
f1046a9
8f1b4e0
fdc671e
34c47fe
57066fb
5de7abe
e1afcf7
0b00aed
8edd1dc
03b4fa1
ffbac1a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -450,6 +450,7 @@ def load_from_disk(cls, dirpath: str) -> CharacterLevelCnnModel: | |
| loaded_model._model_default_ind = loaded_model.label_mapping[ | ||
| loaded_model._parameters["default_label"] | ||
| ] | ||
| loaded_model._compile_loss(loaded_model._model, loaded_model.num_labels) | ||
| return loaded_model | ||
|
|
||
| @staticmethod | ||
|
|
@@ -475,6 +476,28 @@ def _argmax_threshold_layer( | |
| # matrix. | ||
| return ThreshArgMaxLayer(threshold, num_labels, default_ind) | ||
|
|
||
| @staticmethod | ||
| def _compile_loss(model: tf.keras.Model, num_labels: int) -> None: | ||
| """Compiles the loss for the given model and number of labels.""" | ||
| # Compile the model | ||
| softmax_output_layer_name = model.output_names[0] | ||
| # losses = {softmax_output_layer_name: "categorical_crossentropy"} | ||
| losses = ["categorical_crossentropy", None, None] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quick question — the loss assignment changed from dict-based (by output name) to list-based (by position): CharacterLevelCnnModel (3 outputs)losses = ["categorical_crossentropy", None, None] CharLoadTFModel (2 outputs)losses = ["categorical_crossentropy", None] Can you confirm the output ordering is stable and these align correctly with the model outputs? Just want to make sure the positional
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call out! I believe the previous layers were list based which is why in keras 3 it required the list losses. This code matched that, however, like you I prefer the order-independent approach and am looking into the requirements of that and ensuring the backwards compatibility of loading a model that was list based initially. |
||
|
|
||
| # use f1 score metric | ||
| f1_score_training = labeler_utils.F1Score( | ||
| num_classes=num_labels, average="micro" | ||
| ) | ||
| metrics = { | ||
| softmax_output_layer_name: [ | ||
| "categorical_crossentropy", | ||
| "acc", | ||
| f1_score_training, | ||
| ] | ||
| } | ||
|
|
||
| model.compile(loss=losses, optimizer="adam", metrics=metrics) | ||
|
|
||
| def _construct_model(self) -> None: | ||
| """ | ||
| Construct model for the data labeler. | ||
|
|
@@ -570,24 +593,7 @@ def _construct_model(self) -> None: | |
| final_predicted_layer(argmax_layer, self._model.outputs[0]), | ||
| ] | ||
| self._model = tf.keras.Model(self._model.inputs, argmax_outputs) | ||
|
|
||
| # Compile the model | ||
| softmax_output_layer_name = self._model.output_names[0] | ||
| losses = {softmax_output_layer_name: "categorical_crossentropy"} | ||
|
|
||
| # use f1 score metric | ||
| f1_score_training = labeler_utils.F1Score( | ||
| num_classes=num_labels, average="micro" | ||
| ) | ||
| metrics = { | ||
| softmax_output_layer_name: [ | ||
| "categorical_crossentropy", | ||
| "acc", | ||
| f1_score_training, | ||
| ] | ||
| } | ||
|
|
||
| self._model.compile(loss=losses, optimizer="adam", metrics=metrics) | ||
| self._compile_loss(self._model, num_labels) | ||
|
|
||
| self._epoch_id = 0 | ||
| self._model_num_labels = num_labels | ||
|
|
@@ -632,24 +638,7 @@ def _reconstruct_model(self) -> None: | |
| final_predicted_layer(argmax_layer, final_softmax_layer), | ||
| ] | ||
| self._model = tf.keras.Model(self._model.inputs, argmax_outputs) | ||
|
|
||
| # Compile the model | ||
| softmax_output_layer_name = self._model.output_names[0] | ||
| losses = {softmax_output_layer_name: "categorical_crossentropy"} | ||
|
|
||
| # use f1 score metric | ||
| f1_score_training = labeler_utils.F1Score( | ||
| num_classes=num_labels, average="micro" | ||
| ) | ||
| metrics = { | ||
| softmax_output_layer_name: [ | ||
| "categorical_crossentropy", | ||
| "acc", | ||
| f1_score_training, | ||
| ] | ||
| } | ||
|
|
||
| self._model.compile(loss=losses, optimizer="adam", metrics=metrics) | ||
| self._compile_loss(self._model, num_labels) | ||
| self._epoch_id = 0 | ||
| self._model_num_labels = num_labels | ||
| self._model_default_ind = default_ind | ||
|
|
@@ -699,14 +688,11 @@ def fit( | |
| f1_report: dict = {} | ||
|
|
||
| self._model.reset_metrics() | ||
| softmax_output_layer_name = self._model.output_names[0] | ||
|
|
||
| start_time = time.time() | ||
| batch_id = 0 | ||
| for x_train, y_train in train_data: | ||
| model_results = self._model.train_on_batch( | ||
| x_train, {softmax_output_layer_name: y_train} | ||
| ) | ||
| model_results = self._model.train_on_batch(x_train, y_train) | ||
| sys.stdout.flush() | ||
| if verbose: | ||
| sys.stdout.write( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| """Contains function for generating plugins data.""" | ||
|
|
||
| from collections import defaultdict | ||
| from typing import Any, DefaultDict, Dict | ||
|
|
||
|
|
@@ -21,7 +22,6 @@ def __inner_factory_function(fn): | |
| :param fn: Plugin function | ||
| :return: function | ||
| """ | ||
| global plugins_dict | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. global is only needed when a function rebinds a module variable, like plugins_dict = {...}. |
||
| plugins_dict[typ][name] = fn | ||
| return fn | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,5 @@ | ||
| scikit-learn>=0.23.2 | ||
| keras<=3.4.0 | ||
| keras>=3.11.0 | ||
| rapidfuzz>=2.6.1 | ||
| tensorflow>=2.16.0; sys.platform != 'darwin' | ||
| tensorflow>=2.16.0; sys_platform == 'darwin' and platform_machine != 'arm64' | ||
| tensorflow-macos>=2.16.0; sys_platform == 'darwin' and platform_machine == 'arm64' | ||
| tensorflow>=2.16.0 | ||
| tqdm>=4.0.0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,4 +6,4 @@ pytest-cov>=2.8.1 | |
| pytest-xdist>=2.1.0 | ||
| pytest-forked>=1.3.0 | ||
| toolz>=0.10.0 | ||
| memray>=1.7.0,<1.12.0 | ||
| memray>=1.18.0 | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove