Skip to content

Commit

Permalink
Add default cascade settings (#25)
Browse files Browse the repository at this point in the history
Moves num quantiles (default 50) and IS weight (default 0.5) to the
default settings.
  • Loading branch information
pgasawa authored Oct 29, 2024
1 parent e2f7407 commit 19b3596
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lotus/sem_ops/cascade_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ def importance_sampling(
"""Uses importance sampling and returns the list of indices from which to learn cascade thresholds."""

w = np.sqrt(proxy_scores)
w = 0.5 * w / np.sum(w) + 0.5 * np.ones((len(proxy_scores))) / len(proxy_scores)
is_weight = lotus.settings.cascade_is_weight
w = is_weight * w / np.sum(w) + (1 - is_weight) * np.ones((len(proxy_scores))) / len(proxy_scores)
indices = np.arange(len(proxy_scores))
sample_size = (int) (sample_percentage * len(proxy_scores))
sample_indices = np.random.choice(indices, sample_size, p=w)
Expand All @@ -20,7 +21,7 @@ def importance_sampling(

def calibrate_llm_logprobs(true_probs: list[float]) -> list[float]:
"""Transforms true probabilities to calibrate LLM proxies."""
num_quantiles = 50
num_quantiles = lotus.settings.cascade_num_calibration_quantiles
quantile_values = np.percentile(true_probs, np.linspace(0, 100, num_quantiles + 1))
true_probs = ((np.digitize(true_probs, quantile_values) - 1) / num_quantiles)
true_probs = np.clip(true_probs, 0, 1)
Expand Down
1 change: 1 addition & 0 deletions lotus/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,4 @@ def __repr__(self) -> str:

# set defaults
settings = Settings()
settings.configure(cascade_is_weight=0.5, cascade_num_calibration_quantiles=50)

0 comments on commit 19b3596

Please sign in to comment.