def generate_data(data_size): """ Sample some data according to the target """ data = [] for i in range(data_size): # how many in this set set_size = weighted_sample( range(1,10+1), probs=[7187, 1484, 593, 334, 297, 165, 151, 86, 105, 112] ) # get the objects in the current set s = set(sample_sets_of_objects(set_size, all_objects)) # sample according to the target if random() < ALPHA: r = WORDS[len(s)-1] else: r = weighted_sample( WORDS ) # and append the sampled utterance data.append(FunctionData(input=[s], output=r)) # convert to "FunctionData" and store return data
def make_data(data_size=300, alpha=0.75): """ Sample some data according to the target """ data = [] for i in range(data_size): # how many in this set set_size = weighted_sample( range(1, 10 + 1), probs=[7187, 1484, 593, 334, 297, 165, 151, 86, 105, 112]) # get the objects in the current set s = set(sample_sets_of_objects(set_size, all_objects)) # sample according to the target if random() < alpha: r = WORDS[len(s) - 1] else: r = weighted_sample(WORDS) # and append the sampled utterance data.append(FunctionData(input=[s], output=r, alpha=alpha)) return data
def sample_output(self, datum): # return a sample of my output given the input in datum if random() < datum.alpha: return self(*datum.input) else: return weighted_sample(WORDS) # uniform sample