Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,5 @@ settings.yaml
nimbus_api.iml

# models
*pkl
*pkl
id_rsa
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooo yeah don't want that getting checked in!

7 changes: 7 additions & 0 deletions QA.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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),
Expand Down
9 changes: 7 additions & 2 deletions nimbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"]
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion nimbus_nlp/models/features/overall_features.json
Original file line number Diff line number Diff line change
@@ -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}
{"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}
3 changes: 2 additions & 1 deletion nimbus_nlp/variable_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down