def what_was_loudness(dataset, narrative, rel_diff=0.1): questions = [ 'What was the <AL> sound?', 'What was the <AL> sound you [heard,listened to]?', 'What was the <AL> sound that you [heard,listened to]?', 'What was the <AL> sound that was heard?', ] question = str(np.random.choice(questions)) # sample question loudness = sample_absolute_loudness() question = question.replace('<AL>', loudness) # insert loudness question = sanitize_question(question) # correct grammar lst_events = get_lst_events(narrative) lst_loudness = get_lst_loudness(narrative) if 'loud' in question: est = np.argmax(lst_loudness) elif 'quiet' in question: est = np.argmin(lst_loudness) else: assert False, \ 'Loudness illdefined in Question (what_was_loudness).' # Assert a good margin in relative loudness evt_loudness = lst_loudness[est] x_loudness = [j for i, j in enumerate(lst_loudness) if i != est] rel_loudness_diff = compute_rel_diff(np.array(x_loudness), np.array(evt_loudness)) assert np.sum(rel_loudness_diff < rel_diff) <= 0, \ 'Question (what_was_loudness) illposed.' e = lst_events[est] answer = (str(np.random.choice(dataset['sources'][e])) + ' ' + str(np.random.choice(dataset['actions'][e]))) return question, answer
def compare_same_loudness_ordinal(dataset, narrative, rel_diff=0.1): questions = [ 'Was the <O1> [sound event,sound] [roughly,approximately] as <L> as the <O2> [sound event,sound]?', # noqa: E501 'Was the <O1> and <O2> [sound events,sounds] [roughly,approximately] as <L>?', # noqa: E501 '[Comparing,Listening to,Hearing] the <O1> [sound event,sound] and the <O2> [sound event,sound], were they [roughly,approximately] as loud?', # noqa: E501 '[Comparing,Listening to,Hearing] the <O1> [sound event,sound] and the <O2> [sound event,sound], did they [roughly,approximately] have the same loudness?', # noqa: E501 '[Comparing,Listening to,Hearing] the <O1> and <O2> [sound events,sounds], were they [roughly,approximately] as loud?', # noqa: E501 '[Comparing,Listening to,Hearing] the <O1> and <O2> [sound events,sounds], did they have [roughly,approximately] the same loudness?', # 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)) loudness = sample_loudness() number_2, ordinal_2 = sample_second_number(len(lst_events), number_1) assert number_1 != number_2, 'Question (compare_same_loudness_ordinal) illposed.' question = question.replace('<O1>', ordinal_1) # insert ordinal question = question.replace('<L>', loudness) # insert loudness question = question.replace('<O2>', ordinal_2) # insert ordinal question = sanitize_question(question) # correct grammar lst_loudness = get_lst_loudness(narrative) e_1_loudness = lst_loudness[number_1 - 1] e_2_loudness = lst_loudness[number_2 - 1] rel_loudness_diff = compute_rel_diff(np.array(e_1_loudness), np.array(e_2_loudness)) # Assert a good margin in relative loudness assert np.sum(np.logical_and(rel_loudness_diff > rel_diff, rel_loudness_diff < (2 * rel_diff))) <= 0, \ 'Question (compare_same_loudness_ordinal) illposed.' answer = 'yes' if rel_loudness_diff <= rel_diff else 'no' return question, answer
def what_was_loudness_relative(dataset, narrative, rel_diff=0.1): questions = [ 'What was the <AL> sound <RO> the <S> <A>?', 'What was the <AL> sound <RO> [hearing,listening to] the <S> <A>?', 'What was the <AL> sound <RO> the <S> <A> was heard?', ] question = str(np.random.choice(questions)) # sample question loudness = sample_absolute_loudness() preposition = sample_preposition() 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 (what_was_loudness_relative) illposed.' event = str(np.random.choice(unique_lst_events)) source = str(np.random.choice(dataset['sources'][event])) # sample source action = str(np.random.choice(dataset['actions'][event])) # sample action question = question.replace('<AL>', loudness) # insert loudness question = question.replace('<RO>', preposition) # insert preposition question = question.replace('<S>', source) # insert source question = question.replace('<A>', action) # insert action question = sanitize_question(question) # correct grammar assert lst_events.count(event) == 1, \ 'Question (what_was_loudness_relative) illposed.' lst_loudness = get_lst_loudness(narrative) event_idx = lst_events.index(event) if 'before' in question: lst_events_e = lst_events[:event_idx] lst_events_l = lst_loudness[:event_idx] elif 'after' in question: lst_events_e = lst_events[(event_idx + 1):] lst_events_l = lst_loudness[(event_idx + 1):] else: assert False, \ 'Preposition illdefined in Question (what_was_loudness_relative).' assert len(lst_events_e) > 0, \ 'Question (what_was_loudness_relative) illposed.' if 'loud' in question: est = np.argmax(lst_events_l) elif 'quiet' in question: est = np.argmin(lst_events_l) else: assert False, \ 'Loudness illdefined in Question (what_was_loudness_relative).' # Assert a good margin in relative loudness evt_loudness = lst_events_l[est] x_loudness = [j for i, j in enumerate(lst_events_l) if i != est] rel_loudness_diff = compute_rel_diff(np.array(x_loudness), np.array(evt_loudness)) assert np.sum(rel_loudness_diff < rel_diff) <= 0, \ 'Question (what_was_loudness_relative) illposed.' e = lst_events_e[est] answer = (str(np.random.choice(dataset['sources'][e])) + ' ' + str(np.random.choice(dataset['actions'][e]))) return question, answer
def what_was_loudness_relative_ordinal(dataset, narrative, rel_diff=0.1): questions = [ 'What was the <AL> sound <RO> the <O> sound?', 'What was the <AL> sound <RO> [hearing,listening to] the <O> sound?', 'What was the <AL> sound <RO> the <O> sound was heard?', ] question = str(np.random.choice(questions)) # sample question loudness = sample_absolute_loudness() preposition = sample_preposition() lst_events = get_lst_events(narrative) number, ordinal = sample_number(len(lst_events)) question = question.replace('<AL>', loudness) # insert loudness question = question.replace('<RO>', preposition) # insert preposition question = question.replace('<O>', ordinal) # insert ordinal question = sanitize_question(question) # correct grammar lst_loudness = get_lst_loudness(narrative) event_idx = (number - 1) answer = None if 'before' in question: if (event_idx - 1) < 0: answer = 'nothing' else: lst_events_e = lst_events[:event_idx] lst_events_l = lst_loudness[:event_idx] elif 'after' in question: if (event_idx + 1) >= len(lst_events): answer = 'nothing' else: lst_events_e = lst_events[(event_idx + 1):] lst_events_l = lst_loudness[(event_idx + 1):] else: assert False, \ 'Preposition illdefined in Question (what_was_loudness_relative_ordinal).' if answer is None: assert len(lst_events_e) > 0, \ 'Question (what_was_loudness_relative_ordinal) illposed.' if 'loud' in question: est = np.argmax(lst_events_l) elif 'quiet' in question: est = np.argmin(lst_events_l) else: assert False, \ 'Loudness illdefined in Question (what_was_loudness_relative_ordinal).' # Assert a good margin in relative loudness evt_loudness = lst_events_l[est] x_loudness = [j for i, j in enumerate(lst_events_l) if i != est] rel_loudness_diff = compute_rel_diff(np.array(x_loudness), np.array(evt_loudness)) assert np.sum(rel_loudness_diff < rel_diff) <= 0, \ 'Question (what_was_loudness_relative_ordinal) illposed.' e = lst_events_e[est] answer = (str(np.random.choice(dataset['sources'][e])) + ' ' + str(np.random.choice(dataset['actions'][e]))) return question, answer
def compare_loudness(dataset, narrative, rel_diff): questions = [ 'Was the <S1> <A1> <RL> than the <S2> <A2>?', 'Was the sound of the <S1> <A1> <RL> than the sound of the <S2> <A2>?', # noqa: E501 '[Comparing,Listening to,Hearing] the sound of the <S1> <A1> and the sound of the <S2> <A2>, was the former <RL>?', # noqa: E501 '[Comparing,Listening to,Hearing] the sounds of the <S1> <A1> and the <S2> <A2>, was the former <RL>?', # noqa: E501 '[Comparing,Listening to,Hearing] the sound of the <S2> <A2> and the sound of the <S1> <A1>, was the latter <RL>?', # noqa: E501 '[Comparing,Listening to,Hearing] the sounds of the <S2> <A2> and the <S1> <A1>, was the latter <RL>?', # 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_loudness) illposed.' event_1 = str(np.random.choice(unique_lst_events)) # sample event source_1 = str(np.random.choice(dataset['sources'][event_1])) action_1 = str(np.random.choice(dataset['actions'][event_1])) rel_loudness = sample_rel_loudness() x_unique_lst_events = [e for e in unique_lst_events if e != event_1] assert len(x_unique_lst_events) > 0, \ 'Question (compare_loudness) illposed.' event_2 = str(np.random.choice(x_unique_lst_events)) # sample event source_2 = str(np.random.choice(dataset['sources'][event_2])) action_2 = str(np.random.choice(dataset['actions'][event_2])) assert lst_events.count(event_1) == 1, \ 'Question (compare_loudness) illposed.' assert lst_events.count(event_2) == 1, \ 'Question (compare_loudness) illposed.' assert event_1 != event_2, 'Question (compare_loudness) illposed.' question = question.replace('<S1>', source_1) # insert source question = question.replace('<A1>', action_1) # insert action question = question.replace('<RL>', rel_loudness) # insert loudness question = question.replace('<S2>', source_2) # insert source question = question.replace('<A2>', action_2) # insert action question = sanitize_question(question) lst_loudness = get_lst_loudness(narrative) e_1_loudness = lst_loudness[lst_events.index(event_1)] e_2_loudness = lst_loudness[lst_events.index(event_2)] # Assert a good margin in relative loudness rel_loudness_diff = compute_rel_diff(np.array(e_1_loudness), np.array(e_2_loudness)) assert np.sum(rel_loudness_diff < rel_diff) <= 0, \ 'Question (compare_loudness) illposed.' if 'quiet' in question: answer = 'yes' if e_1_loudness < e_2_loudness else 'no' elif 'loud' in question: answer = 'yes' if e_1_loudness > e_2_loudness else 'no' else: assert False, 'Loudness illdefined in Question (compare_loudness).' return question, answer
def compare_same_loudness(dataset, narrative, rel_diff=0.1): questions = [ 'Was the <S1> <A1> [roughly,approximately] as <L> as the <S2> <A2>?', # noqa: E501 'Was the sound of the <S1> <A1> [roughly,approximately] as <L> as the sound of the <S2> <A2>?', # noqa: E501 'Was the sound of the <S1> <A1> [roughly,approximately] the same loudness as the sound of the <S2> <A2>?', # noqa: E501 '[Comparing,Listening to,Hearing] the sound of the <S1> <A1> and the sound of the <S2> <A2>, did they [roughly,approximately] have the same loudness?', # noqa: E501 '[Comparing,Listening to,Hearing] the sounds of the <S1> <A1> and the <S2> <A2>, did they [roughly,approximately] have the same loudness?', # 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_loudness) illposed.' event_1 = str(np.random.choice(unique_lst_events)) # sample event source_1 = str(np.random.choice(dataset['sources'][event_1])) action_1 = str(np.random.choice(dataset['actions'][event_1])) loudness = sample_loudness() x_unique_lst_events = [e for e in unique_lst_events if e != event_1] assert len(x_unique_lst_events) > 0, \ 'Question (compare_same_loudness) illposed.' event_2 = str(np.random.choice(x_unique_lst_events)) # sample event source_2 = str(np.random.choice(dataset['sources'][event_2])) action_2 = str(np.random.choice(dataset['actions'][event_2])) assert lst_events.count(event_1) == 1, \ 'Question (compare_same_loudness) illposed.' assert lst_events.count(event_2) == 1, \ 'Question (compare_same_loudness) illposed.' assert event_1 != event_2, 'Question (compare_same_loudness) illposed.' question = question.replace('<S1>', source_1) # insert source question = question.replace('<A1>', action_1) # insert action question = question.replace('<L>', loudness) # insert loudness question = question.replace('<S2>', source_2) # insert source question = question.replace('<A2>', action_2) # insert action question = sanitize_question(question) lst_loudness = get_lst_loudness(narrative) e_1_loudness = lst_loudness[lst_events.index(event_1)] e_2_loudness = lst_loudness[lst_events.index(event_2)] rel_loudness_diff = compute_rel_diff(np.array(e_1_loudness), np.array(e_2_loudness)) # Assert a good margin in relative loudness assert np.sum(np.logical_and(rel_loudness_diff > rel_diff, rel_loudness_diff < (2 * rel_diff))) <= 0, \ 'Question (compare_same_loudness) illposed.' answer = 'yes' if rel_loudness_diff <= rel_diff else 'no' return question, answer
def compare_same_loudness_event_ordinal(dataset, narrative, rel_diff=0.1): questions = [ 'Was the <S> <A> [roughly,approximately] as <L> 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 loud?', # noqa: E501 '[Comparing,Listening to,Hearing] the sound of the <S> <A> and the <O> [sound event,sound], were they [roughly,approximately] as loud?', # noqa: E501 '[Comparing,Listening to,Hearing] the <S> <A> and the <O> [sound event,sound], did they [roughly,approximately] have the same loudness?', # 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 loudness?', # noqa: E501 'Was the <O> [sound event,sound] [roughly,approximately] as <L> as the <S> <A>?', # noqa: E501 '[Comparing,Listening to,Hearing] the <O> [sound event,sound] and the <S> <A>, were they [roughly,approximately] as loud?', # noqa: E501 '[Comparing,Listening to,Hearing] the <O> [sound event,sound] and the sound of the <S> <A>, were they [roughly,approximately] as loud?', # noqa: E501 '[Comparing,Listening to,Hearing] the <O> [sound event,sound] and the <S> <A>, did they [roughly,approximately] have the same loudness?', # 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 loudness?', # 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_loudness_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])) loudness = sample_loudness() number, ordinal = sample_second_number(len(lst_events), lst_events.index(event) + 1) assert lst_events.count(event) == 1, \ 'Question (compare_same_loudness_event_ordinal) illposed.' assert lst_events.index(event) != (number - 1), \ 'Question (compare_same_loudness_event_ordinal) illposed.' question = question.replace('<S>', source) # insert source question = question.replace('<A>', action) # insert action question = question.replace('<L>', loudness) # insert loudness question = question.replace('<O>', ordinal) # insert ordinal question = sanitize_question(question) # correct grammar lst_loudness = get_lst_loudness(narrative) e_1_loudness = lst_loudness[lst_events.index(event)] e_2_loudness = lst_loudness[number - 1] rel_loudness_diff = compute_rel_diff(np.array(e_1_loudness), np.array(e_2_loudness)) # Assert a good margin in relative loudness assert np.sum(np.logical_and(rel_loudness_diff > rel_diff, rel_loudness_diff < (2 * rel_diff))) <= 0, \ 'Question (compare_same_loudness_event_ordinal) illposed.' answer = 'yes' if rel_loudness_diff <= rel_diff else 'no' return question, answer
def compare_loudness_ordinal_event(dataset, narrative, rel_diff=0.1): questions = [ 'Was the <O> [sound event,sound] <RL> than the <S> <A>?', 'Was the <O> [sound event,sound] <RL> 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 <RL>?', # noqa: E501 '[Comparing,Listening to,Hearing] the <S> <A> and the <O> [sound event,sound], was the latter <RL>?', # 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_loudness_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_loudness = sample_rel_loudness() number, ordinal = sample_second_number(len(lst_events), lst_events.index(event) + 1) assert lst_events.count(event) == 1, \ 'Question (compare_loudness_ordinal_event) illposed.' assert lst_events.index(event) != (number - 1), \ 'Question (compare_loudness_ordinal_event) illposed.' question = question.replace('<S>', source) # insert source question = question.replace('<A>', action) # insert action question = question.replace('<RL>', rel_loudness) # insert loudness question = question.replace('<O>', ordinal) # insert ordinal question = sanitize_question(question) # correct grammar lst_loudness = get_lst_loudness(narrative) e_1_loudness = lst_loudness[number - 1] e_2_loudness = lst_loudness[lst_events.index(event)] # Assert a good margin in relative loudness rel_loudness_diff = compute_rel_diff(np.array(e_1_loudness), np.array(e_2_loudness)) assert np.sum(rel_loudness_diff < rel_diff) <= 0, \ 'Question (compare_loudness_ordinal_event) illposed.' if 'quiet' in question: answer = 'yes' if e_1_loudness < e_2_loudness else 'no' elif 'loud' in question: answer = 'yes' if e_1_loudness > e_2_loudness else 'no' else: assert False, \ 'Loudness illdefined in Question (compare_loudness_ordinal_event).' return question, answer
def how_many_sounds_loudness_event(dataset, narrative, rel_diff=0.1): questions = ['How many [sound events,sounds] [roughly,approximately] as <L> as the <S> <A>?', # noqa: E501 'How many [sound events,sounds] that are [roughly,approximately] as <L> as the <S> <A> [did,could] you [hear,listen to]?', # noqa: E501 'How many [sound events,sounds] that are [roughly,approximately] as <L> as the <S> <A> have you heard?', # noqa: E501 'How many [sound events,sounds] that have [roughly,approximately] the same loudness as the <S> <A>?', # noqa: E501 'How many [sound events,sounds] that have [roughly,approximately] the same loudness as the <S> <A> [did,could] you [hear,listen to]?', # noqa: E501 'How many [sound events,sounds] that have [roughly,approximately] the same loudness as the <S> <A> have you heard?', # noqa: E501 'What is the number of [sound events,sounds] [roughly,approximately] as <L> as the <S> <A>?', # noqa: E501 'What is the number of [sound events,sounds] that are [roughly,approximately] as <L> as the <S> <A> [did,could] you [hear,listen to]?', # noqa: E501 'What is the number of [sound events,sounds] that are [roughly,approximately] as <L> as the <S> <A> have you heard?', # noqa: E501 'What is the number of [sound events,sounds] that have [roughly,approximately] the same loudness as the <S> <A>?', # noqa: E501 'What is the number of [sound events,sounds] that have [roughly,approximately] the same loudness as the <S> <A> [did,could] you [hear,listen to]?', # noqa: E501 'What is the number of [sound events,sounds] that have [roughly,approximately] the same loudness as the <S> <A> have you heard?', # noqa: E501 'There is [a,an] <S> <A>; how many [sound events,sounds] that are [roughly,approximately] as <L>?', # noqa: E501 'There is [a,an] <S> <A>; what is the number of [sound events,sounds] that are [roughly,approximately] as <L>?', # noqa: E501 ] question = str(np.random.choice(questions)) # sample question loudness = sample_loudness() # sample loudness 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 (how_many_sounds_loudness_event) illposed.' event = str(np.random.choice(unique_lst_events)) source = str(np.random.choice(dataset['sources'][event])) # sample source action = str(np.random.choice(dataset['actions'][event])) # sample action question = question.replace('<L>', loudness) # insert loudness question = question.replace('<S>', source) # insert source question = question.replace('<A>', action) # insert action question = sanitize_question(question) # correct grammar assert lst_events.count(event) == 1, \ 'Question (how_many_sounds_loudness_event) illposed.' lst_loudness = get_lst_loudness(narrative) event_idx = lst_events.index(event) evt_loudness = lst_loudness[event_idx] x_loudness = [j for i, j in enumerate(lst_loudness) if i != event_idx] rel_loudness_diff = compute_rel_diff(np.array(x_loudness), np.array(evt_loudness)) # Assert a good margin in relative loudness assert np.sum(np.logical_and(rel_loudness_diff > rel_diff, rel_loudness_diff < (2 * rel_diff))) <= 0, \ 'Question (how_many_sounds_loudness_event) illposed.' answer = numbers_to_words(np.sum(rel_loudness_diff <= rel_diff)) return question, answer
def was_there_similar_loudness(dataset, narrative, rel_diff=0.1): questions = [ 'Were there any sounds [roughly,approximately] as <L> as the <S> <A>?', # noqa: E501 'Were there any sounds that were [roughly,approximately] as <L> as the <S> <A>?', # noqa: E501 'Were there any sounds that were [roughly,approximately] the same loudness as the <S> <A>?', # noqa: E501 'Was there any sound [roughly,approximately] as <L> as the <S> <A>?', # noqa: E501 'Was there any sound that was [roughly,approximately] as <L> as the <S> <A>?', # noqa: E501 'Was there any sound that was [roughly,approximately] the same loudness as the <S> <A>?', # noqa: E501 'Was there at least a sound [roughly,approximately] as <L> as the <S> <A>?', # noqa: E501 'Was there at least a sound that was [roughly,approximately] as <L> as the <S> <A>?', # noqa: E501 'Was there at least a sound that was [roughly,approximately] the same loudness as <S> <A>?', # noqa: E501 'Was there at least [one,a single] sound [roughly,approximately] as <L> as the <S> <A>?', # noqa: E501 'Was there at least [one,a single] sound that was [roughly,approximately] as <L> as the <S> <A>?', # noqa: E501 'Was there at least [one,a single] sound that was [roughly,approximately] the same loudness as <S> <A>?', # noqa: E501 ] question = str(np.random.choice(questions)) # sample question loudness = sample_loudness() # sample loudness 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 (was_there_similar_loudness) illposed.' event = str(np.random.choice(unique_lst_events)) source = str(np.random.choice(dataset['sources'][event])) # sample source action = str(np.random.choice(dataset['actions'][event])) # sample action question = question.replace('<L>', loudness) # insert loudness question = question.replace('<S>', source) # insert source question = question.replace('<A>', action) # insert action question = sanitize_question(question) # correct grammar assert lst_events.count(event) == 1, \ 'Question (was_there_similar_loudness) illposed.' lst_loudness = get_lst_loudness(narrative) event_idx = lst_events.index(event) evt_loudness = lst_loudness[event_idx] x_loudness = [j for i, j in enumerate(lst_loudness) if i != event_idx] rel_loudness_diff = compute_rel_diff(np.array(x_loudness), np.array(evt_loudness)) # Assert a good margin in relative loudness assert np.sum(np.logical_and(rel_loudness_diff > rel_diff, rel_loudness_diff < (2 * rel_diff))) <= 0, \ 'Question (was_there_similar_loudness) illposed.' answer = 'yes' if np.sum(rel_loudness_diff <= rel_diff) >= 1 else 'no' return question, answer
def compare_loudness_ordinal(dataset, narrative, rel_diff=0.1): questions = [ 'Was the <O1> [sound event,sound] <RL> 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 <RL>?', # noqa: E501 '[Comparing,Listening to,Hearing] the <O1> and <O2> [sound events,sounds], was the former <RL>?', # noqa: E501 '[Comparing,Listening to,Hearing] the <O2> [sound event,sound] and the <O1> [sound event,sound], was the latter <RL>?', # noqa: E501 '[Comparing,Listening to,Hearing] the <O2> and <O1> [sound events,sounds], was the latter <RL>?', # 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_loudness = sample_rel_loudness() number_2, ordinal_2 = sample_second_number(len(lst_events), number_1) assert number_1 != number_2, 'Question (compare_loudness_ordinal) illposed.' question = question.replace('<O1>', ordinal_1) # insert ordinal question = question.replace('<RL>', rel_loudness) # insert loudness question = question.replace('<O2>', ordinal_2) # insert ordinal question = sanitize_question(question) # correct grammar lst_loudness = get_lst_loudness(narrative) e_1_loudness = lst_loudness[number_1 - 1] e_2_loudness = lst_loudness[number_2 - 1] # Assert a good margin in relative loudness rel_loudness_diff = compute_rel_diff(np.array(e_1_loudness), np.array(e_2_loudness)) assert np.sum(rel_loudness_diff < rel_diff) <= 0, \ 'Question (compare_loudness_ordinal) illposed.' if 'quiet' in question: answer = 'yes' if e_1_loudness < e_2_loudness else 'no' elif 'loud' in question: answer = 'yes' if e_1_loudness > e_2_loudness else 'no' else: assert False, 'Loudness illdefined in Question (compare_loudness_ordinal).' return question, answer
def how_many_sounds_loudness_ordinal(dataset, narrative, rel_diff=0.1): questions = ['How many [sound events,sounds] [roughly,approximately] as <L> as the <O> sound?', # noqa: E501 'How many [sound events,sounds] that are [roughly,approximately] as <L> as the <O> sound?', # noqa: E501 'How many [sound events,sounds] that are [roughly,approximately] as <L> as the <O> sound [did,could] you [hear,listen to]?', # noqa: E501 'How many [sound events,sounds] that are [roughly,approximately] as <L> as the <O> sound have you heard?', # noqa: E501 'How many [sound events,sounds] that have [roughly,approximately] the same loudness as the <O> sound?', # noqa: E501 'How many [sound events,sounds] that have [roughly,approximately] the same loudness as the <O> sound [did,could] you [hear,listen to]?', # noqa: E501 'How many [sound events,sounds] that have [roughly,approximately] the same loudness as the <O> sound have you heard?', # noqa: E501 'What is the number of [sound events,sounds] [roughly,approximately] as <L> as the <O> sound?', # noqa: E501 'What is the number of [sound events,sounds] that are [roughly,approximately] as <L> as the <O> sound?', # noqa: E501 'What is the number of [sound events,sounds] that are [roughly,approximately] as <L> as the <O> sound [did,could] you [hear,listen to]?', # noqa: E501 'What is the number of [sound events,sounds] that are [roughly,approximately] as <L> as the <O> sound have you heard?', # noqa: E501 'What is the number of [sound events,sounds] that have [roughly,approximately] the same loudness as the <O> sound?', # noqa: E501 'What is the number of [sound events,sounds] that have [roughly,approximately] the same loudness as the <O> sound [did,could] you [hear,listen to]?', # noqa: E501 'What is the number of [sound events,sounds] that have [roughly,approximately] the same loudness as the <O> sound have you heard?', # noqa: E501 ] question = str(np.random.choice(questions)) # sample question loudness = sample_loudness() # sample loudness lst_events = get_lst_events(narrative) number, ordinal = sample_number(len(lst_events)) question = question.replace('<L>', loudness) # insert loudness question = question.replace('<O>', ordinal) # insert ordinal question = sanitize_question(question) # correct grammar lst_loudness = get_lst_loudness(narrative) evt_loudness = lst_loudness[number - 1] x_loudness = [j for i, j in enumerate(lst_loudness) if i != (number - 1)] rel_loudness_diff = compute_rel_diff(np.array(x_loudness), np.array(evt_loudness)) # Assert a good margin in relative loudness assert np.sum(np.logical_and(rel_loudness_diff > rel_diff, rel_loudness_diff < (2 * rel_diff))) <= 0, \ 'Question (how_many_sounds_loudness_ordinal) illposed.' answer = numbers_to_words(np.sum(rel_loudness_diff <= rel_diff)) return question, answer
def was_there_similar_loudness_ordinal(dataset, narrative, rel_diff=0.1): questions = [ 'Were there any sounds [roughly,approximately] as <L> as the <O> sound?', # noqa: E501 'Were there any sounds that were [roughly,approximately] as <L> as the <O> sound?', # noqa: E501 'Were there any sounds that were [roughly,approximately] the same loudness as the <O> sound?', # noqa: E501 'Was there any sound [roughly,approximately] as <L> as the <O> sound?', # noqa: E501 'Was there any sound that was [roughly,approximately] as <L> as the <O> sound?', # noqa: E501 'Was there any sound that was [roughly,approximately] the same loudness as the <O> sound?', # noqa: E501 'Was there at least a sound [roughly,approximately] as <L> as the <O> sound?', # noqa: E501 'Was there at least a sound that was [roughly,approximately] as <L> as the <O> sound?', # noqa: E501 'Was there at least a sound that was [roughly,approximately] the same loudness as the <O> sound?', # noqa: E501 'Was there at least [one,a single] sound that was [roughly,approximately] as <L> as the <O> sound?', # noqa: E501 'Was there at least [one,a single] sound [roughly,approximately] as <L> as the <O> sound?', # noqa: E501 'Was there at least [one,a single] sound that was [roughly,approximately] the same loudness as the <O> sound?', # noqa: E501 ] question = str(np.random.choice(questions)) # sample question loudness = sample_loudness() # sample loudness lst_events = get_lst_events(narrative) number, ordinal = sample_number(len(lst_events)) question = question.replace('<L>', loudness) # insert loudness question = question.replace('<O>', ordinal) # insert ordinal question = sanitize_question(question) # correct grammar lst_loudness = get_lst_loudness(narrative) evt_loudness = lst_loudness[number - 1] x_loudness = [j for i, j in enumerate(lst_loudness) if i != (number - 1)] rel_loudness_diff = compute_rel_diff(np.array(x_loudness), np.array(evt_loudness)) # Assert a good margin in relative loudness assert np.sum(np.logical_and(rel_loudness_diff > rel_diff, rel_loudness_diff < (2 * rel_diff))) <= 0, \ 'Question (was_there_similar_loudness_ordinal) illposed.' answer = 'yes' if np.sum(rel_loudness_diff <= rel_diff) >= 1 else 'no' return question, answer