|
1 | 1 | import pickle |
2 | 2 | from pathlib import Path |
3 | 3 |
|
| 4 | +import confidence |
4 | 5 | from lir.config.lrsystem_architectures import specific_source |
5 | 6 | from lir.data.models import FeatureData |
6 | 7 | from lir.datasets.feature_data_csv import FeatureDataCsvFileParser |
| 8 | +from lir.experiments import Experiment |
7 | 9 | from lir.lrsystems.lrsystems import LRSystem |
| 10 | +from lir.main import initialize_experiments |
8 | 11 |
|
9 | 12 |
|
10 | 13 | def get_lr_system(lr_system_folder: Path, file_name: str = "model.pkl") -> LRSystem: |
@@ -50,6 +53,22 @@ def get_reference_data(lr_system_folder: Path, file_name: str = "reference_data. |
50 | 53 | return FeatureDataCsvFileParser(file=reference_data_file, label_column="hypothesis").get_instances() |
51 | 54 |
|
52 | 55 |
|
| 56 | +def get_validation_experiment(model_name: str, training_data_path: Path, output_path: Path) -> tuple[Experiment, Path]: |
| 57 | + """ |
| 58 | + Return an `Experiment` that builds and validates a model. |
| 59 | +
|
| 60 | + The `lr_system_folder` will be created in `output_path` under the name "model". |
| 61 | + """ |
| 62 | + yaml_file = Path(__file__).parent / "models" / model_name / "validation.yaml" |
| 63 | + yaml_update = { |
| 64 | + "output_path": str(output_path), |
| 65 | + "input_file_path": str(training_data_path), |
| 66 | + } |
| 67 | + cfg = confidence.Configuration(confidence.loadf(yaml_file), yaml_update) |
| 68 | + exps, _ = initialize_experiments(cfg) |
| 69 | + return exps["model"], output_path / "model" |
| 70 | + |
| 71 | + |
53 | 72 | # create an alias for the specific source system, since the architecture is identical but the name is misleading |
54 | 73 | # in the current application |
55 | 74 | binary_lrsystem = specific_source |
0 commit comments