util
genlm.eval.util
bootstrap_ci(values, metric, ci=0.95, n_bootstrap=10000)
Calculate bootstrap confidence intervals for a given metric.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
values
|
array - like
|
Array-like object containing the data points. |
required |
metric
|
function
|
Function that computes the statistic of interest (e.g., np.mean, np.median). |
required |
ci
|
float
|
Confidence interval level (between 0 and 1). Default is 0.95 for 95% CI. |
0.95
|
n_bootstrap
|
int
|
Number of bootstrap samples to generate. Default is 10000. |
10000
|
Returns:
Type | Description |
---|---|
tuple
|
(mean, lower, upper) where: - mean is the metric computed on the original data - lower is the lower bound of the confidence interval - upper is the upper bound of the confidence interval |
Raises:
Type | Description |
---|---|
ValueError
|
If ci is not between 0 and 1 or if values is empty. |
Source code in genlm/eval/util.py
chat_template_messages(prompt, examples, user_message)
Create a list of messages for chat template formatting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt
|
str
|
System prompt to be used as the initial message. |
required |
examples
|
list
|
List of (example, response) tuples for few-shot learning. |
required |
user_message
|
str
|
The actual user query to be processed. |
required |
Returns:
Type | Description |
---|---|
list
|
List of dictionaries containing the formatted messages with roles and content for the chat template. |
Source code in genlm/eval/util.py
LRUCache
Bases: ABC
A cache that evicts the least recently used item when the cache is full.
Source code in genlm/eval/util.py
__init__(cache_size=1)
Initialize the cache.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cache_size
|
int
|
The size of the cache. |
1
|
create(key)
abstractmethod
Create an object for a given key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
any
|
The key to create an object for. |
required |
cleanup(key, obj)
Cleanup an object for a given key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
any
|
The key to cleanup an object for. |
required |
obj
|
any
|
The object to cleanup. |
required |
get(key)
Get an object for a given key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
any
|
The key to get an object for. |
required |
Returns:
Name | Type | Description |
---|---|---|
any |
The object for the given key. |