mirror of
https://github.com/modelscope/FunASR
synced 2025-09-15 14:48:36 +08:00
Merge pull request #83 from alibaba-damo-academy/dev_lzr
remove useless vars and fix bug in predictor tail_process_fn
This commit is contained in:
commit
579b998ded
@ -464,16 +464,6 @@ def inference_modelscope(
|
|||||||
|
|
||||||
return _forward
|
return _forward
|
||||||
|
|
||||||
def set_parameters(language: str = None,
|
|
||||||
sample_rate: Union[int, Dict[Any, int]] = None):
|
|
||||||
if language is not None:
|
|
||||||
global global_asr_language
|
|
||||||
global_asr_language = language
|
|
||||||
if sample_rate is not None:
|
|
||||||
global global_sample_rate
|
|
||||||
global_sample_rate = sample_rate
|
|
||||||
|
|
||||||
|
|
||||||
def get_parser():
|
def get_parser():
|
||||||
parser = config_argparse.ArgumentParser(
|
parser = config_argparse.ArgumentParser(
|
||||||
description="ASR Decoding",
|
description="ASR Decoding",
|
||||||
|
|||||||
@ -68,7 +68,8 @@ class CifPredictor(nn.Module):
|
|||||||
mask_2 = torch.cat([ones_t, mask], dim=1)
|
mask_2 = torch.cat([ones_t, mask], dim=1)
|
||||||
mask = mask_2 - mask_1
|
mask = mask_2 - mask_1
|
||||||
tail_threshold = mask * tail_threshold
|
tail_threshold = mask * tail_threshold
|
||||||
alphas = torch.cat([alphas, tail_threshold], dim=1)
|
alphas = torch.cat([alphas, zeros_t], dim=1)
|
||||||
|
alphas = torch.add(alphas, tail_threshold)
|
||||||
else:
|
else:
|
||||||
tail_threshold = torch.tensor([tail_threshold], dtype=alphas.dtype).to(alphas.device)
|
tail_threshold = torch.tensor([tail_threshold], dtype=alphas.dtype).to(alphas.device)
|
||||||
tail_threshold = torch.reshape(tail_threshold, (1, 1))
|
tail_threshold = torch.reshape(tail_threshold, (1, 1))
|
||||||
@ -597,7 +598,8 @@ class CifPredictorV3(nn.Module):
|
|||||||
mask_2 = torch.cat([ones_t, mask], dim=1)
|
mask_2 = torch.cat([ones_t, mask], dim=1)
|
||||||
mask = mask_2 - mask_1
|
mask = mask_2 - mask_1
|
||||||
tail_threshold = mask * tail_threshold
|
tail_threshold = mask * tail_threshold
|
||||||
alphas = torch.cat([alphas, tail_threshold], dim=1)
|
alphas = torch.cat([alphas, zeros_t], dim=1)
|
||||||
|
alphas = torch.add(alphas, tail_threshold)
|
||||||
else:
|
else:
|
||||||
tail_threshold = torch.tensor([tail_threshold], dtype=alphas.dtype).to(alphas.device)
|
tail_threshold = torch.tensor([tail_threshold], dtype=alphas.dtype).to(alphas.device)
|
||||||
tail_threshold = torch.reshape(tail_threshold, (1, 1))
|
tail_threshold = torch.reshape(tail_threshold, (1, 1))
|
||||||
|
|||||||
@ -186,23 +186,12 @@ def recursion_dir_all_wav(wav_list, dir_path: str) -> List[str]:
|
|||||||
|
|
||||||
return wav_list
|
return wav_list
|
||||||
|
|
||||||
|
|
||||||
def set_parameters(language: str = None):
|
|
||||||
if language is not None:
|
|
||||||
global global_asr_language
|
|
||||||
global_asr_language = language
|
|
||||||
|
|
||||||
|
|
||||||
def compute_wer(hyp_list: List[Any],
|
def compute_wer(hyp_list: List[Any],
|
||||||
ref_list: List[Any],
|
ref_list: List[Any],
|
||||||
lang: str = None) -> Dict[str, Any]:
|
lang: str = None) -> Dict[str, Any]:
|
||||||
assert len(hyp_list) > 0, 'hyp list is empty'
|
assert len(hyp_list) > 0, 'hyp list is empty'
|
||||||
assert len(ref_list) > 0, 'ref list is empty'
|
assert len(ref_list) > 0, 'ref list is empty'
|
||||||
|
|
||||||
if lang is not None:
|
|
||||||
global global_asr_language
|
|
||||||
global_asr_language = lang
|
|
||||||
|
|
||||||
rst = {
|
rst = {
|
||||||
'Wrd': 0,
|
'Wrd': 0,
|
||||||
'Corr': 0,
|
'Corr': 0,
|
||||||
@ -216,12 +205,15 @@ def compute_wer(hyp_list: List[Any],
|
|||||||
'wrong_sentences': 0
|
'wrong_sentences': 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if lang is None:
|
||||||
|
lang = global_asr_language
|
||||||
|
|
||||||
for h_item in hyp_list:
|
for h_item in hyp_list:
|
||||||
for r_item in ref_list:
|
for r_item in ref_list:
|
||||||
if h_item['key'] == r_item['key']:
|
if h_item['key'] == r_item['key']:
|
||||||
out_item = compute_wer_by_line(h_item['value'],
|
out_item = compute_wer_by_line(h_item['value'],
|
||||||
r_item['value'],
|
r_item['value'],
|
||||||
global_asr_language)
|
lang)
|
||||||
rst['Wrd'] += out_item['nwords']
|
rst['Wrd'] += out_item['nwords']
|
||||||
rst['Corr'] += out_item['cor']
|
rst['Corr'] += out_item['cor']
|
||||||
rst['wrong_words'] += out_item['wrong']
|
rst['wrong_words'] += out_item['wrong']
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user