Initialize the prompt tuner. Args: reward_fn: User-defined reward function (question, ans1, ans2, std) -> [1,0], [0,1], or [0.5,0.5] tuning_model_fn: Optional single inference function (auto-created from batch if not provided) tuner_model
(
self,
reward_fn: Callable[[str, str, str, str], List[int]],
tuning_model_fn: Optional[Callable[[str, Optional[str], float, Optional[int]], str]] = None,
tuner_model_fn: Optional[Callable[[str, Optional[str], float, Optional[int]], str]] = None,
embedding_model_fn: Optional[Callable[[str], List[float]]] = None,
tuning_model_batch_fn: Optional[Callable[[List[str], Any, float, Optional[int]], List[str]]] = None,
tuner_model_batch_fn: Optional[Callable[[List[str], Any, float, Optional[int]], List[str]]] = None,
embedding_model_batch_fn: Optional[Callable[[List[str]], List[List[float]]]] = None,
mlflow_tracking_uri: str = "http://localhost:5000",
mlflow_experiment_name: str = "prompt_tuning",
mlflow_project_name: Optional[str] = None,
batch_size: int = 10,
eval_steps: int = 5,
max_guidance_length: int = 500,
# Question retrieval parameters (for retrieving guidance based on questions)
question_retrieval_top_k: int = 3,
question_retrieval_threshold: float = 0.7,
# Subject retrieval parameters (for merging related subjects)
subject_retrieval_top_k: int = 5,
subject_retrieval_threshold: float = 0.9,
# Evaluation parameters
eval_retrieval_top_k: int = 3,
eval_retrieval_threshold: float = 0.7,
eval_batch_size: int = 10,
eval_at_n: int = 1,
knowledge_base_path: Optional[str] = None,
max_prompt_tokens: Optional[int] = None,
token_counting_model: str = "gpt-3.5-turbo",
# Prompt templates for customization
guidance_extraction_prompt_template: Optional[str] = None,
guidance_merge_prompt_template: Optional[str] = None,
shuffle_batches: bool = False,
)
| 44 | """ |
| 45 | |
| 46 | def __init__( |
| 47 | self, |
| 48 | reward_fn: Callable[[str, str, str, str], List[int]], |
| 49 | tuning_model_fn: Optional[Callable[[str, Optional[str], float, Optional[int]], str]] = None, |
| 50 | tuner_model_fn: Optional[Callable[[str, Optional[str], float, Optional[int]], str]] = None, |
| 51 | embedding_model_fn: Optional[Callable[[str], List[float]]] = None, |
| 52 | tuning_model_batch_fn: Optional[Callable[[List[str], Any, float, Optional[int]], List[str]]] = None, |
| 53 | tuner_model_batch_fn: Optional[Callable[[List[str], Any, float, Optional[int]], List[str]]] = None, |
| 54 | embedding_model_batch_fn: Optional[Callable[[List[str]], List[List[float]]]] = None, |
| 55 | mlflow_tracking_uri: str = "http://localhost:5000", |
| 56 | mlflow_experiment_name: str = "prompt_tuning", |
| 57 | mlflow_project_name: Optional[str] = None, |
| 58 | batch_size: int = 10, |
| 59 | eval_steps: int = 5, |
| 60 | max_guidance_length: int = 500, |
| 61 | # Question retrieval parameters (for retrieving guidance based on questions) |
| 62 | question_retrieval_top_k: int = 3, |
| 63 | question_retrieval_threshold: float = 0.7, |
| 64 | # Subject retrieval parameters (for merging related subjects) |
| 65 | subject_retrieval_top_k: int = 5, |
| 66 | subject_retrieval_threshold: float = 0.9, |
| 67 | # Evaluation parameters |
| 68 | eval_retrieval_top_k: int = 3, |
| 69 | eval_retrieval_threshold: float = 0.7, |
| 70 | eval_batch_size: int = 10, |
| 71 | eval_at_n: int = 1, |
| 72 | knowledge_base_path: Optional[str] = None, |
| 73 | max_prompt_tokens: Optional[int] = None, |
| 74 | token_counting_model: str = "gpt-3.5-turbo", |
| 75 | # Prompt templates for customization |
| 76 | guidance_extraction_prompt_template: Optional[str] = None, |
| 77 | guidance_merge_prompt_template: Optional[str] = None, |
| 78 | shuffle_batches: bool = False, |
| 79 | ): |
| 80 | """ |
| 81 | Initialize the prompt tuner. |
| 82 | |
| 83 | Args: |
| 84 | reward_fn: User-defined reward function (question, ans1, ans2, std) -> [1,0], [0,1], or [0.5,0.5] |
| 85 | tuning_model_fn: Optional single inference function (auto-created from batch if not provided) |
| 86 | tuner_model_fn: Optional single inference function (auto-created from batch if not provided) |
| 87 | embedding_model_fn: Optional single embedding function (auto-created from batch if not provided) |
| 88 | tuning_model_batch_fn: Batch inference function for tuning model (preferred) |
| 89 | tuner_model_batch_fn: Batch inference function for tuner model (preferred) |
| 90 | embedding_model_batch_fn: Batch embedding function (preferred) |
| 91 | mlflow_tracking_uri: MLflow tracking server URI (default: http://localhost:5000) |
| 92 | mlflow_experiment_name: Name of the MLflow experiment (default: prompt_tuning) |
| 93 | mlflow_project_name: Optional project/run name |
| 94 | batch_size: Number of samples per training batch |
| 95 | eval_steps: Evaluate every N steps |
| 96 | max_guidance_length: Maximum character length for guidance |
| 97 | question_retrieval_top_k: Top-k guidance to retrieve when searching by question |
| 98 | question_retrieval_threshold: Minimum similarity threshold for question-based retrieval |
| 99 | subject_retrieval_top_k: Top-k entries to retrieve when merging related subjects |
| 100 | subject_retrieval_threshold: Minimum similarity threshold for subject-based retrieval |
| 101 | eval_retrieval_top_k: Top-k guidance to retrieve during evaluation |
| 102 | eval_retrieval_threshold: Minimum similarity threshold for evaluation retrieval |
| 103 | eval_batch_size: Batch size for evaluation processing |
nothing calls this directly
no test coverage detected