def _get_state_cost(self, state: WikiTablesDecoderState) -> torch.Tensor:
        if not state.is_finished():
            raise RuntimeError(
                "_get_state_cost() is not defined for unfinished states!")

        # Our checklist cost is a sum of squared error from where we want to be, making sure we
        # take into account the mask. We clamp the lower limit of the balance at 0 to avoid
        # penalizing agenda actions produced multiple times.
        checklist_balance = torch.clamp(state.checklist_state[0].get_balance(),
                                        min=0.0)
        checklist_cost = torch.sum((checklist_balance)**2)

        # This is the number of items on the agenda that we want to see in the decoded sequence.
        # We use this as the denotation cost if the path is incorrect.
        denotation_cost = torch.sum(
            state.checklist_state[0].checklist_target.float())
        checklist_cost = self._checklist_cost_weight * checklist_cost
        action_history = state.action_history[0]
        batch_index = state.batch_indices[0]
        action_strings = [
            state.possible_actions[batch_index][i][0] for i in action_history
        ]
        logical_form = state.world[batch_index].get_logical_form(
            action_strings)
        lisp_string = state.example_lisp_string[batch_index]
        if self._denotation_accuracy.evaluate_logical_form(
                logical_form, lisp_string):
            cost = checklist_cost
        else:
            cost = checklist_cost + (
                1 - self._checklist_cost_weight) * denotation_cost
        return cost
 def _get_state_cost(self, state: WikiTablesDecoderState) -> torch.Tensor:
     if not state.is_finished():
         raise RuntimeError("_get_state_cost() is not defined for unfinished states!")
     action_history = state.action_history[0]
     batch_index = state.batch_indices[0]
     action_strings = [state.possible_actions[batch_index][i][0] for i in action_history]
     logical_form = state.world[batch_index].get_logical_form(action_strings)
     lisp_string = state.example_lisp_string[batch_index]
     if self._denotation_accuracy.evaluate_logical_form(logical_form, lisp_string):
         cost = torch.FloatTensor([0.0])
     else:
         cost = torch.FloatTensor([10])
     return Variable(state.flattened_linking_scores.data.new(cost)).float()
    def _get_state_cost(self, state: WikiTablesDecoderState) -> torch.Tensor:
        if not state.is_finished():
            raise RuntimeError("_get_state_cost() is not defined for unfinished states!")

        # Our checklist cost is a sum of squared error from where we want to be, making sure we
        # take into account the mask. We clamp the lower limit of the balance at 0 to avoid
        # penalizing agenda actions produced multiple times.
        checklist_balance = torch.clamp(state.checklist_state[0].get_balance(), min=0.0)
        checklist_cost = torch.sum((checklist_balance) ** 2)

        # This is the number of items on the agenda that we want to see in the decoded sequence.
        # We use this as the denotation cost if the path is incorrect.
        denotation_cost = torch.sum(state.checklist_state[0].checklist_target.float())
        checklist_cost = self._checklist_cost_weight * checklist_cost
        action_history = state.action_history[0]
        batch_index = state.batch_indices[0]
        action_strings = [state.possible_actions[batch_index][i][0] for i in action_history]
        logical_form = state.world[batch_index].get_logical_form(action_strings)
        lisp_string = state.example_lisp_string[batch_index]
        if self._denotation_accuracy.evaluate_logical_form(logical_form, lisp_string):
            cost = checklist_cost
        else:
            cost = checklist_cost + (1 - self._checklist_cost_weight) * denotation_cost
        return cost