def __init__(self, config): labeled_demos = [ LabeledDemonstration.from_oracle_programs( [[ WeightedProgram( ClickToken(LikeToken(FieldsValueSelectorToken(1))), 1) ], [ WeightedProgram( ClickToken(LikeToken(StringToken(u"Forward"))), 1) ], [ WeightedProgram( FocusAndTypeToken(InputElementsToken(), FieldsValueSelectorToken(0)), 1) ], [WeightedProgram(ClickToken(LikeToken(StringToken(u""))), 1)] ], # TODO: Remove this hack "Find the email by Harmonia and forward that email to Eleanore.", Fields({ "by": "Harmonia", "to": "Eleanore" })) ] super(EmailInboxForwardOracleProgramPolicy, self).__init__(labeled_demos, config)
def __init__(self, config): labeled_demos = [ LabeledDemonstration.from_oracle_programs( [[ WeightedProgram( ClickToken(LikeToken(FieldsValueSelectorToken(1))), 1) ], [ WeightedProgram( ClickToken(LikeToken(StringToken(u"Reply"))), 1) ], [ WeightedProgram( FocusAndTypeToken(InputElementsToken(), FieldsValueSelectorToken(0)), 1) ], [WeightedProgram(ClickToken(LikeToken(StringToken(u""))), 1)] ], # TODO: Remove this hack "Find the email by Harmonia and reply to them with the text \"hello\".", Fields({ "by": "Harmonia", "message": "hello" })) ] super(EmailInboxReplyOracleProgramPolicy, self).__init__(labeled_demos, config)
def __init__(self, config): labeled_demos = [ LabeledDemonstration.from_oracle_programs([ [ WeightedProgram( FocusAndTypeToken( NearToken(LikeToken(StringToken(u"Username"))), UtteranceSelectorToken(4, 5)), 1) ], [ WeightedProgram( FocusAndTypeToken( NearToken(LikeToken(StringToken(u"Password"))), UtteranceSelectorToken(10, 11)), 1) ], [ WeightedProgram( ClickToken(LikeToken(StringToken(u"Login"))), 1) ] ], "Enter the username \"blah\" and the password \"blah\" into the text fields and press login.", Fields({ "username": "******", "password": "******" })) ] super(LoginUserOracleProgramPolicy, self).__init__(labeled_demos, config)
def __init__(self, config): # Appears on first page labeled_demos = [ LabeledDemonstration.from_oracle_programs([[ WeightedProgram( ClickToken(LikeToken(UtteranceSelectorToken(12, 13))), 1) ]], "Switch between the tabs to find and click on the link \"x\".", Fields({"target": "x"})) ] # Appears in other tabs labeled_demos += [ LabeledDemonstration.from_oracle_programs( [[ WeightedProgram( ClickToken(LikeToken(StringToken(u"Tab #2"))), 1) ], [ WeightedProgram( ClickToken(LikeToken(UtteranceSelectorToken(12, 13))), 1) ]], "Switch between the tabs to find and click on the link \"x\".", Fields({"target": "x"})) ] labeled_demos += [ LabeledDemonstration.from_oracle_programs( [[ WeightedProgram( ClickToken(LikeToken(StringToken(u"Tab #2"))), 1) ], [ WeightedProgram( ClickToken(LikeToken(StringToken(u"Tab #3"))), 1) ], [ WeightedProgram( ClickToken(LikeToken(UtteranceSelectorToken(12, 13))), 1) ]], "Switch between the tabs to find and click on the link \"x\".", Fields({"target": "x"})) ] super(ClickTab2OracleProgramPolicy, self).__init__(labeled_demos, config)
def __init__(self, config): submit = lambda: [ WeightedProgram(ClickToken(LikeToken(StringToken(u"Submit"))), 1) ] check_field = lambda i: [ WeightedProgram( ClickToken(SameRowToken(LikeToken(FieldsValueSelectorToken(i))) ), 1) ] def demo(num_boxes, randomize_order): programs_sequence = [check_field(i + 1) for i in range(num_boxes)] if randomize_order: random.shuffle(programs_sequence) programs_sequence.append(submit()) utt, fields = { 0: ("Click nothing then submit", Fields({"button": "submit"})), 1: ("Click a then submit", Fields({ "target 0": "a", "button": "submit" })), 2: ("Click a,b then submit", Fields({ "target 0": "a", "target 1": "b", "button": "submit" })), 3: ("Click a,b,c then submit", Fields({ "target 0": "a", "target 1": "b", "target 2": "c", "button": "submit" })), 4: ("Click a,b,c,d then submit", Fields({ "target 0": "a", "target 1": "b", "target 2": "c", "target 3": "d", "button": "submit" })), 5: ("Click a,b,c,d,e then submit", Fields({ "target 0": "a", "target 1": "b", "target 2": "c", "target 3": "d", "target 4": "e", "button": "submit" })), 6: ("Click a,b,c,d,e,f then submit", Fields({ "target 0": "a", "target 1": "b", "target 2": "c", "target 3": "d", "target 4": "e", "target 5": "f", "button": "submit" })), }[num_boxes] return LabeledDemonstration.from_oracle_programs( programs_sequence, utt, fields) # randomize = True # num_samples = 100 randomize = False num_samples = 1 labeled_demos = [] for i in range(7): demos_for_i = [demo(i, randomize) for _ in range(num_samples)] labeled_demos.extend(demos_for_i) super(ClickCheckboxesOracle, self).__init__(labeled_demos, config)
def __init__(self, config): labeled_demos = [ # block LabeledDemonstration.from_oracle_programs( [ # More [ WeightedProgram( ClickToken( NearToken(LikeToken( FieldsValueSelectorToken(1)), classes="more")), 1) ], # Block [ WeightedProgram( ClickToken(LikeToken(StringToken(u"Block"))), 1) ] ], "For the user @jess, click on the \"Block\" button.", Fields({ "user": "******", "button": "block" })), # reply LabeledDemonstration.from_oracle_programs( [ # reply [ WeightedProgram( ClickToken( NearToken(LikeToken( FieldsValueSelectorToken(1)), classes="reply")), 1) ], ], "For the user @jess, click on the \"Reply\" button.", Fields({ "user": "******", "button": "reply" })), # like LabeledDemonstration.from_oracle_programs( [ # like [ WeightedProgram( ClickToken( NearToken(LikeToken( FieldsValueSelectorToken(1)), classes="like")), 1) ], ], "For the user @jess, click on the \"Like\" button.", Fields({ "user": "******", "button": "like" })), # share via DM LabeledDemonstration.from_oracle_programs( [ # More [ WeightedProgram( ClickToken( NearToken(LikeToken( FieldsValueSelectorToken(1)), classes="more")), 1) ], # share [ WeightedProgram( ClickToken(LikeToken(StringToken(u"share"))), 1) ] ], "For the user @jess, click on the \"share\" button.", Fields({ "user": "******", "button": "share" })), # copy LabeledDemonstration.from_oracle_programs( [ # More [ WeightedProgram( ClickToken( NearToken(LikeToken( FieldsValueSelectorToken(1)), classes="more")), 1) ], # copy [ WeightedProgram( ClickToken(LikeToken(StringToken(u"copy"))), 1) ] ], "For the user @jess, click on the \"Copy\" button.", Fields({ "user": "******", "button": "copy" })), # embed LabeledDemonstration.from_oracle_programs( [ # More [ WeightedProgram( ClickToken( NearToken(LikeToken( FieldsValueSelectorToken(1)), classes="more")), 1) ], # embed [ WeightedProgram( ClickToken(LikeToken(StringToken(u"embed"))), 1) ] ], "For the user @jess, click on the \"Embed\" button.", Fields({ "user": "******", "button": "embed" })), # mute LabeledDemonstration.from_oracle_programs( [ # More [ WeightedProgram( ClickToken( NearToken(LikeToken( FieldsValueSelectorToken(1)), classes="more")), 1) ], # mute [ WeightedProgram( ClickToken(LikeToken(StringToken(u"mute"))), 1) ] ], "For the user @jess, click on the \"Mute\" button.", Fields({ "user": "******", "button": "mute" })), # report LabeledDemonstration.from_oracle_programs( [ # More [ WeightedProgram( ClickToken( NearToken(LikeToken( FieldsValueSelectorToken(1)), classes="more")), 1) ], # embed [ WeightedProgram( ClickToken(LikeToken(StringToken(u"report"))), 1) ] ], "For the user @jess, click on the \"Report\" button.", Fields({ "user": "******", "button": "report" })), # retweet LabeledDemonstration.from_oracle_programs( [ # like [ WeightedProgram( ClickToken( NearToken(LikeToken( FieldsValueSelectorToken(1)), classes="retweet")), 1) ], ], "For the user @jess, click on the \"Retweet\" button.", Fields({ "user": "******", "button": "retweet" })), ] super(SocialMediaOracle, self).__init__(labeled_demos, config)
def __init__(self, config): labeled_demos = [ LabeledDemonstration.from_oracle_programs( [ ####### # forward # Click name of sender [ WeightedProgram( ClickToken(LikeToken(FieldsValueSelectorToken(0))), 1) ], # Forward [ WeightedProgram( ClickToken(LikeToken(StringToken(u"Forward"))), 1) ], # Type name of recipient [ WeightedProgram( FocusAndTypeToken(InputElementsToken(), FieldsValueSelectorToken(2)), 1) ], # Send button [ WeightedProgram( ClickToken(LikeToken(StringToken(u""))), 1) ] ], "Find the email by A and forward that email to B.", Fields({ "by": "A", "task": "forward", "to": "B" })), LabeledDemonstration.from_oracle_programs( [ ####### # reply # Click name of sender [ WeightedProgram( ClickToken(LikeToken(FieldsValueSelectorToken(0))), 1) ], # Reply [ WeightedProgram( ClickToken(LikeToken(StringToken(u"Reply"))), 1) ], # Type message [ WeightedProgram( FocusAndTypeToken(InputElementsToken(), FieldsValueSelectorToken(1)), 1) ], # Send button [ WeightedProgram( ClickToken(LikeToken(StringToken(u""))), 1) ] ], "Find the email by A and reply to them with the text \"B\".", Fields({ "by": "A", "message": "B", "task": "reply" })), LabeledDemonstration.from_oracle_programs( [ ####### # trash # Click name of sender [ WeightedProgram( ClickToken( SameRowToken( LikeToken(FieldsValueSelectorToken(0)))), 1) ], ], "Find the email by A and click the trash icon to delete it.", Fields({ "by": "A", "task": "delete" })), LabeledDemonstration.from_oracle_programs( [ ####### # star # Click name of sender [ WeightedProgram( ClickToken( SameRowToken( LikeToken(FieldsValueSelectorToken(0)))), 1) ], ], ("Find the email by A and click the star " "icon to mark it as important."), Fields({ "by": "A", "task": "star" })), ] super(EmailNoScrollOracle, self).__init__(labeled_demos, config)
def _edges_to_programs(vertex): """Collect ActionEdges originating from the given StateVertex, and list all WeightedPrograms that could execute to the actions in those edges. Args: vertex (StateVertex) Returns: list[WeightedProgram] """ weighted_programs = [] env = ExecutionEnvironment(vertex.state) for action_edge in vertex.action_edges: action = action_edge.action state_incr = action_edge.end - action_edge.start if action is None: weighted_programs.append(WeightedProgram(None, 1., state_incr)) continue # All string tokens strings = [StringToken(s) for s in env.valid_strings] # All fields tokens fields = env.fields fields_tokens = [ FieldsValueSelectorToken(i) for i in range(len(fields.keys)) ] strings += fields_tokens # TODO: Support last. Hard because it depends on the actual exec # env. element_sets = [TagToken(tag) for tag in env.tags] # All of the Like element_sets += [ LikeToken(string_token) for string_token in strings ] element_sets += [ ExactMatchToken(string_token) for string_token in strings ] # Max one-level of Near, SameRow, SameCol classes = action.element.classes distance_programs = [ NearToken(elem_token, classes) for elem_token in element_sets ] distance_programs += [ SameRowToken(elem_token, classes) for elem_token in element_sets ] distance_programs += [ SameColToken(elem_token, classes) for elem_token in element_sets ] element_sets += distance_programs click_actions = [ ClickToken(element_token) for element_token in element_sets ] type_actions = [ FocusAndTypeToken(element_token, string_token) for element_token, string_token in itertools.product( element_sets, fields_tokens) ] # Random typing actions type_actions += [ FocusAndRandomFieldTypeToken(element_token) for element_token in element_sets ] if isinstance(action, MiniWoBElementClick): consistent_clicks = [ WeightedProgram(click, 1., state_incr) for click in click_actions if click.consistent(env, action) ] weighted_programs.extend(consistent_clicks) elif isinstance(action, MiniWoBFocusAndType): consistent_types = [ WeightedProgram(type_action, 1., state_incr) for type_action in type_actions if type_action.consistent(env, action) ] weighted_programs.extend(consistent_types) else: raise ValueError("Action: {} not supported.".format(action)) return weighted_programs