'inputs,errors are both list of integers.
returns the hidden states and gradients on model parameters'

def lossFun(self, inputs, errors):

    (xs, hs) = ({}, {})
    hs[(-1)] = np.zeros((self.hidden_size, 1))
    seq_len = len(inputs)
    hs_list = np.zeros((self.hidden_size, seq_len))
    nin = inputs[0].shape[0]
    for t in range(seq_len):
        xs[t] = np.matrix(inputs[t])
        hs[t] = np.tanh(((np.dot(self.Wxh, xs[t]) + np.dot(self.Whh, hs[(t - 1)])) + self.bh))
        hs_list[:, t] = hs[t].flatten()
    dhnext = np.zeros_like(hs[0])
    dWxh = np.zeros_like(self.Wxh)
    dWhh = np.zeros_like(self.Whh)
    dbh = np.zeros_like(self.bh)
    dh_list = errors
    dh_list_out = np.zeros_like(dh_list)
    dout_list = np.zeros((nin, seq_len))
    for t in reversed(range(seq_len)):
        dh = (dh_list[t] + dhnext)
        dh_list_out[t] = dh
        dhraw = np.multiply(dh, (1 - np.square(hs[t])))
        dbh += dhraw
        dWxh += np.dot(dhraw, xs[t].T)
        dWhh += np.dot(dhraw, hs[(t - 1)].T)
        dhnext = np.dot(self.Whh.T, dhraw)
        dout = np.dot(self.Wxh.T, dhraw)
        dout_list[:, t] = dout.flatten()
    return (dWxh, dWhh, dbh, hs_list, dh_list_out, dout_list)
