Skip to content

Commit 9fcde3d

Browse files
committed
move experiment configurations to lrsystem module
1 parent ab35721 commit 9fcde3d

5 files changed

Lines changed: 24 additions & 10 deletions

File tree

lrmodule/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import pickle
22
from pathlib import Path
33

4+
import confidence
45
from lir.config.lrsystem_architectures import specific_source
56
from lir.data.models import FeatureData
67
from lir.datasets.feature_data_csv import FeatureDataCsvFileParser
8+
from lir.experiments import Experiment
79
from lir.lrsystems.lrsystems import LRSystem
10+
from lir.main import initialize_experiments
811

912

1013
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.
5053
return FeatureDataCsvFileParser(file=reference_data_file, label_column="hypothesis").get_instances()
5154

5255

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+
5372
# create an alias for the specific source system, since the architecture is identical but the name is misleading
5473
# in the current application
5574
binary_lrsystem = specific_source
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/conftest.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from lir.lrsystems.lrsystems import LRSystem
99
from lir.main import initialize_experiments
1010

11+
from lrmodule import get_validation_experiment
1112

1213
# TEST_FOLDER is a folder that contains packages (folders) with everything relevant for that specific model
1314
# (e.g. reference data, trained model, etc.).
@@ -21,16 +22,10 @@
2122
])
2223
def model_folder(request) -> Path:
2324
TEST_FOLDER.mkdir(exist_ok=True, parents=True)
25+
output_path = TEST_FOLDER / request.param
2426

2527
# Generate models at import time so that TEST_FOLDER is populated before @pytest.mark.parametrize
2628
# evaluates its argument list during collection.
27-
yaml_file = Path('models') / request.param / 'validation.yaml'
28-
yaml_update = {
29-
'output_path': TEST_FOLDER / request.param,
30-
'input_file_path': str(Path('data') / f'{request.param}.csv'),
31-
}
32-
cfg = confidence.Configuration(confidence.loadf(yaml_file), yaml_update)
33-
exps, _ = initialize_experiments(cfg)
34-
for exp in exps.values():
35-
exp.run()
36-
return TEST_FOLDER / request.param / 'model'
29+
exp, output_folder = get_validation_experiment(request.param, Path('data') / f'{request.param}.csv', output_path)
30+
exp.run()
31+
return output_folder

0 commit comments

Comments
 (0)