Spaces:
Runtime error
Runtime error
File size: 6,328 Bytes
20684dc 441ec1f 20684dc 9372e1c 441ec1f 20684dc 441ec1f 20684dc 441ec1f 20684dc 441ec1f 20684dc 441ec1f 20684dc 441ec1f 20684dc 441ec1f 20684dc 441ec1f 20684dc 441ec1f 20684dc 441ec1f e1d12e9 441ec1f 20684dc 441ec1f 20684dc 441ec1f e1d12e9 9f47e79 e1d12e9 441ec1f e1d12e9 20684dc 441ec1f 20684dc bfa0c67 20684dc bfa0c67 20684dc 441ec1f 20684dc 441ec1f bfa0c67 20684dc bfa0c67 20684dc 441ec1f 20684dc 441ec1f 20684dc 441ec1f 20684dc 441ec1f 20684dc 441ec1f 20684dc 441ec1f 20684dc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
import numpy as np
import plotly.graph_objects as go
import streamlit as st
from .lib import set_input
@st.cache
def get_w(f, ec=0.86, rv=0.50):
result = (rv + f-1)/(ec + f-1)
result = np.clip(result, 0, 1)
print(f'w = {result}')
return result
@st.cache
def get_f(w, ec=0.86, rv=0.50):
result = 1+(ec*w-rv)/(1-w)
result = np.clip(result, 0, 1)
print(f'f = {result}')
return result
@st.cache
def get_pe(w, ec=0.86, f=0.50):
result = ec*w+(1-w)*(1-f)
result = np.clip(result, 0, 1)
print(f'f = {result}')
return result
xdata1 = np.arange(0, 1.1, step=0.01)
# rand = np.random.random_sample()
@st.cache
def proper_float(i):
return np.round(i, 2)
@st.cache
def get_text():
return '''
### Eric's proposal
> I would propose a scoring metric something like this:
> * `probability_emote = w * emotion_confidence + (1 - w) * frequency_penalty`
>
> Where:
> * emotion_confidence: a score from 0.0 to 1.0 representing the emotion model’s confidence in it’s classification results
> * frequency_penalty: a score from 0.0 to 1.0 where a high score penalizes frequent emotes
> * `frequency_penalty = 1 - emotion_frequency`
> * w: a weight from 0.0 to 1.0 that controls the balance between emotion_confidence and frequency_penalty
> * Then you generate a random number between 0.0 and 1.0 and emote if it is greater than probability_emote
> * You will have to set frequency_penalty and w through trial and error, but you can start with setting w=0.5 and giving the emotion classifier and frequency penalty equal weight.
> * Setting w=1.0 would disable the frequency penalty altogether
'''
@st.cache
def get_equation_text(w=0.5, ec=0.7, rand=None, emotion_frequency=None):
text = f'''
#### Equation
```
frequency_penalty = 1 - emotion_frequency
probability_emote = w * emotion_confidence + (1 - w) * frequency_penalty
```
**probability_emote** = {proper_float(w)} * {proper_float(ec)} + {proper_float(1-w)} * frequency_penalty
'''
if rand is not None:
frequency_penalty = proper_float(1-emotion_frequency)
probability_emote = proper_float((w)*(ec)+(1-w)*frequency_penalty)
text = f'''
#### Equation
```
frequency_penalty = 1 - emotion_frequency = 1 - {proper_float(emotion_frequency)} = {frequency_penalty}
probability_emote = w * emotion_confidence + (1 - w) * frequency_penalty
probability_emote = {proper_float(w)} * {proper_float(ec)} + {proper_float(1-w)} * {frequency_penalty}
```
**probability_emote** = {probability_emote}
```
Show_Emotion
= probability_emote > (Random value between 0 and 1)
Random value = {rand}
Show_Emotion = {probability_emote} > {rand}
```
**Show_Emotion** = {probability_emote > rand}
'''
return text
def run_probability_emote(container_param):
w = set_input(container_param,
label='Weight w', key_slider='w_slider', key_input='w_input',
min_value=0.,
max_value=1.,
value=.5,
step=.01,)
score = set_input(container_param,
label='Confidence Score', key_slider='score_slider', key_input='score_input',
min_value=0.,
max_value=1.,
value=.5,
step=.01,)
# score = container_param.slider(
# label='Confidence Score',
# min_value=0.,
# max_value=1.,
# value=.5,
# step=.01)
calculate_check = container_param.checkbox(label='Calculate', value=False)
if calculate_check:
emotion_frequency = set_input(container_param,
label='Emotion Frequency', key_slider='emotion_frequency_slider_slider', key_input='emotion_frequency_slider_input',
min_value=0.,
max_value=1.,
value=.5,
step=.01,)
rand = set_input(container_param,
label='Random Value', key_slider='rand_slider', key_input='rand_input',
min_value=0.,
max_value=1.,
value=.5,
step=.01,)
else:
emotion_frequency = 'emotion_frequency'
rand = None
st.markdown(get_equation_text(w=w, ec=score, rand=rand,
emotion_frequency=emotion_frequency))
fig = go.Figure()
# fig.add_trace(go.Scatter(x=xdata1, y=np.ones_like(xdata1)*rand,
# mode='markers', name='Random',
# line=dict(color='#ff8300', width=2)
# ))
if calculate_check:
dd = 0.01
fig.add_hline(y=rand, line_width=3,
line_dash="dash", line_color="#ff8300")
fig.add_vline(x=emotion_frequency, line_width=3,
line_dash="dash", line_color="green")
fig.add_trace(go.Scatter(
x=[emotion_frequency-dd, emotion_frequency+dd], y=[rand-dd, rand+dd],
mode='lines',
line=dict(color='#ee00ee', width=8)
),)
fig.add_trace(go.Scatter(
x=[emotion_frequency+dd, emotion_frequency-dd], y=[rand-dd, rand+dd],
mode='lines',
line=dict(color='#ee00ee', width=8)
),)
fig.add_trace(go.Scatter(
x=xdata1, y=get_pe(w=w, f=xdata1, ec=score),
mode='lines',
name='Probability-Emote',
line=dict(color='#00eeee', width=4)
),
)
fig.update_layout(
template='plotly_dark',
xaxis_range=[0., 1.],
yaxis_range=[0., 1.],
xaxis_title="Emotion Frequency",
yaxis_title="Probability Emote",
showlegend=False
)
st.plotly_chart(fig, use_container_width=True)
st.markdown(get_text())
|