From 08709883fe955b0669441d57306bb8ca6fc655df Mon Sep 17 00:00:00 2001 From: Cameron Toy Date: Thu, 28 May 2020 01:04:13 -0700 Subject: [PATCH 1/3] hacky support for hardcoded answers --- nimbus_nlp/models/classification/keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 nimbus_nlp/models/classification/keep diff --git a/nimbus_nlp/models/classification/keep b/nimbus_nlp/models/classification/keep deleted file mode 100644 index e69de29..0000000 From 9950d227442b0e75e011d84ffc9c879352899d6a Mon Sep 17 00:00:00 2001 From: Cameron Toy Date: Thu, 28 May 2020 01:05:55 -0700 Subject: [PATCH 2/3] hacky support for hard coded questions --- QA.py | 7 +++++++ nimbus.py | 9 +++++++-- nimbus_nlp/models/features/overall_features.json | 2 +- nimbus_nlp/variable_extractor.py | 3 ++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/QA.py b/QA.py index 3a00650..a0285d3 100644 --- a/QA.py +++ b/QA.py @@ -49,6 +49,8 @@ def __init__(self, q_format, db_query, format_answer, db): self.format_answer = format_answer def answer(self, extracted_vars): + if self.db_query is None: + return self.format_answer({"normalized entity": ""}, dict()) db_data = self.db_query(extracted_vars, self.db) answer = self.format_answer(extracted_vars, db_data) return answer @@ -239,6 +241,8 @@ def _chain_db_access( # Actually returns partial[Dict[str, Any]] def chain_db_access(fns: List[DB_Query]) -> DB_Query: + if fns is None: + return None return functools.partial(_chain_db_access, fns) @@ -287,6 +291,9 @@ def generate_qa_pairs(qa_pairs: Tuple[str, str], db: NimbusMySQLAlchemy): db_access_fns.append(get_property_list(prop, joiner, table)) tokens[i] = "{db_" + prop + "}" + if not db_access_fns: + db_access_fns = None + o = QA( q_format=q, db_query=chain_db_access(db_access_fns), diff --git a/nimbus.py b/nimbus.py index 70e8b28..f78d9d5 100644 --- a/nimbus.py +++ b/nimbus.py @@ -28,12 +28,14 @@ def __init__(self, db: NimbusMySQLAlchemy): self.classifier.train_model() self.classifier.load_latest_classifier() - def answer_question(self, question): ans_dict = self.predict_question(question) print(ans_dict) try: - qa = self.qa_dict[ans_dict["question class"]] + if ans_dict is None: + qa = self.qa_dict[self.classifier.classify_question(question)] + else: + qa = self.qa_dict[ans_dict["question class"]] except KeyError: # Printed if question isn't found. This occurs because the training set is broader # than the answerable question set. @@ -64,6 +66,9 @@ def predict_question(self, question): # Get dictionary of extracted variables + info from question nlp_props = self.variable_extractor.extract_variables(question) + if nlp_props is None: + return None + # Add classified question to nlp_props dictionary nlp_props["question class"] = self.classifier.classify_question( nlp_props["normalized question"] diff --git a/nimbus_nlp/models/features/overall_features.json b/nimbus_nlp/models/features/overall_features.json index c5de3a3..f9b4934 100644 --- a/nimbus_nlp/models/features/overall_features.json +++ b/nimbus_nlp/models/features/overall_features.json @@ -1 +1 @@ -{"prereqs": 0, "COURSE": 0, "be": 0, "course": 0, "require": 0, "take": 0, "unit": 0, "count": 0, "typically": 0, "offer": 0, "quarter": 0, "go": 0, "4": 0, "class": 0, "term": 0, "prerequisite": 0, "have": 0, "recommend": 0, "need": 0, "order": 0, "topic": 0, "cover": 0, "title": 0, "call": 0, "code": 0, "time": 0, "year": 0, "available": 0, "fulfill": 0, "preq": 0, "soon": 0, "description": 0, "learn": 0, "credit": 0, "worth": 0, "number": 0, "corequisite": 0, "concurrent": 0, "enrollement": 0, "list": 0, "lab": 0, "PROF": 0, "office": 0, "hour": 0, "right": 0, "later": 0, "today": 0, "tomorrow": 0, "email": 0, "phone": 0, "contact": 0, "information": 0, "reach": 0, "room": 0, "in": 0, "address": 0, "visit": 0, "host": 0, "job": 0, "lecturer": 0, "professor": 0, "position": 0, "Cal": 0, "Poly": 0, "'s": 0, "place": 0, "find": 0, "campus": 0, "building": 0, "day": 0, "CLUB": 0, "club": 0, "box": 0, "college": 0, "affiliate": 0, "President": 0, "Advisor": 0, "do": 0, "brief": 0, "overview": 0, "give": 0, "chief": 0, "touch": 0, "get": 0, "general": 0, "adviser": 0, "usually": 0, "currently": 0, "advisor": 0, "teaching": 0, "week": 0, "platform": 0, "virtual": 0, "zoom": 0, "vroom": 0, "Zoom": 0, "Skype": 0, "see": 0, "section": 0, "teach": 0, "type": 0, "department": 0, "found": 0, "tell": 0, "student": 0, "attend": 0, "faculty": 0, "ratio": 0, "big": 0, "acre": 0, "program": 0, "bacherlor": 0, "degree": 0, "master": 0, "minor": 0, "credential": 0, "make": 0, "create": 0, "help": 0, "ask": 0, "kind": 0, "question": 0, "69": 0, "not related": 0} \ No newline at end of file +{"prereqs": 0, "COURSE": 0, "be": 0, "course": 0, "require": 0, "take": 0, "unit": 0, "count": 0, "typically": 0, "offer": 0, "quarter": 0, "go": 0, "4": 0, "class": 0, "term": 0, "prerequisite": 0, "have": 0, "recommend": 0, "need": 0, "order": 0, "topic": 0, "cover": 0, "title": 0, "call": 0, "code": 0, "time": 0, "year": 0, "available": 0, "fulfill": 0, "preq": 0, "soon": 0, "description": 0, "learn": 0, "credit": 0, "worth": 0, "number": 0, "corequisite": 0, "concurrent": 0, "enrollement": 0, "list": 0, "lab": 0, "PROF": 0, "office": 0, "hour": 0, "right": 0, "later": 0, "today": 0, "tomorrow": 0, "email": 0, "phone": 0, "contact": 0, "information": 0, "reach": 0, "room": 0, "in": 0, "address": 0, "visit": 0, "host": 0, "job": 0, "lecturer": 0, "professor": 0, "position": 0, "Cal": 0, "Poly": 0, "'s": 0, "place": 0, "find": 0, "campus": 0, "building": 0, "day": 0, "CLUB": 0, "club": 0, "box": 0, "college": 0, "affiliate": 0, "President": 0, "Advisor": 0, "do": 0, "brief": 0, "overview": 0, "give": 0, "chief": 0, "touch": 0, "get": 0, "general": 0, "adviser": 0, "usually": 0, "currently": 0, "advisor": 0, "teaching": 0, "week": 0, "platform": 0, "virtual": 0, "zoom": 0, "vroom": 0, "Zoom": 0, "Skype": 0, "see": 0, "section": 0, "teach": 0, "type": 0, "department": 0, "found": 0, "tell": 0, "student": 0, "attend": 0, "faculty": 0, "ratio": 0, "big": 0, "acre": 0, "program": 0, "bacherlor": 0, "degree": 0, "master": 0, "minor": 0, "credential": 0, "make": 0, "create": 0, "help": 0, "ask": 0, "kind": 0, "question": 0, "not related": 0} \ No newline at end of file diff --git a/nimbus_nlp/variable_extractor.py b/nimbus_nlp/variable_extractor.py index ad7fa55..caf8ddb 100644 --- a/nimbus_nlp/variable_extractor.py +++ b/nimbus_nlp/variable_extractor.py @@ -70,7 +70,8 @@ def extract_variables(self, sent): # Make the prediction request = self.get_prediction(sent) - + if not request.payload: + return None # Obtain the entity in the sentence entity = request.payload[0].text_extraction.text_segment.content From 351bd9a22d23187f3b9931752c59d036b2bb6b3a Mon Sep 17 00:00:00 2001 From: Michael Fekadu Date: Thu, 28 May 2020 08:08:45 -0700 Subject: [PATCH 3/3] Update .gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 8c1f3ca..f2ea737 100644 --- a/.gitignore +++ b/.gitignore @@ -125,4 +125,5 @@ settings.yaml nimbus_api.iml # models -*pkl \ No newline at end of file +*pkl +id_rsa