-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add dream_emotion dist with annotators * add component cards * fix codestyle flake8 * fix codestyle * another codestyle fix * PR fixes * fixed batches * move preprocessing to annotator * fix codestyle black * minor fixes * removed unnecessary api_configs * changed type of annotator to bot utts annotator * fixed component file * fixed service.yml files * fixed formatters * fixed emotional response server and dist files * moved prompt into separate file * fixed annotators * fixed annotators again * fixed emotion response selector * fixed emotion dist and components * fixed codestyle * fixed codestyle again * fixed codestyle black * fixed naming of emotion response selector * fixed emotional_bot_response component * fixed emotion response selector server * added prev_services in annotator in pipeline_conf * fixed result formatting of bot_emo_cls * fixed codestyle * fixed codestyle again * changed description of emo_bot_response * added necessary component cards * fix: timeout * fix: timeout --------- Co-authored-by: Dilyara Zharikova (Baymurzina) <dilyara.rimovna@gmail.com>
- Loading branch information
1 parent
fd75515
commit f605640
Showing
46 changed files
with
3,010 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
FROM python:3.9.16 | ||
WORKDIR /src | ||
|
||
COPY annotators/bot_emotion_classifier/requirements.txt ./requirements.txt | ||
RUN pip install -r requirements.txt | ||
|
||
ARG SERVICE_PORT | ||
ENV SERVICE_PORT=$SERVICE_PORT | ||
|
||
COPY annotators/bot_emotion_classifier/ ./ | ||
COPY common /src/common | ||
RUN python -c 'import stanza; stanza.download("en")' | ||
|
||
# wait for a server answer ( INTERVAL + TIMEOUT ) * RETRIES seconds after that change status to unhealthy | ||
HEALTHCHECK --interval=5s --timeout=5s --retries=3 CMD curl --fail 127.0.0.1:${SERVICE_PORT}/healthcheck || exit 1 | ||
|
||
CMD gunicorn --workers=1 server:app -b 0.0.0.0:${SERVICE_PORT} --timeout=600 |
139 changes: 139 additions & 0 deletions
139
annotators/bot_emotion_classifier/dscript_scheme_classifier.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import stanza | ||
|
||
stanza.download("en") | ||
nlp = stanza.Pipeline("en") | ||
|
||
|
||
pos_type_expl = { | ||
"i - someone": 1, | ||
"you - someone": 2, | ||
"i - you": 3, | ||
"you - you": 3, | ||
"i - i": 4, | ||
"you - i": 5, | ||
"we - someone": 6, | ||
"someone - someone": 6, | ||
"we - we": 7, | ||
} | ||
|
||
neg_type_expl = { | ||
"i - you": 1, | ||
"i - someone": 2, | ||
"we - someone": 3, | ||
"you - someone": 3, | ||
"you - i": 4, | ||
"i - i": 5, | ||
"we - we": 5, | ||
} | ||
|
||
first_prons = ["i", "me", "myself"] | ||
second_prons = ["you"] | ||
inclusive_prons = ["we"] | ||
|
||
|
||
def find_root(sent): | ||
for token in sent: | ||
if token["deprel"] == "root": | ||
return token | ||
|
||
|
||
def find_clause_head(root, sent): | ||
clauses = ["ccomp", "xcomp", "acl", "acl:relcl", "advcl"] | ||
all_clause_heads = [] | ||
head_id = root["id"] | ||
for token in sent: | ||
if token["head"] == head_id and token["deprel"] in clauses: | ||
all_clause_heads.append(token) | ||
return all_clause_heads | ||
|
||
|
||
def find_arguments(head, sent): | ||
objects = ["obl", "obj", "iobj"] | ||
head_id = head["id"] | ||
subj = "" | ||
obj = "" | ||
for token in sent: | ||
if token["head"] == head_id and "subj" in token["deprel"]: | ||
subj = token | ||
elif token["head"] == head_id and token["deprel"] in objects: | ||
obj = token | ||
return subj, obj | ||
|
||
|
||
def reverse_if_not_verb(root, subj, obj, has_clauses): | ||
not_verbs = ["NOUN", "ADJ", "ADV"] | ||
if has_clauses: | ||
return subj, obj | ||
if root["upos"] in not_verbs: | ||
obj = subj | ||
subj = "I" | ||
return subj, obj | ||
|
||
|
||
def find_final_arguments(sent): | ||
root = find_root(sent) | ||
subj, obj = find_arguments(root, sent) | ||
next_clause_heads = find_clause_head(root, sent) | ||
has_clauses = False | ||
if next_clause_heads: | ||
has_clauses = True | ||
queue = next_clause_heads | ||
|
||
if subj and not obj: | ||
dep_subj, dep_obj = "", "" | ||
while not dep_subj and not dep_obj and queue: | ||
root = queue[0] | ||
queue = queue[1:] | ||
dep_subj, dep_obj = find_arguments(root, sent) | ||
next_clause_heads = find_clause_head(root, sent) | ||
queue.extend(next_clause_heads) | ||
if dep_subj: | ||
obj = dep_subj | ||
else: | ||
obj = {"text": "someone"} | ||
return reverse_if_not_verb(root, subj["text"], obj["text"], has_clauses) | ||
|
||
while not subj and not obj and queue: | ||
root = queue[0] | ||
queue = queue[1:] | ||
subj, obj = find_arguments(root, sent) | ||
next_clause_heads = find_clause_head(root, sent) | ||
queue.extend(next_clause_heads) | ||
|
||
if obj and not subj: | ||
if "Mood=Imp" in root["feats"]: | ||
subj = {"text": "you"} | ||
else: | ||
subj = {"text": "someone"} | ||
return reverse_if_not_verb(root, subj["text"], obj["text"], has_clauses) | ||
elif not subj and not obj: | ||
subj = {"text": "someone"} | ||
obj = {"text": "someone"} | ||
return reverse_if_not_verb(root, subj["text"], obj["text"], has_clauses) | ||
elif subj and obj: | ||
return subj["text"], obj["text"] | ||
else: | ||
obj = {"text": "someone"} | ||
return subj["text"], obj["text"] | ||
|
||
|
||
def get_dsript_type(orig_sent, type_expl): | ||
doc = nlp(orig_sent) | ||
sent = doc.sentences[0].to_dict() | ||
subj, obj = find_final_arguments(sent) | ||
subj = subj.lower() | ||
obj = obj.lower() | ||
if subj not in first_prons and subj not in second_prons and subj not in inclusive_prons: | ||
subj = "someone" | ||
if obj not in first_prons and obj not in second_prons and obj not in inclusive_prons: | ||
obj = "someone" | ||
if subj in first_prons: | ||
subj = "i" | ||
if obj in first_prons: | ||
obj = "i" | ||
line = subj + " - " + obj | ||
if line not in type_expl: | ||
type_num = 3 | ||
else: | ||
type_num = type_expl[line] | ||
return type_num |
49 changes: 49 additions & 0 deletions
49
annotators/bot_emotion_classifier/info_files/neg_reactions.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
anger shame | ||
resentment distress | ||
disappointment shame | ||
disgust distress | ||
shame shame | ||
distress shame | ||
fear shame | ||
sadness shame | ||
surprise shame | ||
|
||
anger pity | ||
resentment pity | ||
disappointment pity | ||
disgust neutral | ||
shame pity | ||
distress pity | ||
fear fear | ||
sadness pity | ||
surprise pity | ||
|
||
anger anger | ||
resentment resentment | ||
disappointment disappointment | ||
disgust disgust | ||
shame shame | ||
distress distress | ||
fear fear | ||
sadness sadness | ||
surprise distress | ||
|
||
anger resentment | ||
resentment resentment | ||
disappointment distress | ||
disgust resentment | ||
shame resentment | ||
distress distress | ||
fear fear | ||
sadness resentment | ||
surprise distress | ||
|
||
anger pity | ||
resentment pity | ||
disappointment pity | ||
disgust pity | ||
shame pity | ||
distress pity | ||
fear pity | ||
sadness pity | ||
surprise pity |
69 changes: 69 additions & 0 deletions
69
annotators/bot_emotion_classifier/info_files/pos_reactions.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
admiration admiration | ||
joy joy | ||
liking liking | ||
love admiration | ||
hope hope | ||
gratitude admiration | ||
pride admiration | ||
relief relief | ||
surprise joy | ||
|
||
admiration admiration | ||
joy joy | ||
liking liking | ||
love love | ||
hope hope | ||
gratitude gratitude | ||
pride pride | ||
relief relief | ||
surprise joy | ||
|
||
admiration gratitude | ||
joy joy | ||
liking gratitude | ||
love love | ||
hope gratitude | ||
gratitude joy | ||
pride gratitude | ||
relief joy | ||
surprise joy | ||
|
||
admiration admiration | ||
joy joy | ||
liking admiration | ||
love admiration | ||
hope hope | ||
gratitude joy | ||
pride admiration | ||
relief joy | ||
surprise joy | ||
|
||
admiration admiration | ||
joy joy | ||
liking liking | ||
love love | ||
hope hope | ||
gratitude gratitude | ||
pride pride | ||
relief relief | ||
surprise joy | ||
|
||
admiration admiration | ||
joy joy | ||
liking liking | ||
love love | ||
hope hope | ||
gratitude gratitude | ||
pride pride | ||
relief relief | ||
surprise joy | ||
|
||
admiration admiration | ||
joy joy | ||
liking admiration | ||
love admiration | ||
hope hope | ||
gratitude gratitude | ||
pride pride | ||
relief relief | ||
surprise joy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
attrdict==2.0.1 | ||
flask==1.1.1 | ||
gunicorn==19.9.0 | ||
requests==2.22.0 | ||
numpy==1.17.2 | ||
sentry-sdk[flask]==0.14.1 | ||
stanza==1.2.2 | ||
six==1.16.0 | ||
itsdangerous==2.0.1 | ||
uvicorn==0.13.0 | ||
healthcheck==1.3.3 | ||
requests==2.22.0 | ||
jinja2<=3.0.3 | ||
Werkzeug==2.0.3 |
Oops, something went wrong.