Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dream emotion dist #568

Merged
merged 35 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
73aa87d
add dream_emotion dist with annotators
asleepann Aug 29, 2023
9dfd0fc
add component cards
asleepann Aug 29, 2023
e4ed51a
fix codestyle flake8
asleepann Aug 30, 2023
f98bcb4
fix codestyle
asleepann Aug 31, 2023
3d72d70
another codestyle fix
asleepann Aug 31, 2023
6fdbd3f
PR fixes
asleepann Sep 1, 2023
29181b0
fixed batches
asleepann Sep 4, 2023
c62e0c3
move preprocessing to annotator
asleepann Sep 4, 2023
2fda668
fix codestyle black
asleepann Sep 12, 2023
27a541a
minor fixes
asleepann Sep 18, 2023
597e363
removed unnecessary api_configs
asleepann Sep 18, 2023
c6a8c80
changed type of annotator to bot utts annotator
asleepann Sep 18, 2023
bd0f171
fixed component file
asleepann Sep 18, 2023
f6bd772
fixed service.yml files
asleepann Sep 29, 2023
9a1d533
fixed formatters
asleepann Sep 29, 2023
aeb452d
fixed emotional response server and dist files
asleepann Oct 19, 2023
0c007a5
moved prompt into separate file
asleepann Oct 19, 2023
6398d01
fixed annotators
asleepann Nov 2, 2023
24ad18a
fixed annotators again
asleepann Nov 2, 2023
67e07ec
fixed emotion response selector
asleepann Nov 2, 2023
84f3392
fixed emotion dist and components
asleepann Nov 2, 2023
32e2da9
fixed codestyle
asleepann Nov 2, 2023
e476b67
fixed codestyle again
asleepann Nov 2, 2023
1377bcd
fixed codestyle black
asleepann Nov 2, 2023
4355635
fixed naming of emotion response selector
asleepann Nov 11, 2023
3c230ed
fixed emotional_bot_response component
asleepann Nov 11, 2023
2c261fa
fixed emotion response selector server
asleepann Nov 11, 2023
94bdbbb
added prev_services in annotator in pipeline_conf
asleepann Nov 14, 2023
bf945da
fixed result formatting of bot_emo_cls
asleepann Nov 14, 2023
64c5078
fixed codestyle
asleepann Nov 14, 2023
3995623
fixed codestyle again
asleepann Nov 14, 2023
767a45f
changed description of emo_bot_response
asleepann Nov 14, 2023
44dcd4f
added necessary component cards
asleepann Nov 14, 2023
05cf5ba
fix: timeout
dilyararimovna Nov 16, 2023
094a837
fix: timeout
dilyararimovna Nov 16, 2023
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
17 changes: 17 additions & 0 deletions annotators/bot_emotion_classifier/Dockerfile
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 annotators/bot_emotion_classifier/dscript_scheme_classifier.py
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 annotators/bot_emotion_classifier/info_files/neg_reactions.txt
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 annotators/bot_emotion_classifier/info_files/pos_reactions.txt
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
14 changes: 14 additions & 0 deletions annotators/bot_emotion_classifier/requirements.txt
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
Loading
Loading