trait GenericModule[A, B] extends AnyRef
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.
- A
the argument type of the module
- B
the value type of the module
- See also
nn.Module is an alias for simple
Variable => Variable
modules
- Alphabetic
- By Inheritance
- GenericModule
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Abstract Value Members
- abstract def forward[S](x: A)(implicit arg0: Sc[S]): B
The implementation of the function.
The implementation of the function.
In addition of
x
it can also use all thestate to compute its value.
- abstract def state: Seq[(Constant, PTag)]
List of optimizable, or non-optimizable, but stateful parameters
List of optimizable, or non-optimizable, but stateful parameters
Stateful means that the state is carried over the repeated forward calls.
Concrete Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def apply[S](a: A)(implicit arg0: Sc[S]): B
Alias of forward
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @IntrinsicCandidate() @native()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @IntrinsicCandidate() @native()
- final def gradients(loss: Variable, zeroGrad: Boolean = true): Seq[Option[STen]]
Computes the gradient of loss with respect to the parameters.
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @IntrinsicCandidate() @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def learnableParameters: Long
Returns the total number of optimizable parameters.
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @IntrinsicCandidate() @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @IntrinsicCandidate() @native()
- final def parameters: Seq[(Constant, PTag)]
Returns the state variables which need gradient computation.
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def zeroGrad(): Unit
Deprecated Value Members
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated
- Deprecated
(Since version 9)