Skip to content

Commit 861147c

Browse files
LauraGPTR1ckShi
andauthored
Dev gzf exp (#1654)
* sensevoice finetune * sensevoice finetune * sensevoice finetune * sensevoice finetune * sensevoice finetune * sensevoice finetune * sensevoice finetune * sensevoice finetune * sensevoice finetune * sensevoice finetune * bugfix * update with main (#1631) * update seaco finetune * v1.0.24 --------- Co-authored-by: 维石 <[email protected]> * sensevoice * sensevoice * sensevoice * update with main (#1638) * update seaco finetune * v1.0.24 * update rwkv template --------- Co-authored-by: 维石 <[email protected]> * sensevoice * sensevoice * sensevoice * sensevoice * sensevoice * sensevoice * sensevoice * sensevoice * sensevoice * sensevoice * sensevoice * sensevoice * sensevoice * sensevoice * sensevoice * sense voice * sense voice * sense voice * sense voice * sense voice * sense voice * sense voice * sense voice * sense voice * sense voice * sense voice * sense voice * sense voice * sense voice * sense voice * sense voice * sense voice * sense voice * sense voice * sense voice * whisper * whisper * update style * update style --------- Co-authored-by: 维石 <[email protected]>
1 parent 7c3ba91 commit 861147c

File tree

1,015 files changed

+25573
-30554
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,015 files changed

+25573
-30554
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
repos:
2+
- repo: https://github.com/psf/black
3+
rev: 24.4.0
4+
hooks:
5+
- id: black
6+
args: ['--line-length=100'] # 示例参数,black默认使用4个空格缩进

docs/conf.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
# -- Project information -----------------------------------------------------
1919

20-
project = 'FunASR'
21-
copyright = '2022, Speech Lab, Alibaba Group'
22-
author = 'Speech Lab, Alibaba Grou'
20+
project = "FunASR"
21+
copyright = "2022, Speech Lab, Alibaba Group"
22+
author = "Speech Lab, Alibaba Group"
2323

2424

2525
# -- General configuration ---------------------------------------------------
@@ -30,18 +30,18 @@
3030
extensions = [
3131
"nbsphinx",
3232
"sphinx.ext.autodoc",
33-
'sphinx.ext.napoleon',
34-
'sphinx.ext.viewcode',
33+
"sphinx.ext.napoleon",
34+
"sphinx.ext.viewcode",
3535
"sphinx.ext.mathjax",
3636
"sphinx.ext.todo",
3737
# "sphinxarg.ext",
3838
"sphinx_markdown_tables",
39-
'recommonmark',
40-
'sphinx_rtd_theme',
39+
"recommonmark",
40+
"sphinx_rtd_theme",
4141
]
4242

4343
# Add any paths that contain templates here, relative to this directory.
44-
templates_path = ['_templates']
44+
templates_path = ["_templates"]
4545

4646
source_suffix = [".rst", ".md"]
4747

@@ -64,4 +64,4 @@
6464
# Add any paths that contain custom static files (such as style sheets) here,
6565
# relative to this directory. They are copied after the builtin static files,
6666
# so a file named "default.css" will overwrite the builtin "default.css".
67-
# html_static_path = ['_static']
67+
# html_static_path = ['_static']

docs/m2met2/conf.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@
66
# -- Project information -----------------------------------------------------
77
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
88

9-
project = 'MULTI-PARTY MEETING TRANSCRIPTION CHALLENGE 2.0'
10-
copyright = '2023, Speech Lab, Alibaba Group; ASLP Group, Northwestern Polytechnical University'
11-
author = 'Speech Lab, Alibaba Group; Audio, Speech and Language Processing Group, Northwestern Polytechnical University'
9+
project = "MULTI-PARTY MEETING TRANSCRIPTION CHALLENGE 2.0"
10+
copyright = "2023, Speech Lab, Alibaba Group; ASLP Group, Northwestern Polytechnical University"
11+
author = "Speech Lab, Alibaba Group; Audio, Speech and Language Processing Group, Northwestern Polytechnical University"
1212

1313

1414
extensions = [
1515
"nbsphinx",
1616
"sphinx.ext.autodoc",
17-
'sphinx.ext.napoleon',
18-
'sphinx.ext.viewcode',
17+
"sphinx.ext.napoleon",
18+
"sphinx.ext.viewcode",
1919
"sphinx.ext.mathjax",
2020
"sphinx.ext.todo",
2121
# "sphinxarg.ext",
2222
"sphinx_markdown_tables",
2323
# 'recommonmark',
24-
'sphinx_rtd_theme',
25-
'myst_parser',
24+
"sphinx_rtd_theme",
25+
"myst_parser",
2626
]
2727

2828
myst_enable_extensions = [
@@ -33,13 +33,12 @@
3333
]
3434

3535
myst_heading_anchors = 2
36-
myst_highlight_code_blocks=True
37-
myst_update_mathjax=False
36+
myst_highlight_code_blocks = True
37+
myst_update_mathjax = False
3838

39-
templates_path = ['_templates']
39+
templates_path = ["_templates"]
4040
source_suffix = [".rst", ".md"]
4141

4242
pygments_style = "sphinx"
4343

4444
html_theme = "sphinx_rtd_theme"
45-

examples/aishell/paraformer/utils/compute_wer.py

Lines changed: 105 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2,66 +2,98 @@
22
import numpy as np
33
import sys
44

5-
def compute_wer(ref_file,
6-
hyp_file,
7-
cer_detail_file):
5+
6+
def compute_wer(ref_file, hyp_file, cer_detail_file):
87
rst = {
9-
'Wrd': 0,
10-
'Corr': 0,
11-
'Ins': 0,
12-
'Del': 0,
13-
'Sub': 0,
14-
'Snt': 0,
15-
'Err': 0.0,
16-
'S.Err': 0.0,
17-
'wrong_words': 0,
18-
'wrong_sentences': 0
8+
"Wrd": 0,
9+
"Corr": 0,
10+
"Ins": 0,
11+
"Del": 0,
12+
"Sub": 0,
13+
"Snt": 0,
14+
"Err": 0.0,
15+
"S.Err": 0.0,
16+
"wrong_words": 0,
17+
"wrong_sentences": 0,
1918
}
2019

2120
hyp_dict = {}
2221
ref_dict = {}
23-
with open(hyp_file, 'r') as hyp_reader:
22+
with open(hyp_file, "r") as hyp_reader:
2423
for line in hyp_reader:
2524
key = line.strip().split()[0]
2625
value = line.strip().split()[1:]
2726
hyp_dict[key] = value
28-
with open(ref_file, 'r') as ref_reader:
27+
with open(ref_file, "r") as ref_reader:
2928
for line in ref_reader:
3029
key = line.strip().split()[0]
3130
value = line.strip().split()[1:]
3231
ref_dict[key] = value
3332

34-
cer_detail_writer = open(cer_detail_file, 'w')
33+
cer_detail_writer = open(cer_detail_file, "w")
3534
for hyp_key in hyp_dict:
3635
if hyp_key in ref_dict:
37-
out_item = compute_wer_by_line(hyp_dict[hyp_key], ref_dict[hyp_key])
38-
rst['Wrd'] += out_item['nwords']
39-
rst['Corr'] += out_item['cor']
40-
rst['wrong_words'] += out_item['wrong']
41-
rst['Ins'] += out_item['ins']
42-
rst['Del'] += out_item['del']
43-
rst['Sub'] += out_item['sub']
44-
rst['Snt'] += 1
45-
if out_item['wrong'] > 0:
46-
rst['wrong_sentences'] += 1
47-
cer_detail_writer.write(hyp_key + print_cer_detail(out_item) + '\n')
48-
cer_detail_writer.write("ref:" + '\t' + " ".join(list(map(lambda x: x.lower(), ref_dict[hyp_key]))) + '\n')
49-
cer_detail_writer.write("hyp:" + '\t' + " ".join(list(map(lambda x: x.lower(), hyp_dict[hyp_key]))) + '\n')
50-
51-
if rst['Wrd'] > 0:
52-
rst['Err'] = round(rst['wrong_words'] * 100 / rst['Wrd'], 2)
53-
if rst['Snt'] > 0:
54-
rst['S.Err'] = round(rst['wrong_sentences'] * 100 / rst['Snt'], 2)
55-
56-
cer_detail_writer.write('\n')
57-
cer_detail_writer.write("%WER " + str(rst['Err']) + " [ " + str(rst['wrong_words'])+ " / " + str(rst['Wrd']) +
58-
", " + str(rst['Ins']) + " ins, " + str(rst['Del']) + " del, " + str(rst['Sub']) + " sub ]" + '\n')
59-
cer_detail_writer.write("%SER " + str(rst['S.Err']) + " [ " + str(rst['wrong_sentences']) + " / " + str(rst['Snt']) + " ]" + '\n')
60-
cer_detail_writer.write("Scored " + str(len(hyp_dict)) + " sentences, " + str(len(hyp_dict) - rst['Snt']) + " not present in hyp." + '\n')
61-
62-
63-
def compute_wer_by_line(hyp,
64-
ref):
36+
out_item = compute_wer_by_line(hyp_dict[hyp_key], ref_dict[hyp_key])
37+
rst["Wrd"] += out_item["nwords"]
38+
rst["Corr"] += out_item["cor"]
39+
rst["wrong_words"] += out_item["wrong"]
40+
rst["Ins"] += out_item["ins"]
41+
rst["Del"] += out_item["del"]
42+
rst["Sub"] += out_item["sub"]
43+
rst["Snt"] += 1
44+
if out_item["wrong"] > 0:
45+
rst["wrong_sentences"] += 1
46+
cer_detail_writer.write(hyp_key + print_cer_detail(out_item) + "\n")
47+
cer_detail_writer.write(
48+
"ref:" + "\t" + " ".join(list(map(lambda x: x.lower(), ref_dict[hyp_key]))) + "\n"
49+
)
50+
cer_detail_writer.write(
51+
"hyp:" + "\t" + " ".join(list(map(lambda x: x.lower(), hyp_dict[hyp_key]))) + "\n"
52+
)
53+
54+
if rst["Wrd"] > 0:
55+
rst["Err"] = round(rst["wrong_words"] * 100 / rst["Wrd"], 2)
56+
if rst["Snt"] > 0:
57+
rst["S.Err"] = round(rst["wrong_sentences"] * 100 / rst["Snt"], 2)
58+
59+
cer_detail_writer.write("\n")
60+
cer_detail_writer.write(
61+
"%WER "
62+
+ str(rst["Err"])
63+
+ " [ "
64+
+ str(rst["wrong_words"])
65+
+ " / "
66+
+ str(rst["Wrd"])
67+
+ ", "
68+
+ str(rst["Ins"])
69+
+ " ins, "
70+
+ str(rst["Del"])
71+
+ " del, "
72+
+ str(rst["Sub"])
73+
+ " sub ]"
74+
+ "\n"
75+
)
76+
cer_detail_writer.write(
77+
"%SER "
78+
+ str(rst["S.Err"])
79+
+ " [ "
80+
+ str(rst["wrong_sentences"])
81+
+ " / "
82+
+ str(rst["Snt"])
83+
+ " ]"
84+
+ "\n"
85+
)
86+
cer_detail_writer.write(
87+
"Scored "
88+
+ str(len(hyp_dict))
89+
+ " sentences, "
90+
+ str(len(hyp_dict) - rst["Snt"])
91+
+ " not present in hyp."
92+
+ "\n"
93+
)
94+
95+
96+
def compute_wer_by_line(hyp, ref):
6597
hyp = list(map(lambda x: x.lower(), hyp))
6698
ref = list(map(lambda x: x.lower(), ref))
6799

@@ -96,57 +128,65 @@ def compute_wer_by_line(hyp,
96128
match_idx = []
97129
i = len_hyp
98130
j = len_ref
99-
rst = {
100-
'nwords': len_ref,
101-
'cor': 0,
102-
'wrong': 0,
103-
'ins': 0,
104-
'del': 0,
105-
'sub': 0
106-
}
131+
rst = {"nwords": len_ref, "cor": 0, "wrong": 0, "ins": 0, "del": 0, "sub": 0}
107132
while i >= 0 or j >= 0:
108133
i_idx = max(0, i)
109134
j_idx = max(0, j)
110135

111136
if ops_matrix[i_idx][j_idx] == 0: # correct
112137
if i - 1 >= 0 and j - 1 >= 0:
113138
match_idx.append((j - 1, i - 1))
114-
rst['cor'] += 1
139+
rst["cor"] += 1
115140

116141
i -= 1
117142
j -= 1
118143

119144
elif ops_matrix[i_idx][j_idx] == 2: # insert
120145
i -= 1
121-
rst['ins'] += 1
146+
rst["ins"] += 1
122147

123148
elif ops_matrix[i_idx][j_idx] == 3: # delete
124149
j -= 1
125-
rst['del'] += 1
150+
rst["del"] += 1
126151

127152
elif ops_matrix[i_idx][j_idx] == 1: # substitute
128153
i -= 1
129154
j -= 1
130-
rst['sub'] += 1
155+
rst["sub"] += 1
131156

132157
if i < 0 and j >= 0:
133-
rst['del'] += 1
158+
rst["del"] += 1
134159
elif j < 0 and i >= 0:
135-
rst['ins'] += 1
160+
rst["ins"] += 1
136161

137162
match_idx.reverse()
138163
wrong_cnt = cost_matrix[len_hyp][len_ref]
139-
rst['wrong'] = wrong_cnt
164+
rst["wrong"] = wrong_cnt
140165

141166
return rst
142167

143-
def print_cer_detail(rst):
144-
return ("(" + "nwords=" + str(rst['nwords']) + ",cor=" + str(rst['cor'])
145-
+ ",ins=" + str(rst['ins']) + ",del=" + str(rst['del']) + ",sub="
146-
+ str(rst['sub']) + ") corr:" + '{:.2%}'.format(rst['cor']/rst['nwords'])
147-
+ ",cer:" + '{:.2%}'.format(rst['wrong']/rst['nwords']))
148168

149-
if __name__ == '__main__':
169+
def print_cer_detail(rst):
170+
return (
171+
"("
172+
+ "nwords="
173+
+ str(rst["nwords"])
174+
+ ",cor="
175+
+ str(rst["cor"])
176+
+ ",ins="
177+
+ str(rst["ins"])
178+
+ ",del="
179+
+ str(rst["del"])
180+
+ ",sub="
181+
+ str(rst["sub"])
182+
+ ") corr:"
183+
+ "{:.2%}".format(rst["cor"] / rst["nwords"])
184+
+ ",cer:"
185+
+ "{:.2%}".format(rst["wrong"] / rst["nwords"])
186+
)
187+
188+
189+
if __name__ == "__main__":
150190
if len(sys.argv) != 4:
151191
print("usage : python compute-wer.py test.ref test.hyp test.wer")
152192
sys.exit(0)

examples/aishell/paraformer/utils/extract_embeds.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import torch
66
from kaldiio import WriteHelper
77
import re
8+
89
text_file_json = sys.argv[1]
910
out_ark = sys.argv[2]
1011
out_scp = sys.argv[3]
@@ -16,17 +17,17 @@
1617
tokenizer = AutoTokenizer.from_pretrained(model_path)
1718
extractor = pipeline(task="feature-extraction", model=model, tokenizer=tokenizer, device=device)
1819

19-
with open(text_file_json, 'r') as f:
20+
with open(text_file_json, "r") as f:
2021
js = f.readlines()
2122

2223

2324
f_shape = open(out_shape, "w")
24-
with WriteHelper('ark,scp:{},{}'.format(out_ark, out_scp)) as writer:
25+
with WriteHelper("ark,scp:{},{}".format(out_ark, out_scp)) as writer:
2526
with torch.no_grad():
2627
for idx, line in enumerate(js):
2728
id, tokens = line.strip().split(" ", 1)
2829
tokens = re.sub(" ", "", tokens.strip())
29-
tokens = ' '.join([j for j in tokens])
30+
tokens = " ".join([j for j in tokens])
3031
token_num = len(tokens.split(" "))
3132
outputs = extractor(tokens)
3233
outputs = np.array(outputs)
@@ -38,10 +39,11 @@
3839
shape_line = "{} {},{}\n".format(id, token_num_embeds, dim)
3940
f_shape.write(shape_line)
4041
else:
41-
print("{}, size has changed, {}, {}, {}".format(id, token_num, token_num_embeds, tokens))
42-
42+
print(
43+
"{}, size has changed, {}, {}, {}".format(
44+
id, token_num, token_num_embeds, tokens
45+
)
46+
)
4347

4448

4549
f_shape.close()
46-
47-

0 commit comments

Comments
 (0)