def compare_same_duration_ordinal(dataset, narrative, rel_diff=0.1): questions = [ 'Was the <O1> [sound event,sound] [roughly,approximately] as <D> as the <O2> [sound event,sound]?', # noqa: E501 'Was the <O1> and <O2> [sound events,sounds] [roughly,approximately] as <D>?', # noqa: E501 '[Comparing,Listening to,Hearing] the <O1> [sound event,sound] and the <O2> [sound event,sound], were they [roughly,approximately] as <D>?', # noqa: E501 '[Comparing,Listening to,Hearing] the <O1> [sound event,sound] and the <O2> [sound event,sound], did they [roughly,approximately] have the same duration?', # noqa: E501 '[Comparing,Listening to,Hearing] the <O1> and <O2> [sound events,sounds], were they [roughly,approximately] as <D>?', # noqa: E501 '[Comparing,Listening to,Hearing] the <O1> and <O2> [sound events,sounds], did they [roughly,approximately] have the same duration?', # noqa: E501 ] question = str(np.random.choice(questions)) # sample question lst_events = get_lst_events(narrative) number_1, ordinal_1 = sample_number(len(lst_events)) duration = sample_duration() number_2, ordinal_2 = sample_second_number(len(lst_events), number_1) assert number_1 != number_2, 'Question (compare_same_duration_ordinal) illposed.' question = question.replace('<O1>', ordinal_1) # insert ordinal question = question.replace('<D>', duration) # insert duration question = question.replace('<O2>', ordinal_2) # insert ordinal question = sanitize_question(question) # correct grammar lst_duration = get_lst_durations(narrative) e_1_duration = lst_duration[number_1 - 1] e_2_duration = lst_duration[number_2 - 1] rel_duration_diff = compute_rel_diff(np.array(e_1_duration), np.array(e_2_duration)) # Assert a good margin in relative duration assert np.sum(np.logical_and(rel_duration_diff > rel_diff, rel_duration_diff < (2 * rel_diff))) <= 0, \ 'Question (compare_same_duration_ordinal) illposed.' answer = 'yes' if rel_duration_diff <= rel_diff else 'no' return question, answer
def compare_same_duration_event_ordinal(dataset, narrative, rel_diff=0.1): questions = [ 'Was the <S> <A> [roughly,approximately] as <D> as the <O> [sound event,sound]?', # noqa: E501 '[Comparing,Listening to,Hearing] the <S> <A> and the <O> [sound event,sound], were they [roughly,approximately] as <D>?', # noqa: E501 '[Comparing,Listening to,Hearing] the sound of the <S> <A> and the <O> [sound event,sound], were they [roughly,approximately] as <D>?', # noqa: E501 '[Comparing,Listening to,Hearing] the <S> <A> and the <O> [sound event,sound], did they [roughly,approximately] have the same duration?', # noqa: E501 '[Comparing,Listening to,Hearing] the sound of the <S> <A> and the <O> [sound event,sound], did they [roughly,approximately] have the same duration?', # noqa: E501 'Was the <O> [sound event,sound] [roughly,approximately] as <D> as the <S> <A>?', # noqa: E501 '[Comparing,Listening to,Hearing] the <O> [sound event,sound] and the <S> <A>, were they [roughly,approximately] as <D>?', # noqa: E501 '[Comparing,Listening to,Hearing] the <O> [sound event,sound] and the sound of the <S> <A>, were they [roughly,approximately] as <D>?', # noqa: E501 '[Comparing,Listening to,Hearing] the <O> [sound event,sound] and the <S> <A>, did they [roughly,approximately] have the same duration?', # noqa: E501 '[Comparing,Listening to,Hearing] the <O> [sound event,sound] and the sound of the <S> <A>, did they [roughly,approximately] have the same duration?', # noqa: E501 ] question = str(np.random.choice(questions)) # sample question lst_events = get_lst_events(narrative) unique_lst_events = [e for e in lst_events if lst_events.count(e) == 1] assert len(unique_lst_events) > 0, \ 'Question (compare_same_duration_event_ordinal) illposed.' event = str(np.random.choice(unique_lst_events)) # sample event source = str(np.random.choice(dataset['sources'][event])) action = str(np.random.choice(dataset['actions'][event])) duration = sample_duration() number, ordinal = sample_second_number(len(lst_events), lst_events.index(event) + 1) assert lst_events.count(event) == 1, \ 'Question (compare_same_duration_event_ordinal) illposed.' assert lst_events.index(event) != (number - 1), \ 'Question (compare_same_duration_event_ordinal) illposed.' question = question.replace('<S>', source) # insert source question = question.replace('<A>', action) # insert action question = question.replace('<D>', duration) # insert duration question = question.replace('<O>', ordinal) # insert ordinal question = sanitize_question(question) # correct grammar lst_duration = get_lst_durations(narrative) e_1_duration = lst_duration[lst_events.index(event)] e_2_duration = lst_duration[number - 1] rel_duration_diff = compute_rel_diff(np.array(e_1_duration), np.array(e_2_duration)) # Assert a good margin in relative duration assert np.sum(np.logical_and(rel_duration_diff > rel_diff, rel_duration_diff < (2 * rel_diff))) <= 0, \ 'Question (compare_same_duration_event_ordinal) illposed.' answer = 'yes' if rel_duration_diff <= rel_diff else 'no' return question, answer
def compare_duration_ordinal_event(dataset, narrative, rel_diff=0.1): questions = [ 'Was the <O> [sound event,sound] <RD> than the <S> <A>?', 'Was the <O> [sound event,sound] <RD> than the sound of the <S> <A>?', # noqa: E501 '[Comparing,Listening to,Hearing] the <O> [sound event,sound] and the <S> <A>, was the former <RD>?', # noqa: E501 '[Comparing,Listening to,Hearing] the <S> <A> and the <O> [sound event,sound], was the latter <RD>?', # noqa: E501 ] question = str(np.random.choice(questions)) # sample question lst_events = get_lst_events(narrative) unique_lst_events = [e for e in lst_events if lst_events.count(e) == 1] assert len(unique_lst_events) > 0, \ 'Question (compare_duration_ordinal_event) illposed.' event = str(np.random.choice(unique_lst_events)) # sample event source = str(np.random.choice(dataset['sources'][event])) action = str(np.random.choice(dataset['actions'][event])) rel_duration = sample_rel_duration() number, ordinal = sample_second_number(len(lst_events), lst_events.index(event) + 1) assert lst_events.count(event) == 1, \ 'Question (compare_duration_ordinal_event) illposed.' assert lst_events.index(event) != (number - 1), \ 'Question (compare_duration_ordinal_event) illposed.' question = question.replace('<S>', source) # insert source question = question.replace('<A>', action) # insert action question = question.replace('<RD>', rel_duration) # insert duration question = question.replace('<O>', ordinal) # insert ordinal question = sanitize_question(question) # correct grammar lst_duration = get_lst_durations(narrative) e_1_duration = lst_duration[number - 1] e_2_duration = lst_duration[lst_events.index(event)] # Assert a good margin in relative duration rel_duration_diff = compute_rel_diff(np.array(e_1_duration), np.array(e_2_duration)) assert np.sum(rel_duration_diff < rel_diff) <= 0, \ 'Question (compare_duration_ordinal_event) illposed.' if 'short' in question: answer = 'yes' if e_1_duration < e_2_duration else 'no' elif 'long' in question: answer = 'yes' if e_1_duration > e_2_duration else 'no' else: assert False, \ 'Duration illdefined in Question (compare_duration_ordinal_event).' return question, answer
def compare_ordinal(dataset, narrative, _): questions = [ 'Was the <O1> [sound event,sound] [the same as,similar to] the <O2> [sound event,sound]?', # noqa: E501 'Was the <O1> [sound event,sound] and <O2> [sound event,sound] [the same,similar]?', # noqa: E501 'Were the <O1> and <O2> [sound events,sounds] [the same,similar]?', ] question = str(np.random.choice(questions)) # sample question lst_events = get_lst_events(narrative) number_1, ordinal_1 = sample_number(len(lst_events)) number_2, ordinal_2 = sample_second_number(len(lst_events), number_1) assert number_1 != number_2, 'Question (compare_ordinal) illposed.' question = question.replace('<O1>', ordinal_1) # insert ordinal question = question.replace('<O2>', ordinal_2) # insert ordinal question = sanitize_question(question) # correct grammar answer = 'yes' if lst_events[number_1 - 1] == lst_events[number_2 - 1] \ else 'no' return question, answer
def how_many_event_two_ordinal(dataset, narrative, _): questions = ['How many times did you [hear,listen to] a sound that [sounded,seemed] like the <O1> [sound event,sound] [or,and] the <O2> [sound event,sound]?', # noqa: E501 'What is the number of times did you [hear,listen to] a sound that [sounded,seemed] like the <O1> [sound event,sound] [or,and] the <O2> [sound event,sound]?', # noqa: E501 '[Hearing,Listening to] the <O1> [sound event,sound] and the <O2> [sound event,sound], how many sounds were [the same,similar]?', # noqa: E501 '[Hearing,Listening to] the <O1> [sound event,sound] and the <O2> [sound event,sound], what is the number of sounds that were [the same,similar]?', # noqa: E501 ] question = str(np.random.choice(questions)) # sample question lst_events = get_lst_events(narrative) number_1, ordinal_1 = sample_number(len(lst_events)) number_2, ordinal_2 = sample_second_number(len(lst_events), number_1) question = question.replace('<O1>', ordinal_1) # insert ordinal question = question.replace('<O2>', ordinal_2) # insert ordinal question = sanitize_question(question) # correct grammar event_1 = lst_events[number_1 - 1] event_2 = lst_events[number_2 - 1] answer = numbers_to_words((lst_events.count(event_1) - 1) # -1 for base event + (lst_events.count(event_2) - 1)) return question, answer
def compare_duration_ordinal(dataset, narrative, rel_diff=0.1): questions = [ 'Was the <O1> [sound event,sound] <RD> than the <O2> [sound event,sound]?', # noqa: E501 '[Comparing,Listening to,Hearing] the <O1> [sound event,sound] and the <O2> [sound event,sound], was the former <RD>?', # noqa: E501 '[Comparing,Listening to,Hearing] the <O1> and <O2> [sound events,sounds], was the former <RD>?', # noqa: E501 '[Comparing,Listening to,Hearing] the <O2> [sound event,sound] and the <O1> [sound event,sound], was the latter <RD>?', # noqa: E501 '[Comparing,Listening to,Hearing] the <O2> and <O1> [sound events,sounds], was the latter <RD>?', # noqa: E501 ] question = str(np.random.choice(questions)) # sample question lst_events = get_lst_events(narrative) number_1, ordinal_1 = sample_number(len(lst_events)) rel_duration = sample_rel_duration() number_2, ordinal_2 = sample_second_number(len(lst_events), number_1) assert number_1 != number_2, 'Question (compare_duration_ordinal) illposed.' question = question.replace('<O1>', ordinal_1) # insert ordinal question = question.replace('<RD>', rel_duration) # insert duration question = question.replace('<O2>', ordinal_2) # insert ordinal question = sanitize_question(question) # correct grammar lst_duration = get_lst_durations(narrative) e_1_duration = lst_duration[number_1 - 1] e_2_duration = lst_duration[number_2 - 1] # Assert a good margin in relative duration rel_duration_diff = compute_rel_diff(np.array(e_1_duration), np.array(e_2_duration)) assert np.sum(rel_duration_diff < rel_diff) <= 0, \ 'Question (compare_duration_ordinal) illposed.' if 'short' in question: answer = 'yes' if e_1_duration < e_2_duration else 'no' elif 'long' in question: answer = 'yes' if e_1_duration > e_2_duration else 'no' else: assert False, 'Duration illdefined in Question (compare_duration_ordinal).' return question, answer