lamp.nn.GenericModule
See theGenericModule companion object
Base type of modules
Modules are functions of type (Seq[lamp.autograd.Constant],A) => B
, where the Seq[lamp.autograd.Constant]
arguments are optimizable parameters and A
is a non-optimizable input.
Modules provide a way to build composite functions while also keep track of the parameter list of the composite function.
===Example===
case object Weights extends LeafTag
case object Bias extends LeafTag
case class Linear(weights: Constant, bias: Option[Constant]) extends Module {
override val state = List(
weights -> Weights
) ++ bias.toList.map(b => (b, Bias))
def forward[S: Sc](x: Variable): Variable = {
val v = x.mm(weights)
bias.map(_ + v).getOrElse(v)
}
}
Some other attributes of modules are attached by type classes e.g. with the nn.TrainingMode, nn.Load type classes.
Type parameters
- A
-
the argument type of the module
- B
-
the value type of the module
Attributes
- See also
-
nn.Module is an alias for simple
Variable => Variable
modules - Companion
- object
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
class BertEncoderclass BertLossclass BertPretrainModuleclass GraphAttentionclass LanguageModelLossclass LanguageModelModuleclass MultiheadAttentionclass Transformerclass TransformerDecoderclass TransformerDecoderBlockclass TransformerEmbeddingclass TransformerEncoderclass TransformerEncoderBlock
Members list
In this article