From 07be21e8099e6fc5dbaf8e33f441472d14792924 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Fri, 10 Feb 2023 06:21:50 +0100 Subject: [PATCH] idk something more & more --- unimore_bda_6/__main__.py | 4 ++++ unimore_bda_6/analysis/base.py | 7 +++++-- unimore_bda_6/analysis/tf_text.py | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/unimore_bda_6/__main__.py b/unimore_bda_6/__main__.py index 046ac3f..d492b6b 100644 --- a/unimore_bda_6/__main__.py +++ b/unimore_bda_6/__main__.py @@ -65,6 +65,10 @@ def main(): run_counter += 1 slog.debug("Run #%d", run_counter) + if run_counter >= 100: + slog.fatal("Exceeded 100 runs, giving up and exiting...") + exit(2) + try: slog.debug("Instantiating %s with %s...", SentimentAnalyzer.__name__, Tokenizer.__name__) sa = SentimentAnalyzer(tokenizer=Tokenizer()) diff --git a/unimore_bda_6/analysis/base.py b/unimore_bda_6/analysis/base.py index 64dee81..d4d0c19 100644 --- a/unimore_bda_6/analysis/base.py +++ b/unimore_bda_6/analysis/base.py @@ -50,8 +50,11 @@ class BaseSentimentAnalyzer(metaclass=abc.ABCMeta): for review in evaluation_dataset_func(): resulting_category = self.use(review.text) evaluated += 1 - correct += 1 if round(resulting_category) == round(review.category) else 0 - score += 1 - (abs(resulting_category - review.category) / 4) + try: + correct += 1 if round(resulting_category) == round(review.category) else 0 + score += 1 - (abs(resulting_category - review.category) / 4) + except ValueError: + log.warning("Model execution on %s resulted in a NaN value: %s", review, resulting_category) return EvaluationResults(correct=correct, evaluated=evaluated, score=score) diff --git a/unimore_bda_6/analysis/tf_text.py b/unimore_bda_6/analysis/tf_text.py index 1e6066c..351396c 100644 --- a/unimore_bda_6/analysis/tf_text.py +++ b/unimore_bda_6/analysis/tf_text.py @@ -248,7 +248,7 @@ class TensorflowPolarSentimentAnalyzer(TensorflowSentimentAnalyzer): log.debug("Compiling model: %s", model) model.compile( - optimizer=tensorflow.keras.optimizers.Adam(global_clipnorm=1.0), + optimizer=tensorflow.keras.optimizers.Adadelta(global_clipnorm=1.0), loss=tensorflow.keras.losses.MeanSquaredError(), metrics=[ tensorflow.keras.metrics.MeanAbsoluteError(),