Module¶
toydl.core.module.Module ¶
Module()
Modules form a tree that store parameters and other submodules. They make up the basis of neural network stacks.
Source code in toydl/core/module.py
13 14 15 16 |
|
add_parameter ¶
add_parameter(k: str, v: Scalar)
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
56 57 58 59 60 61 62 63 64 65 66 |
|
eval ¶
eval()
Set the mode of this module and all descendant modules to eval
.
Source code in toydl/core/module.py
28 29 30 31 32 |
|
modules ¶
modules()
Return the direct child modules of this module.
Source code in toydl/core/module.py
18 19 20 |
|
named_parameters ¶
named_parameters()
Collect all the parameters of this module and its descendants.
Returns:
Type | Description |
---|---|
Contains the name and :class: |
Source code in toydl/core/module.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
parameters ¶
parameters()
Enumerate over all the parameters of this module and its descendants.
Source code in toydl/core/module.py
51 52 53 54 |
|
train ¶
train()
Set the mode of this module and all descendant modules to train
.
Source code in toydl/core/module.py
22 23 24 25 26 |
|
toydl.core.module.Parameter ¶
Parameter(value: Scalar, name: Optional[str] = None)
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 |
Optional[str]
|
the name of parameter |
None
|
Source code in toydl/core/module.py
98 99 100 101 102 103 104 105 106 107 108 |
|
update ¶
update(x: Any)
Update the parameter value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
Any
|
the parameter's new value |
required |
Source code in toydl/core/module.py
110 111 112 113 114 115 |
|