1- __author__ = 'Tom Schaul, tom@idsia.ch'
1+ # -*- coding: utf-8 -*-
22
33from pybrain .structure .modules import TanhLayer , SigmoidLayer
44from pybrain .structure .networks .feedforward import FeedForwardNetwork
55from pybrain .structure .connections .shared import MotherConnection , SharedFullConnection
66from pybrain .structure .modules .linearlayer import LinearLayer
77from pybrain .structure .modulemesh import ModuleMesh
88
9+ __author__ = 'Tom Schaul, tom@idsia.ch'
10+
911
1012class BidirectionalNetwork (FeedForwardNetwork ):
1113 """ A bi-directional recurrent neural network, implemented as unfolded in time. """
@@ -31,15 +33,16 @@ class BidirectionalNetwork(FeedForwardNetwork):
3133 #: length of the sequences
3234 seqlen = None
3335
34- def __init__ (self , predefined = None , ** kwargs ):
36+ def __init__ (self , predefined = None , ** kwargs ):
3537 """ For the current implementation, the sequence length
3638 needs to be fixed, and given at construction time. """
3739 if predefined is not None :
3840 self .predefined = predefined
3941 else :
4042 self .predefined = {}
4143 FeedForwardNetwork .__init__ (self , ** kwargs )
42- assert self .seqlen is not None
44+ if self .seqlen is None :
45+ raise Exception ("seqlen must be not None!" )
4346
4447 # the input is a 1D-mesh (as a view on a flat input layer)
4548 inmod = LinearLayer (self .inputsize * self .seqlen , name = 'input' )
@@ -90,5 +93,3 @@ def __init__(self, predefined = None, **kwargs):
9093 self .addConnection (SharedFullConnection (backwardconn , hiddenmesh [(1 , i + 1 )], hiddenmesh [(1 , i )]))
9194
9295 self .sortModules ()
93-
94-
0 commit comments