(Go: >> BACK << -|- >> HOME <<)

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EMO_UNK禁用和Merge VAD修复 #1940

Merged
merged 9 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion funasr/auto/auto_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def inference_with_vad(self, input, input_len=None, **cfg):
end_vad = time.time()

# FIX(gcf): concat the vad clips for sense vocie model for better aed
if kwargs.get("merge_vad", False):
if cfg.get("merge_vad", False):
for i in range(len(res)):
res[i]["value"] = merge_vad(
res[i]["value"], kwargs.get("merge_length_s", 15) * 1000
Expand Down
5 changes: 4 additions & 1 deletion funasr/models/sense_voice/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,7 @@ def __init__(
self.embed = torch.nn.Embedding(
7 + len(self.lid_dict) + len(self.textnorm_dict), input_size
)
self.emo_dict = {"unk": 25009, "happy": 25001, "sad": 25002, "angry": 25003, "neutral": 25004}

self.criterion_att = LabelSmoothingLoss(
size=self.vocab_size,
Expand Down Expand Up @@ -870,7 +871,9 @@ def inference(

# c. Passed the encoder result and the beam search
ctc_logits = self.ctc.log_softmax(encoder_out)

if kwargs.get("ban_emo_unk", False):
ctc_logits[:, :, self.emo_dict["unk"]] = -float("inf")

results = []
b, n, d = encoder_out.size()
if isinstance(key[0], (list, tuple)):
Expand Down
20 changes: 12 additions & 8 deletions funasr/utils/vad_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ def slice_padding_audio_samples(speech, speech_lengths, vad_segments):
return speech_list, speech_lengths_list


def merge_vad(vad_result, max_length=15000):
def merge_vad(vad_result, max_length=15000, min_length=0):
new_result = []
if len(vad_result) <= 1:
return vad_result
time_step = [t[0] for t in vad_result] + [t[1] for t in vad_result]
time_step = sorted(list(set(time_step)))
if len(time_step) == 0:
Expand All @@ -43,13 +45,15 @@ def merge_vad(vad_result, max_length=15000):
time = time_step[i]
if time_step[i + 1] - bg < max_length:
continue
if time - bg < max_length * 1.5:
if time - bg > min_length:
new_result.append([bg, time])
else:
split_num = int(time - bg) // max_length + 1
spl_l = int(time - bg) // split_num
for j in range(split_num):
new_result.append([bg + j * spl_l, bg + (j + 1) * spl_l])
# if time - bg < max_length * 1.5:
# new_result.append([bg, time])
# else:
# split_num = int(time - bg) // max_length + 1
# spl_l = int(time - bg) // split_num
# for j in range(split_num):
# new_result.append([bg + j * spl_l, bg + (j + 1) * spl_l])
bg = time
new_result.append([bg, time_step[-1]])
return new_result
return new_result