Skip to content

Commit e31bbc9

Browse files
author
Timur Gilmullin
committed
#14: refactor bidirectional.py
1 parent 492ee27 commit e31bbc9

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

pybrain/structure/networks/bidirectional.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
__author__ = 'Tom Schaul, tom@idsia.ch'
1+
# -*- coding: utf-8 -*-
22

33
from pybrain.structure.modules import TanhLayer, SigmoidLayer
44
from pybrain.structure.networks.feedforward import FeedForwardNetwork
55
from pybrain.structure.connections.shared import MotherConnection, SharedFullConnection
66
from pybrain.structure.modules.linearlayer import LinearLayer
77
from pybrain.structure.modulemesh import ModuleMesh
88

9+
__author__ = 'Tom Schaul, tom@idsia.ch'
10+
911

1012
class 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

Comments
 (0)