def decode_examples(examples): new_examples = [] for inputs, output in examples: new_inputs = [Value.construct(x) for x in inputs] new_output = Value.construct(output) new_examples.append((new_inputs, new_output)) return new_examples
def decode_example(example): """ Expected format: { "inputs": [ [], [] ] "output": [] } """ inputs = [Value.construct(x) for x in example['inputs']] output = Value.construct(example['output']) return inputs, output
def __call__(self, *args): for arg in args: if arg == NULLVALUE: raise NullInputError('{}({})'.format(self.name, args)) raw_args = [x.val for x in args] output_raw = self.val(*raw_args) output_val = Value.construct(output_raw, self.output_type) if output_val != NULLVALUE and not in_range(output_val): raise OutputOutOfRangeError('{}({})'.format(self.name, args)) return output_val
def run(self, inputs): if self.component in LAMBDAS: return self.component elif type(self.component) == Variable: value = inputs[self.component.index] t = INT if type(value) == int else LIST return Value(inputs[self.component.index], t) else: f_inputs = list() for child in self.children: f_inputs.append(child.run(inputs)) return self.component(*f_inputs)
def decode_example(example): """ Expected format: { "inputs": [ [], [] ] "output": [] } """ #print("Input before value construction:", [x for x in example['inputs']]) inputs = [Value.construct(x) for x in example['inputs']] #print("Type() before:", type(example['inputs'][0])) #print("Type() after:", type(inputs[0])) # print("Input after value construction:", inputs) #print("Output before value construction:", example['output']) output = Value.construct(example['output']) #print("Output after value construction:", output) complete = inputs, output #print("CONSTRUCTION COMPLETED", complete) return inputs, output
def get_input_output_examples(program, M=5): examples = [] constraints = propagate_constraints(program) for i in range(M): input_vals = [] for j, (input_type, constraint) in enumerate(zip(program.input_types, constraints)): raw_val = sample(constraint) val = Value.construct(raw_val, input_type) input_vals.append(val) output_val = program(*input_vals) examples.append((input_vals, output_val)) return examples
def __call__(self, *args): raw_args = [x.val for x in args] output_val = self.val(*raw_args) return Value.construct(output_val, self.output_type)
def decode_example(example): #print("DECODE:", example) inputs = [Value.construct(x) for x in example[0]] output = Value.construct(example[1]) return inputs, output