def sample(self, first=1, nchars=0, stop=(- 1)):
    res = [first]
    dy.renew_cg()
    state = self.builder.initial_state()
    R = dy.parameter(self.R)
    bias = dy.parameter(self.bias)
    cw = first
    while True:
        x_t = dy.lookup(self.lookup, cw)
        state = state.add_input(x_t)
        y_t = state.output()
        r_t = (bias + (R * y_t))
        ydist = dy.softmax(r_t)
        dist = ydist.vec_value()
        rnd = random.random()
        for (i, p) in enumerate(dist):
            rnd -= p
            if (rnd <= 0):
                break
        res.append(i)
        cw = i
        if (cw == stop):
            break
        if (nchars and (len(res) > nchars)):
            break
    return res
def sample(self, first=1, nchars=0, stop=(- 1)):
    res = [first]
    dy.renew_cg()
    state = self.builder.initial_state()
    R = dy.parameter(self.R)
    bias = dy.parameter(self.bias)
    cw = first
    while True:
        x_t = dy.lookup(self.lookup, cw)
        state = state.add_input(x_t)
        y_t = state.output()
        r_t = (bias + (R * y_t))
        ydist = dy.softmax(r_t)
        dist = ydist.vec_value()
        rnd = random.random()
        for (i, p) in enumerate(dist):
            rnd -= p
            if (rnd <= 0):
                break
        res.append(i)
        cw = i
        if (cw == stop):
            break
        if (nchars and (len(res) > nchars)):
            break
    return res