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

Form filling is not getting passed, even-through I use the correct code, how did you handle it ? #1

Open
magesh01 opened this issue Apr 19, 2019 · 8 comments

Comments

@magesh01
Copy link

This is the code I used, its very similar to your but still, I am not getting passed in the exercise, could you please help me in explaining to me what went wrong.
`

Define the INIT state

INIT = 0

Define the CHOOSE_COFFEE state

CHOOSE_COFFEE = 1

Define the ORDERED state

ORDERED = 2

Define the policy rules

policy = {
(INIT, "order"): (CHOOSE_COFFEE, "ok, Colombian or Kenyan?"),
(INIT, "none"): (INIT, "I'm sorry - I'm not sure how to help you"),
(CHOOSE_COFFEE, "specify_coffee"): (ORDERED, "perfect, the beans are on their way!"),
(CHOOSE_COFFEE, "none"): (CHOOSE_COFFEE, "I'm sorry - would you like Colombian or Kenyan?"),
}

Create the list of messages

messages = [
"I'd like to become a professional dancer",
"well then I'd like to order some coffee",
"my favourite animal is a zebra",
"kenyan"]

Call send_message() for each message

state = INIT
for message in messages:
state = send_message(policy, state, message)
`

@cjayjonathan
Copy link

Thank you for this. It helped me. I am dropping it once again should anyone need it.

Define the INIT state

INIT = 0

Define the CHOOSE_COFFEE state

CHOOSE_COFFEE = 1

Define the ORDERED state

ORDERED = 2

Define the policy rules

policy = {
(INIT, "order"): (CHOOSE_COFFEE, "ok, Colombian or Kenyan?"),
(INIT, "none"): (INIT, "I'm sorry - I'm not sure how to help you"),
(CHOOSE_COFFEE, "specify_coffee"): (ORDERED, "perfect, the beans are on their way!"),
(CHOOSE_COFFEE, "none"): (CHOOSE_COFFEE, "I'm sorry - would you like Colombian or Kenyan?"),
}

Create the list of messages

messages = [
"I'd like to become a professional dancer",
"well then I'd like to order some coffee",
"my favourite animal is a zebra",
"kenyan"
]

Call send_message() for each message

state = INIT
for message in messages:
state = send_message(policy, state, message)

@cjayjonathan
Copy link

Asking Contextual Questions

Define the states

INIT=0
CHOOSE_COFFEE=1
ORDERED=2

Define the policy rules dictionary

policy_rules = {
(INIT, "ask_explanation"): (INIT, "I'm a bot to help you order coffee beans"),
(INIT, "order"): (CHOOSE_COFFEE, "ok, Colombian or Kenyan?"),
(CHOOSE_COFFEE, "specify_coffee"): (ORDERED, "perfect, the beans are on their way!"),
(CHOOSE_COFFEE, "ask_explanation"): (CHOOSE_COFFEE, "We have two kinds of coffee beans - the Kenyan ones make a slightly sweeter coffee, and cost $6. The Brazilian beans make a nutty coffee and cost $5.")
}

Define send_messages()

def send_messages(messages):
state = INIT
for msg in messages:
state = send_message(state, msg)

Send the messages

send_messages([
"what can you do for me?",
"well then I'd like to order some coffee",
"what do you mean by that?",
"kenyan"
])

@cjayjonathan
Copy link

Handle Negative Feedback

Define respond()

def respond(message, params, prev_suggestions, excluded):
# Interpret the message
parse_data = interpret(message)
# Extract the intent
intent = parse_data["intent"]["name"]
# Extract the entities
entities = parse_data["entities"]
# Add the suggestion to the excluded list if intent is "deny"
if intent == "deny":
excluded.extend(prev_suggestions)
# Fill the dictionary with entities
for ent in entities:
params[ent["entity"]] = str(ent["value"])
# Find matching hotels
results = [
r
for r in find_hotels(params, excluded)
if r[0] not in excluded
]
# Extract the suggestions
names = [r[0] for r in results]
n = min(len(results), 3)
suggestions = names[:2]
return responses[n].format(*names), params, suggestions, excluded

Initialize the empty dictionary and lists

params, suggestions, excluded = {}, [], []

Send the messages

for message in ["I want a mid range hotel", "no that doesn't work for me"]:
print("USER: {}".format(message))
response, params, suggestions, excluded = respond(message, params, suggestions, excluded)
print("BOT: {}".format(response))

@cjayjonathan
Copy link

DataCamp Answers
Pending Actions I

Define policy()

def policy(intent):
# Return "do_pending" if the intent is "affirm"
if intent == "affirm":
return "do_pending", None
# Return "Ok" if the intent is "deny"
if intent == "deny":
return "Ok", None
if intent == "order":
return "Unfortunately, the Kenyan coffee is currently out of stock, would you like to order the Brazilian beans?", "Alright, I've ordered that for you!"

@cjayjonathan
Copy link

Pending Actions II

Define send_message()

def send_message(pending, message):
print("USER : {}".format(message))
action, pending_action = policy(interpret(message))
if action == "do_pending" and pending is not None:
print("BOT : {}".format(pending))
else:
print("BOT : {}".format(action))
return pending_action

Define send_messages()

def send_messages(messages):
pending = None
for msg in messages:
pending = send_message(pending, msg)

Send the messages

send_messages([
"I'd like to order some coffee",
"ok yes please"
])

@cjayjonathan
Copy link

Pending State Transitions DataCamp Answers

Define the states

INIT=0
AUTHED=1
CHOOSE_COFFEE=2
ORDERED=3

Define the policy rules

policy_rules = {
(INIT, "order"): (INIT, "you'll have to log in first, what's your phone number?", AUTHED),
(INIT, "number"): (AUTHED, "perfect, welcome back!", None),
(AUTHED, "order"): (CHOOSE_COFFEE, "would you like Colombian or Kenyan?", None),
(CHOOSE_COFFEE, "specify_coffee"): (ORDERED, "perfect, the beans are on their way!", None)
}

Define send_messages()

def send_messages(messages):
state = INIT
pending = None
for msg in messages:
state, pending = send_message(state, pending, msg)

Send the messages

send_messages([
"I'd like to order some coffee",
"555-1234",
"kenyan"
])

@cjayjonathan
Copy link

Putting it all together

Define chitchat_response()

def chitchat_response(message):
# Call match_rule()
response, phrase = match_rule(eliza_rules, message)
# Return none if response is "default"
if response == "default":
return None
if '{0}' in response:
# Replace the pronouns of phrase
phrase = replace_pronouns(phrase)
# Calculate the response
response = response.format(phrase)
return response

@cjayjonathan
Copy link

Putting It All Together II

Define send_message()

def send_message(state, pending, message):
print("USER : {}".format(message))
response = chitchat_response(message)
if response is not None:
print("BOT : {}".format(response))
return state, None

# Calculate the new_state, response, and pending_state
new_state, response, pending_state = policy_rules[(state, interpret(message))]
print("BOT : {}".format(response))
if pending is not None:
    new_state, response, pending_state = policy_rules[pending]
    print("BOT : {}".format(response))        
if pending_state is not None:
    pending = (pending_state, interpret(message))
return new_state, pending

Define send_messages()

def send_messages(messages):
state = INIT
pending = None
for msg in messages:
state, pending = send_message(state, pending, msg)

Send the messages

send_messages([
"I'd like to order some coffee",
"555-12345",
"do you remember when I ordered 1000 kilos by accident?",
"kenyan"
])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants