From 5378be9418cc5c31ef2cd93295dec779b267ec54 Mon Sep 17 00:00:00 2001 From: Sam Sloniker Date: Fri, 20 May 2022 17:16:00 -0700 Subject: [PATCH] Format code --- gptc/__main__.py | 10 ++++++++-- gptc/classifier.py | 7 +++++-- gptc/compiler.py | 12 +++++++++--- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/gptc/__main__.py b/gptc/__main__.py index caf1fed..d9627b5 100644 --- a/gptc/__main__.py +++ b/gptc/__main__.py @@ -9,10 +9,16 @@ import gptc parser = argparse.ArgumentParser(description="General Purpose Text Classifier") parser.add_argument("model", help="model to use") parser.add_argument( - "-c", "--compile", help="compile raw model model to outfile", metavar="outfile" + "-c", + "--compile", + help="compile raw model model to outfile", + metavar="outfile", ) parser.add_argument( - "-j", "--confidence", help="output confidence dict in json", action="store_true" + "-j", + "--confidence", + help="output confidence dict in json", + action="store_true", ) args = parser.parse_args() diff --git a/gptc/classifier.py b/gptc/classifier.py index 4929b0c..5be02a9 100755 --- a/gptc/classifier.py +++ b/gptc/classifier.py @@ -21,7 +21,9 @@ class Classifier: def __init__(self, model): if model.get("__version__", 0) != 3: - raise gptc.exceptions.UnsupportedModelError(f"unsupported model version") + raise gptc.exceptions.UnsupportedModelError( + f"unsupported model version" + ) self.model = model def confidence(self, text): @@ -57,7 +59,8 @@ class Classifier: except KeyError: pass probs = { - model["__names__"][category]: value for category, value in probs.items() + model["__names__"][category]: value + for category, value in probs.items() } total = sum(probs.values()) probs = {category: value / total for category, value in probs.items()} diff --git a/gptc/compiler.py b/gptc/compiler.py index 83f6b99..f0b63d6 100755 --- a/gptc/compiler.py +++ b/gptc/compiler.py @@ -39,9 +39,13 @@ def compile(raw_model): categories_by_count[category] = {} for word in text: try: - categories_by_count[category][word] += 1 / len(categories[category]) + categories_by_count[category][word] += 1 / len( + categories[category] + ) except KeyError: - categories_by_count[category][word] = 1 / len(categories[category]) + categories_by_count[category][word] = 1 / len( + categories[category] + ) word_weights = {} for category, words in categories_by_count.items(): for word, value in words.items(): @@ -55,7 +59,9 @@ def compile(raw_model): total = sum(weights.values()) model[word] = [] for category in names: - model[word].append(round((weights.get(category, 0) / total) * 65535)) + model[word].append( + round((weights.get(category, 0) / total) * 65535) + ) model["__names__"] = names