def METHOD_NAME(self, action_space, last_r, seen_nodes, kg):
    (r_space, e_space), action_mask = action_space
    # forbid self-loop action in 1th-hop
    if seen_nodes.shape[1] == 1:
        action_mask = (1 - (r_space == kg.self_edge).float()) * action_mask
        self.validate_action_mask(action_mask)
    # if agent reachs to self-loop, then stop explore
    if seen_nodes.shape[1] != 1:
        stop_mask = (last_r == kg.self_edge).unsqueeze(1).float()
        action_mask = (1 - stop_mask) * action_mask + stop_mask * (r_space == kg.self_edge).float()
        self.validate_action_mask(action_mask)
    # prevent choosing the seen nodes
    loop_mask = (((seen_nodes.unsqueeze(1) == e_space.unsqueeze(2)).sum(2) > 0) * (r_space != kg.self_edge)).float()
    action_mask *= (1 - loop_mask)
    self.validate_action_mask(action_mask)
    return (r_space, e_space), action_mask