Module¶
toydl.core.module.Module
¶
Module()
Modules form a tree that stores parameters and other submodules. They make up the basis of neural network stacks.
Source code in toydl/core/module.py
47 48 49 50 |
|
add_parameter
¶
Manually add a parameter. Useful helper for scalar parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
k
|
str
|
Local name of the parameter. |
required |
v
|
Scalar
|
Value for the parameter. |
required |
Returns:
Type | Description |
---|---|
Newly created parameter. |
Source code in toydl/core/module.py
90 91 92 93 94 95 96 97 98 99 100 |
|
eval
¶
eval()
Set the mode of this module and all descendant modules to eval
.
Source code in toydl/core/module.py
62 63 64 65 66 |
|
modules
¶
modules()
Return the direct child modules of this module.
Source code in toydl/core/module.py
52 53 54 |
|
named_parameters
¶
Collect all the parameters of this module and its descendants.
Returns:
Type | Description |
---|---|
list[tuple[str, Parameter]]
|
Contains the name and :class: |
Source code in toydl/core/module.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
parameters
¶
parameters()
Enumerate over all the parameters of this module and its descendants.
Source code in toydl/core/module.py
85 86 87 88 |
|
train
¶
train()
Set the mode of this module and all descendant modules to train
.
Source code in toydl/core/module.py
56 57 58 59 60 |
|
toydl.core.module.Parameter
¶
A Parameter is a special container stored in a :class:Module
.
It is designed to hold a :class:Variable
, but we allow it to hold
any value for testing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
Scalar
|
the value of parameter |
required |
name
|
str | None
|
the name of parameter |
None
|
Source code in toydl/core/module.py
14 15 16 17 18 19 20 21 22 23 24 |
|
update
¶
update(x: Scalar) -> None
Update the parameter value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Scalar
|
the parameter's new value |
required |
Source code in toydl/core/module.py
26 27 28 29 30 31 |
|