Beispiel #1
0
    def dec_lstm_cell(self, x, h, c):
        concat = Concat(h, x)

        # Forget Gate
        f_gate = Sigmoid(Add(Dot(concat, self.dwf), self.dbf))
        # Input Gate
        i_gate = Sigmoid(Add(Dot(concat, self.dwi), self.dbi))
        # Temp Vars
        c_temp = Tanh(Add(Dot(concat, self.dwc), self.dbc))
        o_temp = Sigmoid(Add(Dot(concat, self.dwo), self.dbo))

        # Output
        c_next = Add(Mul(f_gate, c), Mul(i_gate, c_temp))
        h_next = Mul(o_temp, Tanh(c_next))
        return h_next, c_next
Beispiel #2
0
    def __init__(self, wf, bf, wi, bi, wc, bc, wo, bo, x, h, c):
        self.wf = wf
        self.bf = bf
        self.wi = wi
        self.bi = bi
        self.wc = wc
        self.bc = bc
        self.wo = wo
        self.bo = bo
        self.x = x
        self.h = h
        self.c = c

        concat = Concat(x, h)
        fgate = Sigmoid(Add(Dot(concat, wf), bf))
        igate = Sigmoid(Add(Dot(concat, wi), bi))
        cgate = Mul(Tanh(Add(Dot(concat, wc), bc)), igate)
        ogate = Sigmoid(Add(Dot(concat, wo), bo))

        self.cout = Add(Mul(c, fgate), cgate)
        self.hout = Mul(Tanh(self.cout), ogate)