nemo/collections/asr/helpers.py
def monitor_asr_train_progress(tensors: list, labels: list, eval_metric='WER', tb_logger=None):
    """
    Takes output of greedy ctc decoder and performs ctc decoding algorithm to
    remove duplicates and special symbol. Prints sample to screen, computes
    and logs AVG WER to console and (optionally) Tensorboard
    Args:
      tensors: A list of 3 tensors (predictions, targets, target_lengths)
      labels: A list of labels
      eval_metric: An optional string from 'WER', 'CER'. Defaults to 'WER'.
      tb_logger: Tensorboard logging object
    Returns:
      None
    """
    references = []

    labels_map = dict([(i, labels[i]) for i in range(len(labels))])
    with torch.no_grad():
        # prediction_cpu_tensor = tensors[0].long().cpu()
        targets_cpu_tensor = tensors[2].long().cpu()
        tgt_lenths_cpu_tensor = tensors[3].long().cpu()

        # iterate over batch
        for ind in range(targets_cpu_tensor.shape[0]):
            tgt_len = tgt_lenths_cpu_tensor[ind].item()
            target = targets_cpu_tensor[ind][:tgt_len].numpy().tolist()
            reference = ''.join([labels_map[c] for c in target])
            references.append(reference)
        hypotheses = __ctc_decoder_predictions_tensor(tensors[1], labels=labels)

    eval_metric = eval_metric.upper()
    if eval_metric not in {'WER', 'CER'}:
        raise ValueError('eval_metric must be \'WER\' or \'CER\'')
    use_cer = True if eval_metric == 'CER' else False

    tag = f'training_batch_{eval_metric}'
    wer = word_error_rate(hypotheses, references, use_cer=use_cer)
    if tb_logger is not None:
        tb_logger.add_scalar(tag, wer)
    logging.info(f'Loss: {tensors[0]}')
    logging.info(f'{tag}: {wer * 100 : 5.2f}%')
    logging.info(f'Prediction: {hypotheses[0]}')
    logging.info(f'Reference: {references[0]}')

    Takes output of greedy ctc decoder and performs ctc decoding algorithm to
    remove duplicates and special symbol. Prints sample to screen, computes
    and logs AVG WER to console and (optionally) Tensorboard
    Args:
      tensors: A list of 3 tensors (predictions, targets, target_lengths)
      labels: A list of labels
      eval_metric: An optional string from 'WER', 'CER'. Defaults to 'WER'.
      tb_logger: Tensorboard logging object
    Returns:
      None
    
Takes output of greedy ctc decoder and performs ctc decoding algorithm to
remove duplicates and special symbol. Prints sample to screen, computes
and logs AVG WER to console and (optionally) Tensorboard
Takes output of greedy ctc decoder and performs ctc decoding algorithm to remove duplicates and special symbol . Prints sample to screen computes and logs AVG WER to console and ( optionally ) Tensorboard
def monitor_asr_train_progress(tensors: list, labels: list, eval_metric='WER', tb_logger=None):
    references = []
    labels_map = dict([(i, labels[i]) for i in range(len(labels))])
    with torch.no_grad():
        targets_cpu_tensor = tensors[2].long().cpu()
        tgt_lenths_cpu_tensor = tensors[3].long().cpu()
        for ind in range(targets_cpu_tensor.shape[0]):
            tgt_len = tgt_lenths_cpu_tensor[ind].item()
            target = targets_cpu_tensor[ind][:tgt_len].numpy().tolist()
            reference = ''.join([labels_map[c] for c in target])
            references.append(reference)
        hypotheses = __ctc_decoder_predictions_tensor(tensors[1], labels=labels)
    eval_metric = eval_metric.upper()
    if eval_metric not in {'WER', 'CER'}:
        raise ValueError('eval_metric must be \'WER\' or \'CER\'')
    use_cer = True if eval_metric == 'CER' else False
    tag = f'training_batch_{eval_metric}'
    wer = word_error_rate(hypotheses, references, use_cer=use_cer)
    if tb_logger is not None:
        tb_logger.add_scalar(tag, wer)
    logging.info(f'Loss: {tensors[0]}')
    logging.info(f'{tag}: {wer * 100 : 5.2f}%')
    logging.info(f'Prediction: {hypotheses[0]}')
    logging.info(f'Reference: {references[0]}')
def monitor_asr_train_progress ( tensors : list , labels : list , eval_metric = 'WER' , tb_logger = None ) : references = [ ] labels_map = dict ( [ ( i , labels [ i ] ) for i in range ( len ( labels ) ) ] ) with torch . no_grad ( ) : targets_cpu_tensor = tensors [ 2 ] . long ( ) . cpu ( ) tgt_lenths_cpu_tensor = tensors [ 3 ] . long ( ) . cpu ( ) for ind in range ( targets_cpu_tensor . shape [ 0 ] ) : tgt_len = tgt_lenths_cpu_tensor [ ind ] . item ( ) target = targets_cpu_tensor [ ind ] [ : tgt_len ] . numpy ( ) . tolist ( ) reference = '' . join ( [ labels_map [ c ] for c in target ] ) references . append ( reference ) hypotheses = __ctc_decoder_predictions_tensor ( tensors [ 1 ] , labels = labels ) eval_metric = eval_metric . upper ( ) if eval_metric not in { 'WER' , 'CER' } : raise ValueError ( 'eval_metric must be \'WER\' or \'CER\'' ) use_cer = True if eval_metric == 'CER' else False tag = f'training_batch_{eval_metric}' wer = word_error_rate ( hypotheses , references , use_cer = use_cer ) if tb_logger is not None : tb_logger . add_scalar ( tag , wer ) logging . info ( f'Loss: {tensors[0]}' ) logging . info ( f'{tag}: {wer * 100 : 5.2f}%' ) logging . info ( f'Prediction: {hypotheses[0]}' ) logging . info ( f'Reference: {references[0]}' )
Takes output of greedy ctc decoder and performs ctc decoding algorithm to
remove duplicates and special symbol.
Takes output of greedy ctc decoder and performs ctc decoding algorithm to remove duplicates and special symbol .
"""
    Takes output of greedy ctc decoder and performs ctc decoding algorithm to
    remove duplicates and special symbol. Prints sample to screen, computes
    and logs AVG WER to console and (optionally) Tensorboard
    Args:
      tensors: A list of 3 tensors (predictions, targets, target_lengths)
      labels: A list of labels
      eval_metric: An optional string from 'WER', 'CER'. Defaults to 'WER'.
      tb_logger: Tensorboard logging object
    Returns:
      None
    """ # prediction_cpu_tensor = tensors[0].long().cpu() # iterate over batch
None
tensors
list
A list of 3 tensors (predictions, targets, target_lengths)
A list of 3 tensors ( predictions targets target_lengths )
labels
list
A list of labels
A list of labels
eval_metric
An optional string from 'WER', 'CER'. Defaults to 'WER'.
An optional string from ' WER ' ' CER ' . Defaults to ' WER ' .
'WER'
tb_logger
Tensorboard logging object
Tensorboard logging object