parameters: (self, sess, emb, loom_input, sampling_ctx, depth,
                        context)
return_statement: return function
docstring: Sample one function/predicate call.
docstring_summary: Sample one function/predicate call.
docstring_tokens: Sample one function / predicate call .
function: def sample_function(self, sess, emb, loom_input, sampling_ctx, depth,
                        context):
      """Sample one function/predicate call."""
      if depth > FLAGS.max_function_depth:
        return {'error': 'Maximum depth exceeded'}
  
      function = {}
  
      with self.aux_lstm(emb, loom_input, context=context) as (emb, add_to_lstm):
        func = loom_input.which_func(emb)
        sampled_func = loom_input.sample_func(
            func, loom_input.constant(context['temp']))
        func_emb = loom_input.emb_lookup_func(sampled_func)
        add_to_lstm(lambda: func_emb)
  
      if 'uncond_sib' in self.model_variants:
        merged_emb = emb
      else:
        merged_emb = loom_input.merge_func_emb(func_emb, emb)
  
      func_name = sampling_ctx.register(sampled_func,
                                        lambda arr: self.func_id_to_name[arr])
      merged_emb = sampling_ctx.register(merged_emb)
  
      with self.eval_lstm_state(sess, sampling_ctx, context):
        func_name_val, merged_emb_val = sampling_ctx.run_and_insert(
            sess, [func_name, merged_emb])
  
      num_arguments = self.func_arities[func_name_val]
      is_predicate = self.func_name_to_is_predicate[func_name_val]
  
      params = []
      if func_name_val == '__equal__':
        function[u'equal'] = params
      elif is_predicate:
        function[u'pred'] = func_name_val
        function[u'params'] = params
      else:
        function[u'func'] = func_name_val
        function[u'params'] = params
  
      # Now generate each argument.
      prev_state = None
      for i in xrange(num_arguments):
        loom_input = self.loom.make_weaver()
        sampling_ctx = SamplingContext(self.loom, loom_input)
        prev_state = (loom_input.constant(merged_emb_val) if prev_state is None
                      else loom_input.constant(prev_state))
        if i > 0:
          with self.aux_lstm(
              prev_state, loom_input, context=context) as (lstm_added_state, _):
            prev_state = lstm_added_state
  
        next_state, param_emb = loom_input.split_rec_func_args(prev_state)
        next_state = sampling_ctx.register(next_state)
        param_emb = sampling_ctx.register(param_emb)
  
        with self.eval_lstm_state(sess, sampling_ctx, context):
          next_state_val, param_emb_val = sampling_ctx.run_and_insert(
              sess, [next_state, param_emb])
  
        sampled_term = self.sample_term(sess, param_emb_val, depth, context)
        params.append(sampled_term)
        prev_state = next_state_val
  
      return function
function_tokens: def sample_function ( self , sess , emb , loom_input , sampling_ctx , depth , context ) : if depth > FLAGS . max_function_depth : return { 'error' : 'Maximum depth exceeded' } function = { } with self . aux_lstm ( emb , loom_input , context = context ) as ( emb , add_to_lstm ) : func = loom_input . which_func ( emb ) sampled_func = loom_input . sample_func ( func , loom_input . constant ( context [ 'temp' ] ) ) func_emb = loom_input . emb_lookup_func ( sampled_func ) add_to_lstm ( lambda : func_emb ) if 'uncond_sib' in self . model_variants : merged_emb = emb else : merged_emb = loom_input . merge_func_emb ( func_emb , emb ) func_name = sampling_ctx . register ( sampled_func , lambda arr : self . func_id_to_name [ arr ] ) merged_emb = sampling_ctx . register ( merged_emb ) with self . eval_lstm_state ( sess , sampling_ctx , context ) : func_name_val , merged_emb_val = sampling_ctx . run_and_insert ( sess , [ func_name , merged_emb ] ) num_arguments = self . func_arities [ func_name_val ] is_predicate = self . func_name_to_is_predicate [ func_name_val ] params = [ ] if func_name_val == '__equal__' : function [ u'equal' ] = params elif is_predicate : function [ u'pred' ] = func_name_val function [ u'params' ] = params else : function [ u'func' ] = func_name_val function [ u'params' ] = params # Now generate each argument. prev_state = None for i in xrange ( num_arguments ) : loom_input = self . loom . make_weaver ( ) sampling_ctx = SamplingContext ( self . loom , loom_input ) prev_state = ( loom_input . constant ( merged_emb_val ) if prev_state is None else loom_input . constant ( prev_state ) ) if i > 0 : with self . aux_lstm ( prev_state , loom_input , context = context ) as ( lstm_added_state , _ ) : prev_state = lstm_added_state next_state , param_emb = loom_input . split_rec_func_args ( prev_state ) next_state = sampling_ctx . register ( next_state ) param_emb = sampling_ctx . register ( param_emb ) with self . eval_lstm_state ( sess , sampling_ctx , context ) : next_state_val , param_emb_val = sampling_ctx . run_and_insert ( sess , [ next_state , param_emb ] ) sampled_term = self . sample_term ( sess , param_emb_val , depth , context ) params . append ( sampled_term ) prev_state = next_state_val return function