TextAttack icon indicating copy to clipboard operation
TextAttack copied to clipboard

I want to find where I can jump to this

Open zl-comment opened this issue 1 year ago • 1 comments

def get_indices_to_order(self, current_text, **kwargs): """Applies pre_transformation_constraints to text to get all the indices that can be used to search and order.

    Args:
        current_text: The current ``AttackedText`` for which we need to find indices are eligible to be ordered.
    Returns:
        The length and the filtered list of indices which search methods can use to search/order.
    """

    indices_to_order = self.transformation(
        current_text,
        pre_transformation_constraints=self.pre_transformation_constraints,
        return_indices=True,
        **kwargs,
    )

    len_text = len(indices_to_order)

    # Convert indices_to_order to list for easier shuffling later
    return len_text, list(indices_to_order)

I want to know where this self.transformation will jump to this method, I use bertattack I looked for it in the transformation parent class, but it doesn’t seem to match

zl-comment avatar Nov 21 '24 14:11 zl-comment

I'm assuming you're referring to this portion of the code. The docs indicate the following for Attack.transformation:

transformation (:class:`~textattack.transformations.Transformation`):
            The transformation applied at each step of the attack.

For its transformation variable, it looks like BERTAttack is using WordSwapMaskedLM(method="bert-attack", max_candidates=48) (code here)

bterrific2008 avatar Jan 16 '25 04:01 bterrific2008