Ejemplo n.º 1
0
    err = AverageMeter('Loss/test')
    ent = AverageMeter('Entropy/test')
    cer = AverageCER(blank, space)
    wer = AverageWER(blank, space)

    with torch.no_grad():

        temperature = 3
        prediction = []
        prior = 0

        for xs, ys, xn, yn in dev:

            xs, xn = model.forward_acoustic(xs, xn)

            xs = model.greedy_decode(xs, argmax=False)

            xs = xs.exp().view(-1, len(labels))

            prediction.append(xs.argmax(1).cpu())
            prior += xs.sum(dim=0)

            dev.set_description('Epoch %d Prior %.5f' % (epoch, prior.std().item()))

        prediction = torch.cat(prediction)
        prior = (prior / prediction.size(0)).log() / temperature

        writer.add_histogram('Prediction', prediction[prediction != labels.blank()], epoch)
        writer.add_histogram('Prior', prior, epoch)

        for xs, ys, xn, yn in test:
Ejemplo n.º 2
0
            ys = ys.cuda(non_blocking=True)
            xn = xn.cuda(non_blocking=True)
            yn = yn.cuda(non_blocking=True)

            zs, xs, xn = model(xs, ys, xn, yn)

            ys = ys.t().contiguous()

            loss = rnnt_loss(zs,
                             ys,
                             xn,
                             yn,
                             average_frames=False,
                             reduction="mean")

            xs = model.greedy_decode(xs)

            err.update(loss.item())
            ent.update(entropy(xs))

            hypothesis = decoder.unpad(xs, xn, labels)
            references = decoder.unpad(ys, yn, labels)

            for h, r in zip(hypothesis, references):
                cer.update(decoder.cer(h, r))
                wer.update(decoder.wer(h, r))

            progress.set_description('epoch %d %s %s %s %s' %
                                     (epoch + 1, err, cer, wer, ent))
        sys.stderr.write('\n')
Ejemplo n.º 3
0
step = 0
writer = SummaryWriter(comment='_rl_bs16x4_beta0.01_lr3e-6')

model.eval()

with torch.no_grad():

    temperature = 3
    prediction = []
    prior = 0

    for xs, ys, xn, yn in dev:

        xs, xn = model.forward_acoustic(xs, xn)

        xs = model.greedy_decode(xs, argmax=False)

        xs = xs.exp().view(-1, len(labels))

        prediction.append(xs.argmax(1).cpu())
        prior += xs.sum(dim=0)

        dev.set_description('Prior %.5f' % (prior.std().item()))

    prediction = torch.cat(prediction)
    prior = (prior / prediction.size(0)).log() / temperature

for epoch in range(1, 11):

    train.shuffle(epoch)