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

Feat/ru random questions #131

Merged
merged 8 commits into from
Mar 22, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ def rule_score_based_selection(dialog, candidates, scores, confidences, is_toxic
best_id = np.argmax(curr_single_scores)
best_candidate = candidates[best_id]
best_skill_name = skill_names[int(best_id)]
prev_skill_names = [uttr["skill_name"] for uttr in dialog["bot_utterances"][-5:]]

best_candidate = add_question_to_statement(
best_candidate,
Expand All @@ -341,6 +342,7 @@ def rule_score_based_selection(dialog, candidates, scores, confidences, is_toxic
link_to_question,
link_to_human_attrs,
not_sure_factoid,
prev_skill_names,
)

return best_candidate, best_id, curr_single_scores
Expand Down
28 changes: 21 additions & 7 deletions response_selectors/convers_evaluation_based_selector/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
)

sentry_sdk.init(getenv("SENTRY_DSN"))
LANGUAGE = getenv("LANGUAGE", "EN")

logging.basicConfig(format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.DEBUG)
logger = logging.getLogger(__name__)
Expand All @@ -36,12 +37,20 @@
misheard_with_spec2 = "like to chat about"
alexa_abilities_spec = "If you want to use the requested feature say"

LET_ME_ASK_YOU_PHRASES = [
"Let me ask you something.",
"I would like to ask you a question.",
"Hey, I have a quesiton to you.",
"May I ask you one interesting thing.",
]
LET_ME_ASK_YOU_PHRASES = {
"EN": [
"Let me ask you something.",
"I would like to ask you a question.",
"Hey, I have a quesiton to you.",
"May I ask you one interesting thing.",
],
"RU": [
"Я бы хотела кое-что спросить.",
"О, у меня как раз есть вопрос для обсуждения.",
"Я хочу спросить тебя кое-о-чем интересном.",
"У меня есть кое-что интересное для обсуждения.",
],
}


def join_used_links_in_attributes(main_attrs, add_attrs):
Expand All @@ -63,14 +72,15 @@ def add_question_to_statement(
link_to_question,
link_to_human_attrs,
not_sure_factoid,
prev_skill_names,
):

if not_sure_factoid and "factoid_qa" in best_skill_name:
best_candidate["text"] = "I am not sure in my answer but I can try. " + best_candidate["text"]
if best_candidate["text"].strip() in okay_statements:
if dummy_question != "" and random.random() < ASK_DUMMY_QUESTION_PROB:
logger.info(f"adding {dummy_question} to response.")
best_candidate["text"] += f"{np.random.choice(LET_ME_ASK_YOU_PHRASES)} {dummy_question}"
best_candidate["text"] += f"{np.random.choice(LET_ME_ASK_YOU_PHRASES[LANGUAGE])} {dummy_question}"
# if this is not a link-to question, bot attributes will be still empty
best_candidate["human_attributes"] = join_used_links_in_attributes(
best_candidate.get("human_attributes", {}), dummy_question_human_attr
Expand All @@ -82,6 +92,10 @@ def add_question_to_statement(
best_candidate["human_attributes"] = join_used_links_in_attributes(
best_candidate.get("human_attributes", {}), link_to_human_attrs
)
elif LANGUAGE == "RU" and best_skill_name == "dff_generative_skill":
if prev_skill_names[-3:] == 3 * ["dff_generative_skill"] and random.random() < ASK_DUMMY_QUESTION_PROB:
logger.info(f"adding russian {dummy_question} to dff-generative-skill response.")
best_candidate["text"] += f"{np.random.choice(LET_ME_ASK_YOU_PHRASES[LANGUAGE])} {dummy_question}"

return best_candidate

Expand Down
4 changes: 4 additions & 0 deletions skills/dummy_skill/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@


Russian Random questions are collected from https://mensby.com/women/relations/150-voprosov-chtoby-luchshe-uznat-sobesednika-ili-sobesednicu
and https://habr.com/ru/company/testutor/blog/298180/
8 changes: 8 additions & 0 deletions skills/dummy_skill/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
with open("skills/dummy_skill/nounphrases_facts_map.json", "r") as f:
NP_FACTS = json.load(f)

with open("skills/dummy_skill/russian_random_questions.txt", "r") as f:
RUSSIAN_RANDOM_QUESTIONS = f.readlines()


class RandomTopicResponder:
def __init__(self, filename, topic, text):
Expand Down Expand Up @@ -271,6 +274,11 @@ async def send(self, payload: Dict, callback: Callable):
attrs += [{"type": "link_to_for_response_selector"}]
human_attrs += [human_attr]
bot_attrs += [{}]
elif is_russian:
cands += [random.choice(RUSSIAN_RANDOM_QUESTIONS)]
attrs += [{"type": "link_to_for_response_selector"}]
human_attrs += [{}]
bot_attrs += [{}]

if not is_russian:
facts_same_nps = []
Expand Down
Loading