Skip to content

Commit 87edd79

Browse files
authored
Plot creating functions
Currently for GPU only Signed-off-by: Sasha Meister <[email protected]>
1 parent fc59941 commit 87edd79

File tree

1 file changed

+58
-0
lines changed
  • tools/speech_data_explorer/sde/pages/statistics

1 file changed

+58
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import numpy as np
2+
import plotly.graph_objects as go
3+
4+
figures_labels = {
5+
'duration': ['Duration', 'Duration, sec'],
6+
'num_words': ['Number of Words', '#words'],
7+
'num_chars': ['Number of Characters', '#chars'],
8+
'word_rate': ['Word Rate', '#words/sec'],
9+
'char_rate': ['Character Rate', '#chars/sec'],
10+
'WER': ['Word Error Rate', 'WER, %'],
11+
'CER': ['Character Error Rate', 'CER, %'],
12+
'WMR': ['Word Match Rate', 'WMR, %'],
13+
'I': ['# Insertions (I)', '#words'],
14+
'D': ['# Deletions (D)', '#words'],
15+
'D-I': ['# Deletions - # Insertions (D-I)', '#words'],
16+
'freq_bandwidth': ['Frequency Bandwidth', 'Bandwidth, Hz'],
17+
'level_db': ['Peak Level', 'Level, dB'],
18+
}
19+
20+
def gpu_plot_histogram(samples_datatable, field, nbins = 50):
21+
data = samples_datatable[field]
22+
23+
if field in figures_labels:
24+
x_axis_title = figures_labels[field][1]
25+
else:
26+
x_axis_title = field
27+
28+
min_value = data.min()
29+
max_value = data.max()
30+
step = (max_value - min_value) / nbins
31+
bins = np.arange(min_value, max_value + step, step)
32+
hist, _ = np.histogram(data, bins=bins)
33+
34+
midpoints = np.arange(min_value + step / 2, max_value + step / 2, step)
35+
trace = go.Bar(x=midpoints, y=hist, marker_color="green")
36+
layout = go.Layout(xaxis=dict(title=x_axis_title), yaxis=dict(title='Amount'))
37+
fig = go.Figure(data=[trace], layout=layout)
38+
fig.update_layout(showlegend=False, margin=dict(l=0, r=0, t=0, b=0, pad=0), height=200)
39+
fig.update_yaxes(type="log")
40+
return fig
41+
42+
def gpu_plot_word_accuracy(vocabulary_data, field):
43+
data = vocabulary_data[field]
44+
45+
epsilon = 1e-6
46+
amounts, _ = np.histogram(data, bins=[0, epsilon, 100, 100])
47+
percentage = ['{:.2%}'.format(amount / sum(amounts)) for amount in amounts]
48+
labels = ["Unrecognized", "Sometimes recognized", "Always recognized"]
49+
colors = ['red', 'orange', 'green']
50+
trace = go.Bar(x=labels, y=amounts, text = percentage, textposition='auto', marker_color=colors)
51+
layout = go.Layout(xaxis=dict(title='Amount'), yaxis=dict(title='Words amount'))
52+
fig = go.Figure(data=[trace], layout=layout)
53+
54+
fig.update_layout(
55+
showlegend=False, margin=dict(l=0, r=0, t=0, b=0, pad=0), height=200, yaxis={'title_text': '#words'}
56+
)
57+
58+
return fig

0 commit comments

Comments
 (0)