Skip to content
This repository was archived by the owner on Aug 25, 2024. It is now read-only.

Commit 9faebdf

Browse files
programmer290399pdxjohnny
authored andcommitted
model: Renamed directory property to location
1 parent 2d4360a commit 9faebdf

File tree

143 files changed

+465
-468
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+465
-468
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323
- Calls to hashlib now go through helper functions
2424
- Build docs using `dffml service dev docs`
2525
- `cached_download/unpack_archive()` are now functions
26+
- Model `directory` property to `location`
2627
### Fixed
2728
- Record object key properties are now always strings
2829

dffml/high_level.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ async def train(model, *args: Union[BaseSource, Record, Dict[str, Any]]):
381381
... Feature("Years", int, 1),
382382
... ),
383383
... predict=Feature("Salary", int, 1),
384-
... directory="tempdir",
384+
... location="tempdir",
385385
... )
386386
>>>
387387
>>> async def main():
@@ -443,7 +443,7 @@ async def accuracy(
443443
... Feature("Years", int, 1),
444444
... ),
445445
... predict=Feature("Salary", int, 1),
446-
... directory="tempdir",
446+
... location="tempdir",
447447
... )
448448
>>>
449449
>>> async def main():
@@ -513,7 +513,7 @@ async def predict(
513513
... Feature("Years", int, 1),
514514
... ),
515515
... predict=Feature("Salary", int, 1),
516-
... directory="tempdir",
516+
... location="tempdir",
517517
... )
518518
>>>
519519
>>> async def main():

dffml/model/model.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ModelNotTrained(Exception):
2929

3030
@config
3131
class ModelConfig:
32-
directory: str
32+
location: str
3333
features: Features
3434

3535

@@ -80,28 +80,28 @@ def __init__(self, config):
8080
# TODO Just in case its a string. We should make it so that on
8181
# instantiation of an @config we convert properties to their correct
8282
# types.
83-
directory = getattr(self.config, "directory", None)
84-
if isinstance(directory, str):
85-
directory = pathlib.Path(directory)
86-
if isinstance(directory, pathlib.Path):
87-
# to treat "~" as the the home directory rather than a literal
88-
directory = directory.expanduser().resolve()
89-
self.config.directory = directory
83+
location = getattr(self.config, "location", None)
84+
if isinstance(location, str):
85+
location = pathlib.Path(location)
86+
if isinstance(location, pathlib.Path):
87+
# to treat "~" as the the home location rather than a literal
88+
location = location.expanduser().resolve()
89+
self.config.location = location
9090

9191
def __call__(self) -> ModelContext:
92-
self._make_config_directory()
92+
self._make_config_location()
9393
return self.CONTEXT(self)
9494

95-
def _make_config_directory(self):
95+
def _make_config_location(self):
9696
"""
97-
If the config object for this model contains the directory property
97+
If the config object for this model contains the location property
9898
then create it if it does not exist.
9999
"""
100-
directory = getattr(self.config, "directory", None)
101-
if directory is not None:
102-
directory = pathlib.Path(directory)
103-
if not directory.is_dir():
104-
directory.mkdir(mode=MODE_BITS_SECURE, parents=True)
100+
location = getattr(self.config, "location", None)
101+
if location is not None:
102+
location = pathlib.Path(location)
103+
if not location.is_dir():
104+
location.mkdir(mode=MODE_BITS_SECURE, parents=True)
105105

106106

107107
class SimpleModelNoContext:
@@ -131,7 +131,7 @@ async def __aenter__(self) -> Model:
131131
# If we've already entered the model's context once, don't reload
132132
if self._in_context > 1:
133133
return self
134-
self._make_config_directory()
134+
self._make_config_location()
135135
self.open()
136136
return self
137137

@@ -171,20 +171,20 @@ def close(self):
171171
def disk_path(self, extention: Optional[str] = None):
172172
"""
173173
We do this for convenience of the user so they can usually just use the
174-
default directory and if they train models with different parameters
174+
default location and if they train models with different parameters
175175
this method transparently to the user creates a filename unique the that
176176
configuration of the model where data is saved and loaded.
177177
"""
178178
# Export the config to a dictionary
179179
exported = self.config._asdict()
180-
# Remove the directory from the exported dict
181-
if "directory" in exported:
182-
del exported["directory"]
180+
# Remove the location from the exported dict
181+
if "location" in exported:
182+
del exported["location"]
183183
# Replace features with the sorted list of features
184184
if "features" in exported:
185185
exported["features"] = dict(sorted(exported["features"].items()))
186186
# Hash the exported config
187-
return pathlib.Path(self.config.directory, "Model",)
187+
return pathlib.Path(self.config.location, "Model",)
188188

189189
def applicable_features(self, features):
190190
usable = []

dffml/model/slr.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def best_fit_line(x, y):
5050
class SLRModelConfig:
5151
predict: Feature = field("Label or the value to be predicted")
5252
features: Features = field("Features to train on. For SLR only 1 allowed")
53-
directory: pathlib.Path = field("Directory where state should be saved")
53+
location: pathlib.Path = field("Location where state should be saved")
5454

5555

5656
@entrypoint("slr")
@@ -82,7 +82,7 @@ class SLRModel(SimpleModel):
8282
-model slr \
8383
-model-features f1:float:1 \
8484
-model-predict ans:int:1 \
85-
-model-directory tempdir \
85+
-model-location tempdir \
8686
-sources f=csv \
8787
-source-filename dataset.csv
8888
@@ -95,7 +95,7 @@ class SLRModel(SimpleModel):
9595
-model slr \
9696
-model-features f1:float:1 \
9797
-model-predict ans:int:1 \
98-
-model-directory tempdir \
98+
-model-location tempdir \
9999
-sources f=csv \
100100
-source-filename dataset.csv
101101
1.0
@@ -118,7 +118,7 @@ class SLRModel(SimpleModel):
118118
-model slr \
119119
-model-features f1:float:1 \
120120
-model-predict ans:int:1 \
121-
-model-directory tempdir \
121+
-model-location tempdir \
122122
-sources f=csv \
123123
-source-filename predict.csv
124124
[

dffml/operation/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ async def model_predict(self, features: Dict[str, Any]) -> Dict[str, Any]:
6161
>>> slr_model = SLRModel(
6262
... features=Features(Feature("Years", int, 1)),
6363
... predict=Feature("Salary", int, 1),
64-
... directory="tempdir",
64+
... location="tempdir",
6565
... )
6666
>>> dataflow = DataFlow(
6767
... operations={

dffml/skel/model/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ sed -i 's/.*setosa,versicolor,virginica/SepalLength,SepalWidth,PetalLength,Petal
1818
head iris_training.csv
1919
dffml train \
2020
-model model_name \
21-
-model-directory tempdir \
21+
-model-location tempdir \
2222
-sources csv=iris_training.csv \
2323
-classifications 0 1 2 \
2424
-model-features \
@@ -31,7 +31,7 @@ dffml train \
3131
-log debug
3232
dffml accuracy \
3333
-model model_name \
34-
-model-directory tempdir \
34+
-model-location tempdir \
3535
-sources csv=iris_training.csv \
3636
-classifications 0 1 2 \
3737
-model-features \
@@ -42,7 +42,7 @@ dffml accuracy \
4242
-log critical
4343
dffml predict all \
4444
-model model_name \
45-
-model-directory tempdir \
45+
-model-location tempdir \
4646
-sources csv=iris_test.csv \
4747
-classifications 0 1 2 \
4848
-model-features \

dffml/skel/model/REPLACE_IMPORT_PACKAGE_NAME/myslr.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class MySLRModelConfig:
6060
"Features to train on (myslr only supports one)"
6161
)
6262
predict: Feature = field("Label or the value to be predicted")
63-
directory: pathlib.Path = field("Directory where state should be saved")
63+
location: pathlib.Path = field("Location where state should be saved")
6464

6565

6666
@entrypoint("myslr")
@@ -105,7 +105,7 @@ class MySLRModel(SimpleModel):
105105
-model myslr \
106106
-model-features x:float:1 \
107107
-model-predict y:int:1 \
108-
-model-directory tempdir \
108+
-model-location tempdir \
109109
-sources f=csv \
110110
-source-filename train.csv
111111
@@ -118,7 +118,7 @@ class MySLRModel(SimpleModel):
118118
-model myslr \
119119
-model-features x:float:1 \
120120
-model-predict y:int:1 \
121-
-model-directory tempdir \
121+
-model-location tempdir \
122122
-sources f=csv \
123123
-source-filename test.csv
124124
1.0
@@ -141,7 +141,7 @@ class MySLRModel(SimpleModel):
141141
-model myslr \
142142
-model-features x:float:1 \
143143
-model-predict y:int:1 \
144-
-model-directory tempdir \
144+
-model-location tempdir \
145145
-sources f=csv \
146146
-source-filename predict.csv
147147
[

dffml/skel/model/examples/example_myslr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
model = MySLRModel(
77
features=Features(Feature("x", float, 1)),
88
predict=Feature("y", int, 1),
9-
directory="tempdir",
9+
location="tempdir",
1010
)
1111

1212
# Train the model

dffml/skel/model/tests/test_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def setUpClass(cls):
4343
cls.model = MySLRModel(
4444
features=Features(Feature("X", float, 1)),
4545
predict=Feature("Y", float, 1),
46-
directory=cls.model_dir.name,
46+
location=cls.model_dir.name,
4747
)
4848

4949
@classmethod

docs/examples/icecream_sales.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ and the output being sales.
142142
-model-hidden 9 18 9 \
143143
-model-features population:int:1 temperature:float:1 \
144144
-model-predict sales:int:1 \
145-
-model-directory tempdir \
145+
-model-location tempdir \
146146
-sources f=csv \
147147
-source-filename preprocessed.csv \
148148
-log debug
@@ -163,7 +163,7 @@ using the accuracy method.
163163
-model-hidden 9 18 9 \
164164
-model-features population:int:1 temperature:float:1 \
165165
-model-predict sales:int:1 \
166-
-model-directory tempdir \
166+
-model-location tempdir \
167167
-sources f=csv \
168168
-source-filename preprocessed.csv \
169169
-log debug
@@ -188,7 +188,7 @@ for the prediction of sales.
188188
-model-hidden 9 18 9 \
189189
-model-features population:int:1 temperature:float:1 \
190190
-model-predict sales:int:1 \
191-
-model-directory tempdir \
191+
-model-location tempdir \
192192
-sources preprocess=df \
193193
-source-preprocess-dataflow preprocess_ops.json \
194194
-source-preprocess-features city:str:1 state:str:1 month:int:1 \

docs/tutorials/dataflows/nlp.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ We can now use this dataflow to preprocess the data and make it ready to be fed
107107
-model-clstype int \
108108
-model-predict sentiment:int:1 \
109109
-model-classifications 0 1 \
110-
-model-directory tempdir \
110+
-model-location tempdir \
111111
-model-features embedding:float:[1,10,96] \
112112
-sources text=df \
113113
-source-text-dataflow nlp_ops_dataflow.json \
@@ -132,7 +132,7 @@ Assess accuracy:
132132
-model-clstype int \
133133
-model-predict sentiment:int:1 \
134134
-model-classifications 0 1 \
135-
-model-directory tempdir \
135+
-model-location tempdir \
136136
-model-features embedding:float:[1,10,96] \
137137
-sources text=df \
138138
-source-text-dataflow nlp_ops_dataflow.json \
@@ -165,7 +165,7 @@ Make prediction on test data:
165165
-model-clstype int \
166166
-model-predict sentiment:int:1 \
167167
-model-classifications 0 1 \
168-
-model-directory tempdir \
168+
-model-location tempdir \
169169
-model-features embedding:float:[1,10,96] \
170170
-sources text=df \
171171
-source-text-dataflow nlp_ops_dataflow.json \
@@ -273,7 +273,7 @@ We can now use this dataflow to preprocess the data and make it ready to be fed
273273
-model scikitgnb \
274274
-model-features extract_array_from_matrix.outputs.result:float:1 \
275275
-model-predict sentiment:int:1 \
276-
-model-directory tempdir \
276+
-model-location tempdir \
277277
-sources text=df \
278278
-source-text-dataflow nlp_ops_dataflow.json \
279279
-source-text-features sentence:str:1 \
@@ -290,7 +290,7 @@ Assess accuracy:
290290
-model scikitgnb \
291291
-model-features extract_array_from_matrix.outputs.result:float:1 \
292292
-model-predict sentiment:int:1 \
293-
-model-directory tempdir \
293+
-model-location tempdir \
294294
-sources text=df \
295295
-source-text-dataflow nlp_ops_dataflow.json \
296296
-source-text-features sentence:str:1 \
@@ -348,7 +348,7 @@ Now we can make prediction on test data:
348348
-model scikitgnb \
349349
-model-features extract_array_from_matrix.outputs.result:float:1 \
350350
-model-predict sentiment:int:1 \
351-
-model-directory tempdir \
351+
-model-location tempdir \
352352
-sources temp=json \
353353
-source-temp-filename test_data_preprocessed.json \
354354
-pretty

docs/tutorials/models/load.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ dataclass using the :py:func:`dataclasses.fields` function.
3232
<class 'dffml.model.slr.SLRModel'>
3333
predict: Label or the value to be predicted
3434
features: Features to train on. For SLR only 1 allowed
35-
directory: Directory where state should be saved
35+
location: Location where state should be saved

docs/tutorials/models/package.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ reference it by it's short name.
257257
-model myslr \
258258
-model-features Years:int:1 \
259259
-model-predict Salary:float:1 \
260-
-model-directory modeldir \
260+
-model-location modeldir \
261261
-sources f=csv \
262262
-source-filename train.csv
263263

docs/tutorials/models/slr.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ We do the same steps we did with Python, only using the command line interface.
245245
-model myslr:MySLRModel \
246246
-model-features Years:int:1 \
247247
-model-predict Salary:float:1 \
248-
-model-directory modeldir \
248+
-model-location modeldir \
249249
-sources f=csv \
250250
-source-filename train.csv
251251
@@ -260,7 +260,7 @@ Now let's make predictions
260260
-model myslr:MySLRModel \
261261
-model-features Years:int:1 \
262262
-model-predict Salary:float:1 \
263-
-model-directory modeldir \
263+
-model-location modeldir \
264264
-sources f=csv \
265265
-source-filename predict.csv
266266
[
@@ -311,7 +311,7 @@ via the HTTP :ref:`plugin_service_http_api_model` API.
311311
-models mymodel=myslr:MySLRModel \
312312
-model-features Years:int:1 \
313313
-model-predict Salary:float:1 \
314-
-model-directory modeldir
314+
-model-location modeldir
315315
316316
We can then ask the HTTP service to make predictions, or do training or accuracy
317317
assessment.

examples/MNIST/accuracy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ dffml accuracy \
44
-model-hidden 30 50 25 \
55
-model-clstype int \
66
-model-predict label:int:1 \
7-
-model-directory tempdir \
7+
-model-location tempdir \
88
-model-classifications $(seq 0 9) \
99
-model-features image:int:$((28 * 28)) \
1010
-sources images=df label=idx1 \

examples/MNIST/predict.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ dffml predict all \
44
-model-hidden 30 50 25 \
55
-model-clstype int \
66
-model-predict label:int:1 \
7-
-model-directory tempdir \
7+
-model-location tempdir \
88
-model-classifications $(seq 0 9) \
99
-model-features image:int:$((28 * 28)) \
1010
-sources images=df \

examples/MNIST/train.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ dffml train \
55
-model-clstype int \
66
-model-predict label:int:1 \
77
-model-classifications $(seq 0 9) \
8-
-model-directory tempdir \
8+
-model-location tempdir \
99
-model-features image:int:$((28 * 28)) \
1010
-sources images=df label=idx1 \
1111
-source-images-dataflow normalize.yaml \

0 commit comments

Comments
 (0)