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(),