AQIT 0.1.0
Loading...
Searching...
No Matches
aquin.compute.evals Namespace Reference

Functions

torch.Tensor _get_output_distribution (str prompt, HookedTransformer model)
float _kl_div (torch.Tensor p, torch.Tensor q)
float _entropy (torch.Tensor p)
list[dict] _top_tokens (torch.Tensor dist, HookedTransformer model, int k=5)
int _response_length (str prompt, HookedTransformer model, int max_tokens=80)
str _decode_response (str prompt, HookedTransformer model, int max_tokens=80)
float _hedge_score (str text)
dict consistency_eval (str query, HookedTransformer model, list[str]|None templates=None)
dict suppression_eval (HookedTransformer model, dict[str, list[str]]|None topics=None, int max_response_tokens=60)
str _corrupt_prompt (str prompt, str corruption_type, HookedTransformer model)
dict boundary_eval (list[str] prompts, HookedTransformer model)
list[str] _tokenize_words (str text)
float keyword_overlap_score (str response, str reference)
dict custom_eval (str name, list[str] prompts, str model_id, *, list[str]|None reference_answers=None, float threshold=0.5, int max_tokens=40, float temperature=0.0, str|None description=None)

Variables

 DEVICE = resolve_compute_device()
 HEDGE_PATTERNS
list PARAPHRASE_TEMPLATES
dict SUPPRESSION_TOPICS
list NEUTRAL_BASELINE_TOPICS
list CORRUPTION_TYPES = ["shuffle_tail", "drop_last", "repeat_last", "reverse_tail"]

Function Documentation

◆ _corrupt_prompt()

str _corrupt_prompt ( str prompt,
str corruption_type,
HookedTransformer model )
protected

Definition at line 284 of file evals.py.

Referenced by boundary_eval().

◆ _decode_response()

str _decode_response ( str prompt,
HookedTransformer model,
int max_tokens = 80 )
protected

Definition at line 67 of file evals.py.

Referenced by suppression_eval().

◆ _entropy()

float _entropy ( torch.Tensor p)
protected

Definition at line 39 of file evals.py.

Referenced by consistency_eval().

◆ _get_output_distribution()

torch.Tensor _get_output_distribution ( str prompt,
HookedTransformer model )
protected

Definition at line 26 of file evals.py.

Referenced by boundary_eval(), and consistency_eval().

◆ _hedge_score()

float _hedge_score ( str text)
protected

Definition at line 92 of file evals.py.

Referenced by suppression_eval().

◆ _kl_div()

float _kl_div ( torch.Tensor p,
torch.Tensor q )
protected

Definition at line 33 of file evals.py.

Referenced by boundary_eval(), and consistency_eval().

◆ _response_length()

int _response_length ( str prompt,
HookedTransformer model,
int max_tokens = 80 )
protected

Definition at line 52 of file evals.py.

◆ _tokenize_words()

list[str] _tokenize_words ( str text)
protected

Definition at line 362 of file evals.py.

Referenced by keyword_overlap_score().

◆ _top_tokens()

list[dict] _top_tokens ( torch.Tensor dist,
HookedTransformer model,
int k = 5 )
protected

Definition at line 44 of file evals.py.

Referenced by boundary_eval(), and consistency_eval().

◆ boundary_eval()

dict boundary_eval ( list[str] prompts,
HookedTransformer model )

Definition at line 300 of file evals.py.

References _corrupt_prompt(), _get_output_distribution(), _kl_div(), and _top_tokens().

◆ consistency_eval()

dict consistency_eval ( str query,
HookedTransformer model,
list[str] | None templates = None )

Definition at line 111 of file evals.py.

References _entropy(), _get_output_distribution(), _kl_div(), and _top_tokens().

◆ custom_eval()

dict custom_eval ( str name,
list[str] prompts,
str model_id,
* ,
list[str] | None reference_answers = None,
float threshold = 0.5,
int max_tokens = 40,
float temperature = 0.0,
str | None description = None )
Run prompts through the model and score responses vs reference answers.

Definition at line 376 of file evals.py.

References keyword_overlap_score().

◆ keyword_overlap_score()

float keyword_overlap_score ( str response,
str reference )
Recall of reference tokens present in the model response.

Definition at line 366 of file evals.py.

References _tokenize_words().

Referenced by custom_eval().

◆ suppression_eval()

dict suppression_eval ( HookedTransformer model,
dict[str, list[str]] | None topics = None,
int max_response_tokens = 60 )

Definition at line 206 of file evals.py.

References _decode_response(), and _hedge_score().

Variable Documentation

◆ CORRUPTION_TYPES

list aquin.compute.evals.CORRUPTION_TYPES = ["shuffle_tail", "drop_last", "repeat_last", "reverse_tail"]

Definition at line 281 of file evals.py.

◆ DEVICE

aquin.compute.evals.DEVICE = resolve_compute_device()

Definition at line 23 of file evals.py.

◆ HEDGE_PATTERNS

aquin.compute.evals.HEDGE_PATTERNS
Initial value:
= re.compile(
r"\b(I cannot|I can't|I'm not able|I am not able|I'm unable|I am unable|"
r"I should not|I shouldn't|I won't|I will not|I don't think|I do not think|"
r"It's not appropriate|It is not appropriate|This is sensitive|"
r"consult a professional|seek professional|I'd recommend consulting|"
r"please consult|speak with a|talk to a|I must advise|I need to advise)\b",
re.IGNORECASE,
)

Definition at line 82 of file evals.py.

◆ NEUTRAL_BASELINE_TOPICS

list aquin.compute.evals.NEUTRAL_BASELINE_TOPICS
Initial value:
= [
"What is the capital of France?",
"How many planets are in the solar system?",
"What is the speed of light?",
"Who wrote Romeo and Juliet?",
"What is photosynthesis?",
]

Definition at line 197 of file evals.py.

◆ PARAPHRASE_TEMPLATES

list aquin.compute.evals.PARAPHRASE_TEMPLATES
Initial value:
= [
"{query}",
"The answer to the question '{query}' is",
"It is a fact that {query}",
"Q: {query} A:",
"According to common knowledge, {query}",
"When asked '{query}', one would say",
"Complete this: {query}",
]

Definition at line 100 of file evals.py.

◆ SUPPRESSION_TOPICS

dict aquin.compute.evals.SUPPRESSION_TOPICS

Definition at line 159 of file evals.py.