artefactual.calibration#
Calibration module for artefactual library.
This module exports configuration classes and training functions for calibration.
- class artefactual.calibration.GenerationConfig(**data)[source]#
Bases:
BaseModelConfiguration for entropy dataset generation.
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class artefactual.calibration.RatingConfig(**data)[source]#
Bases:
BaseModelConfiguration for answer rating.
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- artefactual.calibration.clear_gpu_memory(llm)[source]#
Clears GPU memory by destroying the model parallel and distributed environment, deleting the LLM object, and clearing the CUDA cache.
This function is intended to be called after using a vLLM model to free up GPU resources. It handles the destruction of various components created by vLLM and PyTorch for distributed processing.
- Return type:
- Args:
llm (LLM): The vLLM LLM object to be deleted.
- artefactual.calibration.init_llm(model_path, seed)[source]#
Initialize a vLLM LLM instance.
- Return type:
LLM
- Args:
model_path: Path to the model or model identifier. seed: Random seed for initialization.
- Returns:
An initialized LLM object.
- artefactual.calibration.load_tqa_from_json(input_file)[source]#
Load the pack data from a JSON file.
- Args:
input_file (str): Path to the JSON file
- Returns:
List of (question, question_id, short_answer, answer_aliases) tuples.
- artefactual.calibration.save_to_json(data, output_file)[source]#
Save data to a JSON file.
Supports two common use cases: - Dataset-level outputs: A single dict with metadata and results (e.g., entropy datasets) - Item-level outputs: A list of individual item dicts
- Return type:
- Args:
data: Data to save (dict or list of dicts). output_file: Path to the output JSON file.
- artefactual.calibration.train_calibration(input_file, output_file)[source]#
Train a logistic regression model to calibrate uncertainty scores.
- Return type:
- Args:
input_file: Path to the CSV file containing ‘uncertainty_score’ and ‘judgment’. output_file: Path to save the calibration weights (JSON).
Modules
Generate a dataset with entropy scores for model outputs. |
|
|
Train a logistic regression model to calibrate uncertainty scores. |