pyrit.prompt_converter.WordProportionSelectionStrategy#

class WordProportionSelectionStrategy(*, proportion: float, seed: int | None = None)[source]#

Bases: WordSelectionStrategy

Selects a random proportion of words.

__init__(*, proportion: float, seed: int | None = None) None[source]#

Initializes the word proportion selection strategy.

Parameters:
  • proportion (float) – The proportion of words to select (0.0 to 1.0).

  • seed (Optional[int]) – Random seed for reproducible selections. Defaults to None.

Raises:

ValueError – If proportion is not between 0.0 and 1.0.

Methods

__init__(*, proportion[, seed])

Initializes the word proportion selection strategy.

select_range(*, text[, word_separator])

Selects a character range by first selecting words, then converting to character positions.

select_words(*, words)

Selects a random proportion of words.

select_words(*, words: List[str]) List[int][source]#

Selects a random proportion of words.

Parameters:

words (List[str]) – The list of words to select from.

Returns:

The list of randomly selected indices.

Return type:

List[int]