chemprop.nn.hparams#

Module Contents#

Classes#

HParamsDict

A dictionary containing a module's class and it's hyperparameters

HasHParams

HasHParams is a protocol for clases which possess an hparams attribute which is a dictionary containing the object's class and arguments required to initialize it.

Functions#

from_hparams(hparams)

class chemprop.nn.hparams.HParamsDict[source]#

Bases: TypedDict

A dictionary containing a module’s class and it’s hyperparameters

Using this type should essentially allow for initializing a module via:

module = hparams.pop('cls')(**hparams)
cls: Type#
class chemprop.nn.hparams.HasHParams[source]#

Bases: Protocol

HasHParams is a protocol for clases which possess an hparams attribute which is a dictionary containing the object’s class and arguments required to initialize it.

That is, any object which implements HasHParams should be able to be initialized via:

class Foo(HasHParams):
    def __init__(self, *args, **kwargs):
        ...

foo1 = Foo(...)
foo1_cls = foo1.hparams['cls']
foo1_kwargs = {k: v for k, v in foo1.hparams.items() if k != "cls"}
foo2 = foo1_cls(**foo1_kwargs)
# code to compare foo1 and foo2 goes here and they should be equal
hparams: HParamsDict#
chemprop.nn.hparams.from_hparams(hparams)[source]#
Parameters:

hparams (HParamsDict)