matchzoo.engine.param_table
¶
Parameters table class.
Module Contents¶
Classes¶
Parameter table class. |
-
class
matchzoo.engine.param_table.
ParamTable
¶ Bases:
object
Parameter table class.
Example
>>> params = ParamTable() >>> params.add(Param('ham', 'Parma Ham')) >>> params.add(Param('egg', 'Over Easy')) >>> params['ham'] 'Parma Ham' >>> params['egg'] 'Over Easy' >>> print(params) ham Parma Ham egg Over Easy >>> params.add(Param('egg', 'Sunny side Up')) Traceback (most recent call last): ... ValueError: Parameter named egg already exists. To re-assign parameter egg value, use `params["egg"] = value` instead.
-
add
(self, param: Param)¶ - Parameters
param – parameter to add.
-
get
(self, key) → Param¶ - Returns
The parameter in the table named key.
-
set
(self, key, param: Param)¶ Set key to parameter param.
-
property
hyper_space
(self) → dict¶ - Returns
Hyper space of the table, a valid hyperopt graph.
-
to_frame
(self) → pd.DataFrame¶ Convert the parameter table into a pandas data frame.
- Returns
A pandas.DataFrame.
Example
>>> import matchzoo as mz >>> table = mz.ParamTable() >>> table.add(mz.Param(name='x', value=10, desc='my x')) >>> table.add(mz.Param(name='y', value=20, desc='my y')) >>> table.to_frame() Name Description Value Hyper-Space 0 x my x 10 None 1 y my y 20 None
-
__getitem__
(self, key: str) → typing.Any¶ - Returns
The value of the parameter in the table named key.
-
__setitem__
(self, key: str, value: typing.Any)¶ Set the value of the parameter named key.
- Parameters
key – Name of the parameter.
value – New value of the parameter to set.
-
__str__
(self)¶ - Returns
Pretty formatted parameter table.
-
__iter__
(self) → typing.Iterator¶ - Returns
A iterator that iterates over all parameter instances.
-
completed
(self, exclude: typing.Optional[list] = None) → bool¶ Check if all params are filled.
- Parameters
exclude – List of names of parameters that was excluded from being computed.
- Returns
True if all params are filled, False otherwise.
Example
>>> import matchzoo >>> model = matchzoo.models.DenseBaseline() >>> model.params.completed( ... exclude=['task', 'out_activation_func', 'embedding', ... 'embedding_input_dim', 'embedding_output_dim'] ... ) True
-
keys
(self) → collections.abc.KeysView¶ - Returns
Parameter table keys.
-
__contains__
(self, item)¶ - Returns
True if parameter in parameters.
-
update
(self, other: dict)¶ Update self.
Update self with the key/value pairs from other, overwriting existing keys. Notice that this does not add new keys to self.
This method is usually used by models to obtain useful information from a preprocessor’s context.
- Parameters
other – The dictionary used update.
Example
>>> import matchzoo as mz >>> model = mz.models.DenseBaseline() >>> prpr = model.get_default_preprocessor() >>> _ = prpr.fit(mz.datasets.toy.load_data(), verbose=0) >>> model.params.update(prpr.context)
-