sanchit-gandhi HF staff commited on
Commit
9c91756
1 Parent(s): 30dabf9

Create new file

Browse files
Files changed (1) hide show
  1. app.py +168 -0
app.py ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from pandas import read_csv
3
+ import os
4
+ import jiwer
5
+ from huggingface_hub import Repository
6
+ import zipfile
7
+
8
+ REFERENCE_NAME = "references"
9
+ SUBMISSION_NAME = "submissions"
10
+
11
+ REFERENCE_URL = os.path.join(
12
+ "https://huggingface.co/datasets/esb", REFERENCE_NAME
13
+ )
14
+ SUBMISSION_URL = os.path.join(
15
+ "https://huggingface.co/datasets/esb", SUBMISSION_NAME
16
+ )
17
+
18
+ TEST_SETS = [
19
+ "ls-clean",
20
+ "ls-other",
21
+ "cv",
22
+ "vox",
23
+ "ted",
24
+ "giga",
25
+ "spgi",
26
+ "earnings",
27
+ "ami",
28
+ ]
29
+ EXPECTED_TEST_FILES = [f + ".txt" for f in TEST_SETS]
30
+
31
+ OPTIONAL_TEST_SETS = ["swbd", "ch", "chime-4"]
32
+ OPTIONAL_TEST_FILES = [f + ".txt" for f in OPTIONAL_TEST_SETS]
33
+
34
+ CSV_RESULTS_FILE = os.path.join(SUBMISSION_NAME, "results.csv")
35
+
36
+ HF_TOKEN = os.environ.get("HF_TOKEN")
37
+
38
+
39
+ def compute_wer(pred_file, ref_file):
40
+ with open(pred_file, "r", encoding="utf-8") as pred, open(
41
+ ref_file, "r", encoding="utf-8"
42
+ ) as ref:
43
+ pred_lines = [line.strip() for line in pred.readlines()]
44
+ ref_lines = [line.strip() for line in ref.readlines()]
45
+
46
+ wer = jiwer.wer(ref_lines, pred_lines)
47
+ return wer
48
+
49
+
50
+ reference_repo = Repository(
51
+ local_dir="references", clone_from=REFERENCE_URL, use_auth_token=HF_TOKEN
52
+ )
53
+ submission_repo = Repository(
54
+ local_dir="submissions", clone_from=SUBMISSION_URL, use_auth_token=HF_TOKEN
55
+ )
56
+ submission_repo.git_pull()
57
+
58
+ all_submissions = [
59
+ folder
60
+ for folder in os.listdir(SUBMISSION_NAME)
61
+ if os.path.isdir(os.path.join(SUBMISSION_NAME, folder)) and folder != ".git"
62
+ ]
63
+
64
+ all_results = read_csv(CSV_RESULTS_FILE)
65
+
66
+ # Write table form CSV
67
+ table = all_results.copy()
68
+
69
+ esb_column = table.pop("esb-score")
70
+ name_column = table.pop("name")
71
+ table.insert(0, "esb-score", esb_column)
72
+ table = table.select_dtypes(exclude=['object', 'string'])
73
+ table.insert(0, "name", name_column)
74
+ table = table.sort_values(by=['esb-score'], ascending=True, ignore_index=True)
75
+ table = table.round(2)
76
+ table.index = table.index + 1
77
+
78
+ # Streamlit
79
+ st.markdown("# ESB: A Benchmark For Multi-Domain End-to-End Speech Recognition")
80
+
81
+ st.markdown(
82
+ f"""
83
+ This is the leaderboard of the End-to end Speech Benchmark (ESB).
84
+ Submitted systems are ranked by the **ESB Score** which is the average of
85
+ all non-optional datasets: {", ".join(TEST_SETS)}. The optional datasets of swbd, ch and chime-4 do not contribute to the ESB score."""
86
+ )
87
+
88
+ # st.table(table)
89
+ st.dataframe(table.style.format(subset=["esb-score", *TEST_SETS, *OPTIONAL_TEST_SETS], formatter="{:.1f}"))
90
+
91
+ st.markdown(
92
+ """
93
+ ESB was proposed in *ESB: A Benchmark For Multi-Domain End-to-End Speech Recognition* by ...
94
+ \n
95
+ The abstract of the paper is as follows:
96
+ \n
97
+ *Speech recognition applications cover a range of different audio and text distributions, with different speaking styles, background noise, transcription punctuation and character casing. However, many speech recognition systems require dataset-specific tuning (audio filtering, punctuation removal and normalisation of casing), therefore assuming a-priori knowledge of both the audio and text distributions. This tuning requirement can lead to systems failing to generalise to other datasets and domains. To promote the development of multi-domain speech systems, we introduce the End-to-end Speech Benchmark (ESB) for evaluating the performance of a single automatic speech recognition (ASR) system across a broad set of speech datasets. Benchmarked systems must use the same data pre- and post-processing algorithm across datasets - assuming the audio and text data distributions are a-priori unknown. We compare a series of state-of-the-art (SoTA) end-to-end (E2E) systems on this benchmark, demonstrating how a single speechsystem can be applied and evaluated on a wide range of data distributions. We find E2E systems to be effective across datasets: in a fair comparison, E2E systems achieve within 2.6% of SoTA systems tuned to a specific dataset. Our analysis reveals that transcription artefacts, such as punctuation and casing, pose difficulties for ASR systems and should be included in evaluation. We believe E2E benchmarking over a range of datasets promotes the research of multi-domain speech recognition systems.*
98
+ \n
99
+ For more information, please see the official submission on [OpenReview.net](https://openreview.net/forum?id=9OL2fIfDLK).
100
+ """
101
+ )
102
+
103
+ st.markdown(
104
+ """
105
+ ## Submitting to ESB
106
+ \n
107
+ To submit to ESB, download the audio data for the nine mandatory ESB test sets from [esb/datasets](https://huggingface.co/datasets/esb/datasets). The test sets contain audio data only. Evaluate your system on the nine test sets by generating predictions for the unlabelled audio samples. For each test set, save the predictions to a .txt file in the order that the audio samples are provided, with one prediction per line. Name the .txt file according to the ESB test set names shown in the table (e.g. the predictions for LibriSpeech test-clean should be named ls-clean.txt).
108
+ \n
109
+ Once you have evaluated your system on all nine test sets, move the predictions into one folder and zip it. The name you assign to the zipped folder will be the name that is shown on the table (e.g. whisper-aed.zip will be displayed as whisper-aed). Upload your zipped submissions for scoring and placement on the leaderboard.
110
+ """
111
+ )
112
+
113
+ # Using the "with" syntax
114
+ with st.form(key="my_form"):
115
+ uploaded_file = st.file_uploader("Choose a zip file")
116
+ submit_button = st.form_submit_button(label="Submit")
117
+
118
+ if submit_button:
119
+ if uploaded_file is None:
120
+ raise ValueError("Please make sure to have uploaded a zip file.")
121
+
122
+ submission = uploaded_file.name.split(".zip")[0]
123
+ with st.spinner(f"Uploading {submission}..."):
124
+ with zipfile.ZipFile(uploaded_file, 'r') as zip_ref:
125
+ zip_ref.extractall(submission_repo.local_dir)
126
+ submission_repo.push_to_hub()
127
+
128
+ with st.spinner(f"Computing ESB Score for {submission}..."):
129
+ results = {"name": submission}
130
+ all_submitted_files = os.listdir(os.path.join(SUBMISSION_NAME, submission))
131
+
132
+ submitted_files = [f for f in all_submitted_files if f in EXPECTED_TEST_FILES]
133
+ submitted_optional_files = [f for f in all_submitted_files if f in OPTIONAL_TEST_FILES]
134
+
135
+ if sorted(EXPECTED_TEST_FILES) != sorted(submitted_files):
136
+ raise ValueError(
137
+ f"{', '.join(submitted_files)} were submitted, but expected {', '.join(EXPECTED_TEST_FILES)}"
138
+ )
139
+
140
+ for file in submitted_files:
141
+ ref_file = os.path.join(REFERENCE_NAME, file)
142
+ pred_file = os.path.join(SUBMISSION_NAME, submission, file)
143
+
144
+ wer = compute_wer(pred_file, ref_file)
145
+ results[file.split(".")[0]] = round(100 * wer, 2)
146
+
147
+ for file in submitted_optional_files:
148
+ ref_file = os.path.join(REFERENCE_NAME, file)
149
+ pred_file = os.path.join(SUBMISSION_NAME, submission, file)
150
+
151
+ wer = compute_wer(pred_file, ref_file)
152
+ results[file.split(".")[0]] = round(100 * wer, 2)
153
+
154
+ # ESB score is computed over the mandatory test sets only
155
+ wer_values = [float(results[t]) for t in TEST_SETS]
156
+ # first average over LS test sets
157
+ wer_values = [sum(wer_values[:2]) / 2, *wer_values[2:]]
158
+ # then macro-average over ESB test sets
159
+ all_wer = sum(wer_values) / len(wer_values)
160
+
161
+ results["esb-score"] = round(all_wer, 2)
162
+ all_results = all_results.append(results, ignore_index=True)
163
+
164
+ # save and upload new evaluated results
165
+ all_results.to_csv(CSV_RESULTS_FILE, index=False)
166
+ commit_url = submission_repo.push_to_hub()
167
+
168
+ st.success('Please refresh this space (CTRL+R) to see your result')