Framework Generator
Module for generating synthetic annotated datasets (frameworks) using instruction-tuned models hosted locally and filtering of low-quality examples via classifier agreement.
Attributes:
Name | Type | Description |
---|---|---|
model_name |
str
|
Name of the local model loaded in LM Studio and referenced in generation requests (default: "llama-3.2-3b-instruct"). |
api_url |
str
|
Full URL of the locally hosted LM Studio API endpoint that handles generation requests. This includes the server host, port, and path (default: "http://localhost:1234/v1/completions"). |
Methods:
Name | Description |
---|---|
generate_framework |
Simulates a dialogue and returns it as a pandas DataFrame. |
filter_with_classifier |
Filters the generated dataset using a small classifier trained on real labeled data. |
Source code in src/educhateval/core.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
|
generate_framework(prompt_path=None, prompt_dict_input=None, num_samples=500, json_out=None, csv_out=None, seed=42, temperature=0.85, top_p=0.9)
Generate a synthetic labeled dataset from prompts using a language model.
Either prompt_path
(path to .py file with prompt_dict
) or prompt_dict_input
must be provided.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt_path
|
str
|
Path to a Python file containing a prompt dictionary. |
None
|
prompt_dict_input
|
dict
|
Prompt dictionary directly provided. |
None
|
num_samples
|
int
|
Number of samples to generate per category. |
500
|
json_out
|
str
|
Optional path to save JSON output. |
None
|
csv_out
|
str
|
Optional path to save CSV output. |
None
|
seed
|
int
|
Random seed for reproducibility. |
42
|
temperature
|
float
|
Sampling temperature for generation. |
0.85
|
top_p
|
float
|
Top-p sampling parameter. |
0.9
|
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: Cleaned, labeled synthetic dataset. |
Source code in src/educhateval/core.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
filter_with_classifier(train_data, synth_data, text_column='text', label_column='category', split_ratio=0.2, training_params=[0.01, 'cross_entropy', 5e-05, 8, 8, 4, 0.01], tuning=False, tuning_params=None, model_save_path=None, classifier_model_name='distilbert-base-uncased', filtered_save_path=None)
Train a small classifier on real labeled data and use it to filter the synthetic dataset by agreement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
train_data
|
str or DataFrame
|
Path or DataFrame of small labeled training set. |
required |
synth_data
|
str or DataFrame
|
Path or DataFrame of generated synthetic dataset. |
required |
text_column
|
str
|
Name of the text column. |
'text'
|
label_column
|
str
|
Name of the label column. |
'category'
|
split_ratio
|
float
|
Ratio for train/test split. |
0.2
|
training_params
|
list
|
Training hyperparameters. |
[0.01, 'cross_entropy', 5e-05, 8, 8, 4, 0.01]
|
tuning
|
bool
|
Whether to perform hyperparameter tuning using Optuna. |
False
|
tuning_params
|
dict
|
Optional tuning grid. |
None
|
model_save_path
|
str
|
Optional path to save the classifier model. |
None
|
classifier_model_name
|
str
|
HF model ID for the classifier. |
'distilbert-base-uncased'
|
filtered_save_path
|
str
|
Optional path to save filtered synthetic dataset. |
None
|
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: Filtered synthetic dataset based on classifier agreement. |
Source code in src/educhateval/core.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
|