def __init__(self, batch_size, max_length, max_nesting, curriculum,
               token_by_char=True, task_type="alg-ctrl"):
    """Creates a LearnToExecute Dataset.

    Initializes the dataset task set and input annd target sequence shapes.
    Maximum sequence sizes for input and target are computed based on maximum
    possible assignments.  Also, curriculum is set, operations corresponding to
    the chosen task is set and the data source is initialized.

    Args:
      batch_size: (int). The number of elements in a mini-batch.
      max_length: (int). Maximum character length.
      max_nesting: (int). Maximum level of statement nesting.
      curriculum: (LTECurriculum). Curriculum strategy to use.
      token_by_char: (bool). Tokenize by character or words?
      task_type: (string) defines the task by allowable ops (see TASK_TYPE_OPS).

    Raises:
      ValueError: If task is invalid.
    """
    super(LearnToExecuteState, self).__init__()
    self._token_by_char = token_by_char
    # Compute the max number of steps possible to take.
    if task_type in self.TASK_GROUPS[TaskGroups.PROG_TASKS]:
      if token_by_char:
        outer_nests_term = (max_length * 3 + 10) * (max_nesting - 1)
        inner_nest_term = max_length * 4 + 10
        nest_tok_term = (max_nesting - 1) * 2
        self._num_steps_out = max_length * 2
      else:
        outer_nests_term = 10 * (max_nesting - 1)
        inner_nest_term = 11
        nest_tok_term = (max_nesting - 1) * 2
        self._num_steps_out = 1
      self._num_steps = outer_nests_term + inner_nest_term + nest_tok_term
    elif task_type in self.TASK_GROUPS[TaskGroups.MEMORY_1]:
      self._token_by_char = True
      self._num_steps = max_length + 1
      self._num_steps_out = max_length + 1
    elif task_type in self.TASK_GROUPS[TaskGroups.MEMORY_2]:
      self._token_by_char = True
      self._num_steps = max_length + 1
      self._num_steps_out = max_length * 2 + 1
    else:
      raise ValueError("Unknown task: {}.".format(task_type))

    self._batch_size = batch_size
    self._ops = LearnToExecuteState.get_task_ops(task_type)
    self._curriculum = curriculum
    num_steps = max(self._num_steps, self._num_steps_out)
    self._data_source = TokenDataSource(
        self._curriculum, self._batch_size, num_steps, self._ops,
        self._token_by_char)
    self.reset_data_source()
def __init__ ( self , batch_size , max_length , max_nesting , curriculum , token_by_char = True , task_type = "alg-ctrl" ) : super ( LearnToExecuteState , self ) . __init__ ( ) self . _token_by_char = token_by_char if task_type in self . TASK_GROUPS [ TaskGroups . PROG_TASKS ] : if token_by_char : outer_nests_term = ( max_length * 3 + 10 ) * ( max_nesting - 1 ) inner_nest_term = max_length * 4 + 10 nest_tok_term = ( max_nesting - 1 ) * 2 self . _num_steps_out = max_length * 2 else : outer_nests_term = 10 * ( max_nesting - 1 ) inner_nest_term = 11 nest_tok_term = ( max_nesting - 1 ) * 2 self . _num_steps_out = 1 self . _num_steps = outer_nests_term + inner_nest_term + nest_tok_term elif task_type in self . TASK_GROUPS [ TaskGroups . MEMORY_1 ] : self . _token_by_char = True self . _num_steps = max_length + 1 self . _num_steps_out = max_length + 1 elif task_type in self . TASK_GROUPS [ TaskGroups . MEMORY_2 ] : self . _token_by_char = True self . _num_steps = max_length + 1 self . _num_steps_out = max_length * 2 + 1 else : raise ValueError ( "Unknown task: {}." . format ( task_type ) ) self . _batch_size = batch_size self . _ops = LearnToExecuteState . get_task_ops ( task_type ) self . _curriculum = curriculum num_steps = max ( self . _num_steps , self . _num_steps_out ) self . _data_source = TokenDataSource ( self . _curriculum , self . _batch_size , num_steps , self . _ops , self . _token_by_char ) self . reset_data_source ( )
Creates a LearnToExecute Dataset.

    Initializes the dataset task set and input annd target sequence shapes.
    Maximum sequence sizes for input and target are computed based on maximum
    possible assignments.  Also, curriculum is set, operations corresponding to
    the chosen task is set and the data source is initialized.

    Args:
      batch_size: (int). The number of elements in a mini-batch.
      max_length: (int). Maximum character length.
      max_nesting: (int). Maximum level of statement nesting.
      curriculum: (LTECurriculum). Curriculum strategy to use.
      token_by_char: (bool). Tokenize by character or words?
      task_type: (string) defines the task by allowable ops (see TASK_TYPE_OPS).

    Raises:
      ValueError: If task is invalid.