human
Complete this python program:
def accuracy(inpt_t, output, target_t, batch_size, nprint, beam_out=None, beam_scores=None):
assistant
#Here is the Python program you requested.

    """Calculate output accuracy given target.
    """
    assert (nprint < (batch_size + 1))
    inpt = []
    for h in xrange(inpt_t.shape[1]):
        inpt.extend([inpt_t[:, h, l] for l in xrange(inpt_t.shape[2])])
    target = [target_t[:, 0, l] for l in xrange(target_t.shape[2])]
    def tok(i):
        if (rev_vocab and (i < len(rev_vocab))):
            return rev_vocab[i]
        return str((i - 1))
    def task_print(inp, output, target):
        stop_bound = 0
        print_len = 0
        while ((print_len < len(target)) and (target[print_len] > stop_bound)):
            print_len += 1
        print_out(('                i:    ' + '    '.join([tok(i) for i in inp if (i > 0)])))
        print_out(('                o:    ' + '    '.join([tok(output[l]) for l in xrange(print_len)])))
        print_out(('                t:    ' + '    '.join([tok(target[l]) for l in xrange(print_len)])))
    decoded_target = target
    decoded_output = decode(output)
    if (beam_out is not None):
        for b in xrange(batch_size):
            if (beam_scores[b] >= 10.0):
                for l in xrange(min(len(decoded_output), beam_out.shape[2])):
                    decoded_output[l][b] = int(beam_out[(b, 0, l)])
    total = 0
    errors = 0
    seq = [0 for b in xrange(batch_size)]
    for l in xrange(len(decoded_output)):
        for b in xrange(batch_size):
            if (decoded_target[l][b] > 0):
                total += 1
                if (decoded_output[l][b] != decoded_target[l][b]):
                    seq[b] = 1
                    errors += 1
    e = 0
    for _ in xrange(min(nprint, sum(seq))):
        while (seq[e] == 0):
            e += 1
        task_print([inpt[l][e] for l in xrange(len(inpt))], [decoded_output[l][e] for l in xrange(len(decoded_target))], [decoded_target[l][e] for l in xrange(len(decoded_target))])
        e += 1
    for b in xrange((nprint - errors)):
        task_print([inpt[l][b] for l in xrange(len(inpt))], [decoded_output[l][b] for l in xrange(len(decoded_target))], [decoded_target[l][b] for l in xrange(len(decoded_target))])
 ...