prompting.validators.penalty#

Submodules#

Package Contents#

Classes#

BasePenaltyModel

Helper class that provides a standard way to create an ABC using

PenaltyModelType

Create a collection of name/value pairs.

TaskValidationPenaltyModel

Helper class that provides a standard way to create an ABC using

KeywordMatchPenaltyModel

ContentMatchPenaltyModel

Helper class that provides a standard way to create an ABC using

class prompting.validators.penalty.BasePenaltyModel(max_penalty)#

Bases: abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

Parameters:

max_penalty (float) –

abstract property name: str#
Return type:

str

__str__()#

Return str(self).

Return type:

str

__repr__()#

Return repr(self).

Return type:

str

abstract calculate_penalties(completions)#
Parameters:

completions (List[str]) –

Return type:

torch.FloatTensor

apply_penalties(responses, task)#
Parameters:
Return type:

torch.FloatTensor

class prompting.validators.penalty.PenaltyModelType(*args, **kwds)#

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

    >>> Color.RED
    <Color.RED: 1>
    
  • value lookup:

    >>> Color(1)
    <Color.RED: 1>
    
  • name lookup:

    >>> Color['RED']
    <Color.RED: 1>
    

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

task_validation_penalty = 'task_validation_penalty'#
keyword_match_penalty = 'keyword_match_penalty'#
sentence_match_penalty = 'sentence_match_penalty'#
class prompting.validators.penalty.TaskValidationPenaltyModel(max_penalty)#

Bases: prompting.validators.penalty.penalty.BasePenaltyModel

Helper class that provides a standard way to create an ABC using inheritance.

Parameters:

max_penalty (float) –

property name: str#
Return type:

str

calculate_penalties(task, completions)#
Parameters:
Return type:

torch.FloatTensor

class prompting.validators.penalty.KeywordMatchPenaltyModel#

Bases: prompting.validators.penalty.penalty.BasePenaltyModel

property name: str#
Return type:

str

check_exploits_keywords(completion, name)#
Parameters:
  • completion (str) –

  • name (str) –

Return type:

float

calculate_penalties(task, completions)#
Parameters:
Return type:

torch.FloatTensor

class prompting.validators.penalty.ContentMatchPenaltyModel(max_penalty)#

Bases: prompting.validators.penalty.penalty.BasePenaltyModel

Helper class that provides a standard way to create an ABC using inheritance.

Parameters:

max_penalty (float) –

property name: str#
Return type:

str

calculate_penalties(task, completions)#
Parameters:
Return type:

torch.FloatTensor