Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
st.set_page_config(layout="wide")
|
3 |
import streamlit_authenticator as stauth
|
4 |
import pandas as pd
|
@@ -11,27 +12,28 @@ import user_evaluation_variables
|
|
11 |
from pathlib import Path
|
12 |
import tab_manager
|
13 |
import yaml
|
|
|
14 |
from yaml.loader import SafeLoader
|
15 |
from PIL import Image
|
16 |
-
|
17 |
-
|
18 |
|
19 |
AUTHENTICATOR = None
|
20 |
TBYB_LOGO = Image.open('./assets/TBYB_logo_light.png')
|
21 |
USER_LOGGED_IN = False
|
22 |
-
USER_DATABASE_PATH = './data/user_database.yaml'
|
23 |
|
24 |
-
|
25 |
-
|
|
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
folder_path=userDataFolder,
|
31 |
-
path_in_repo="data",
|
32 |
-
every=5,
|
33 |
)
|
34 |
|
|
|
|
|
|
|
35 |
def create_new_user(authenticator, users):
|
36 |
try:
|
37 |
if authenticator.register_user('Register user', preauthorization=False):
|
@@ -39,15 +41,10 @@ def create_new_user(authenticator, users):
|
|
39 |
except Exception as e:
|
40 |
st.error(e)
|
41 |
|
42 |
-
with
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
# repo_id="JVice/try-before-you-bias",
|
47 |
-
# operations=[CommitOperationAdd(path_in_repo="data/user_database.yaml",
|
48 |
-
# path_or_fileobj="~/repo/data/user_database.yaml")],
|
49 |
-
# commit_message="Updating ",
|
50 |
-
# )
|
51 |
|
52 |
|
53 |
def forgot_password(authenticator, users):
|
@@ -59,8 +56,12 @@ def forgot_password(authenticator, users):
|
|
59 |
# Random password should be transferred to user securely
|
60 |
except Exception as e:
|
61 |
st.error(e)
|
62 |
-
with open(
|
63 |
yaml.dump(users, file, default_flow_style=False)
|
|
|
|
|
|
|
|
|
64 |
def update_account_details(authenticator, users):
|
65 |
if st.session_state["authentication_status"]:
|
66 |
try:
|
@@ -68,8 +69,12 @@ def update_account_details(authenticator, users):
|
|
68 |
st.success('Entries updated successfully')
|
69 |
except Exception as e:
|
70 |
st.error(e)
|
71 |
-
with open(
|
72 |
yaml.dump(users, file, default_flow_style=False)
|
|
|
|
|
|
|
|
|
73 |
def reset_password(authenticator, users):
|
74 |
if st.session_state["authentication_status"]:
|
75 |
try:
|
@@ -77,14 +82,18 @@ def reset_password(authenticator, users):
|
|
77 |
st.success('Password modified successfully')
|
78 |
except Exception as e:
|
79 |
st.error(e)
|
80 |
-
with open(
|
81 |
yaml.dump(users, file, default_flow_style=False)
|
|
|
|
|
|
|
|
|
82 |
def user_login_create():
|
83 |
global AUTHENTICATOR
|
84 |
global TBYB_LOGO
|
85 |
global USER_LOGGED_IN
|
86 |
users = None
|
87 |
-
with open(
|
88 |
users = yaml.load(file, Loader=SafeLoader)
|
89 |
AUTHENTICATOR = stauth.Authenticate(
|
90 |
users['credentials'],
|
@@ -121,24 +130,28 @@ def user_login_create():
|
|
121 |
# update_account_details(AUTHENTICATOR, users)
|
122 |
reset_password(AUTHENTICATOR, users)
|
123 |
|
124 |
-
|
125 |
return USER_LOGGED_IN
|
|
|
|
|
126 |
def setup_page_banner():
|
127 |
global USER_LOGGED_IN
|
128 |
# for tab in [tab1, tab2, tab3, tab4, tab5]:
|
129 |
-
c1,c2,c3,c4,c5,c6,c7,c8,c9 = st.columns(9)
|
130 |
with c5:
|
131 |
st.image(TBYB_LOGO, use_column_width=True)
|
132 |
-
for col in [c1,c2,c3,c4,c5,c6,c7,c8,c9]:
|
133 |
col = None
|
134 |
st.title('Try Before You Bias (TBYB)')
|
135 |
st.write('*A Quantitative T2I Bias Evaluation Tool*')
|
|
|
|
|
136 |
def setup_how_to():
|
137 |
expander = st.expander("How to Use")
|
138 |
expander.write("1. Login to your TBYB Account using the bar on the right\n"
|
139 |
"2. Navigate to the '\U0001F527 Setup' tab and input the ID of the HuggingFace \U0001F917 T2I model you want to evaluate\n")
|
140 |
expander.image(Image.open('./assets/HF_MODEL_ID_EXAMPLE.png'))
|
141 |
-
expander.write(
|
|
|
142 |
expander.image(Image.open('./assets/lykon_corgi.png'))
|
143 |
expander.write("4. Navigate to the '\U0001F30E General Eval.' or '\U0001F3AF Task-Oriented Eval.' tabs "
|
144 |
" to evaluate your model once it has been loaded\n"
|
@@ -148,44 +161,45 @@ def setup_how_to():
|
|
148 |
" '\U0001F4F0 Additional Information' tab for a TL;DR.\n"
|
149 |
"8. For any questions or to report any bugs/issues. Please contact jordan.vice@uwa.edu.au.\n")
|
150 |
|
|
|
151 |
def setup_additional_information_tab(tab):
|
152 |
with tab:
|
153 |
st.header("1. Quantifying Bias in Text-to-Image (T2I) Generative Models")
|
154 |
st.markdown(
|
155 |
"""
|
156 |
*Based on the article of the same name available here --PAPER HYPERLINK--
|
157 |
-
|
158 |
Authors: Jordan Vice, Naveed Akhtar, Richard Hartley and Ajmal Mian
|
159 |
-
|
160 |
This web-app was developed by **Jordan Vice** to accompany the article, serving as a practical
|
161 |
implementation of how T2I model biases can be quantitatively assessed and compared. Evaluation results from
|
162 |
all *base* models discussed in the paper have been incorporated into the TBYB community results and we hope
|
163 |
that others share their evaluations as we look to further the discussion on transparency and reliability
|
164 |
of T2I models.
|
165 |
-
|
166 |
""")
|
167 |
|
168 |
st.header('2. A (very) Brief Summary')
|
169 |
st.image(Image.open('./assets/TBYB_flowchart.png'))
|
170 |
st.markdown(
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
st.markdown(
|
179 |
-
"""
|
180 |
-
We proposed three novel metrics to quantify T2I model biases:
|
181 |
-
1. Distribution Bias - $B_D$
|
182 |
-
2. Jaccard Hallucination - $H_J$
|
183 |
-
3. Generative Miss Rate - $M_G$
|
184 |
-
|
185 |
-
Open the appropriate drop-down menu to understand the logic and inspiration behind metric.
|
186 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
)
|
188 |
-
c1,c2,c3 = st.columns(3)
|
189 |
with c1:
|
190 |
with st.expander("Distribution Bias - $B_D$"):
|
191 |
st.markdown(
|
@@ -193,16 +207,16 @@ def setup_additional_information_tab(tab):
|
|
193 |
Using the Area under the Curve (AuC) as an evaluation metric in machine learning is not novel. However,
|
194 |
in the context of T2I models, using AuC allows us to define the distribution of objects that have been
|
195 |
detected in generated output image scenes.
|
196 |
-
|
197 |
So, everytime an object is detected in a scene, we update a dictionary (which is available for
|
198 |
download after running an evaluation). After evaluating a full set of images, you can use this
|
199 |
information to determine what objects appear more frequently than others.
|
200 |
-
|
201 |
After all images are evaluated, we sort the objects in descending order and normalize the data. We
|
202 |
then use the normalized values to calculate $B_D$, using the trapezoidal AuC rule i.e.:
|
203 |
-
|
204 |
$B_D = \\Sigma_{i=1}^M\\frac{n_i+n_{i=1}}{2}$
|
205 |
-
|
206 |
So, if a user conducts a task-oriented study on biases related to **dogs** using a model
|
207 |
that was heavily biased using pictures of animals in the wild. You might find that after running
|
208 |
evaluations, the most common objects detected were trees and grass - even if these objects weren't
|
@@ -219,21 +233,21 @@ def setup_additional_information_tab(tab):
|
|
219 |
in relation to some of the most popular large language models. Depending on where you look, hallucinations
|
220 |
can be defined as being positive, negative, or just something to observe $\\rightarrow$ a sentiment
|
221 |
that we echo in our bias evaluations.
|
222 |
-
|
223 |
Now, how does hallucination tie into bias? In our work, we use hallucination to define how often a
|
224 |
T2I model will *add* objects that weren't specified OR, how often it will *omit* objects that were
|
225 |
specified. This indicates that there could be an innate shift in bias in the model, causing it to
|
226 |
add or omit certain objects.
|
227 |
-
|
228 |
Initially, we considered using two variables $H^+$ and $H^-$ to define these two dimensions of
|
229 |
hallucination. Then, we considered the Jaccard similarity coefficient, which
|
230 |
measures the similarity *and* diversity of two sets of objects/samples - defining this as
|
231 |
Jaccard Hallucination - $H_J$.
|
232 |
-
|
233 |
Simply put, we define the set of objects detected in the input prompt and then detect the objects in
|
234 |
the corresponding output image. Then, we determine the intersect over union. For a model, we
|
235 |
calculate the average $H_J$ across generated images using:
|
236 |
-
|
237 |
$H_J = \\frac{\Sigma_{i=0}^{N-1}1-\\frac{\mathcal{X}_i\cap\mathcal{Y}_i}{\mathcal{X}_i\cup\mathcal{Y}_i}}{N}$
|
238 |
|
239 |
"""
|
@@ -247,16 +261,16 @@ def setup_additional_information_tab(tab):
|
|
247 |
of evaluating bias, we thought that it would be important to see if there was a correlation
|
248 |
between bias and performance (as we predicted). And while the other metrics do evaluate biases
|
249 |
in terms of misalignment, they do not consider the relationship between bias and performance.
|
250 |
-
|
251 |
We use an additional CLIP model to assist in calculating Generative Miss Rate - $M_G$. Logically,
|
252 |
as a model becomes more biased, it will begin to diverge away from the intended target and so, the
|
253 |
miss rate of the generative model will increase as a result. This was a major consideration when
|
254 |
designing this metric.
|
255 |
-
|
256 |
We use the CLIP model as a binary classifier, differentiating between two classes:
|
257 |
- the prompt used to generate the image
|
258 |
- **NOT** the prompt
|
259 |
-
|
260 |
Through our experiments on intentionally-biased T2I models, we found that there was a clear
|
261 |
relationship between $M_G$ and the extent of bias. So, we can use this metric to quantify and infer
|
262 |
how badly model performances have been affected by their biases.
|
@@ -276,7 +290,7 @@ def setup_additional_information_tab(tab):
|
|
276 |
- Adaptor models are not currently supported, we will look to add evaluation functionalities of these
|
277 |
models in the future.
|
278 |
- Download, generation, inference and evaluation times are all hardware dependent.
|
279 |
-
|
280 |
Keep in mind that these constraints may be removed or added to any time.
|
281 |
""")
|
282 |
st.header('4. Misuse, Malicious Use, and Out-of-Scope Use')
|
@@ -285,29 +299,30 @@ def setup_additional_information_tab(tab):
|
|
285 |
Given this application is used for the assessment of T2I biases and relies on
|
286 |
pre-trained models available on HuggingFace, we are not responsible for any content generated
|
287 |
by public-facing models that have been used to generate images using this application.
|
288 |
-
|
289 |
TBYB is proposed as an auxiliary tool to assess model biases and thus, if a chosen model is found to output
|
290 |
insensitive, disturbing, distressing or offensive images that propagate harmful stereotypes or
|
291 |
representations of marginalised groups, please address your concerns to the model providers.
|
292 |
-
|
293 |
-
|
294 |
However, given the TBYB tool is designed for bias quantification and is driven by transparency, it would be
|
295 |
beneficial to the TBYB community to share evaluations of biased T2I models!
|
296 |
-
|
297 |
We share no association with HuggingFace \U0001F917, we only use their services as a model repository,
|
298 |
given their growth in popularity in the computer science community recently.
|
299 |
-
|
300 |
-
|
301 |
For further questions/queries or if you want to simply strike a conversation,
|
302 |
please reach out to Jordan Vice at: jordan.vice@uwa.edu.au""")
|
303 |
|
|
|
304 |
setup_page_banner()
|
305 |
setup_how_to()
|
306 |
|
307 |
-
|
308 |
if user_login_create():
|
309 |
-
tab1, tab2, tab3, tab4, tab5, tab6 = st.tabs(
|
310 |
-
|
|
|
311 |
setup_additional_information_tab(tab6)
|
312 |
|
313 |
# PLASTER THE LOGO EVERYWHERE
|
@@ -345,16 +360,19 @@ if user_login_create():
|
|
345 |
user_evaluation_variables.MODEL = modelID
|
346 |
user_evaluation_variables.MODEL_TYPE = modelType
|
347 |
else:
|
348 |
-
st.error(
|
349 |
-
|
350 |
-
|
|
|
|
|
351 |
if modelID:
|
352 |
with st.form("example_image_gen_form", clear_on_submit=True):
|
353 |
testPrompt = st.text_input('Input a random test prompt to test out your '
|
354 |
'chosen model and see if its generating images:')
|
355 |
submitted2 = st.form_submit_button("Submit")
|
356 |
if testPrompt and submitted2:
|
357 |
-
with st.spinner(
|
|
|
358 |
testImage = MINFER.generate_test_image(MINFER.TargetModel, testPrompt)
|
359 |
st.image(testImage, caption='Model: ' + modelID + ' Prompt: ' + testPrompt)
|
360 |
st.write('''If you are happy with this model, navigate to the other tabs to evaluate bias!
|
|
|
1 |
import streamlit as st
|
2 |
+
|
3 |
st.set_page_config(layout="wide")
|
4 |
import streamlit_authenticator as stauth
|
5 |
import pandas as pd
|
|
|
12 |
from pathlib import Path
|
13 |
import tab_manager
|
14 |
import yaml
|
15 |
+
import os
|
16 |
from yaml.loader import SafeLoader
|
17 |
from PIL import Image
|
18 |
+
import huggingface_hub
|
19 |
+
from huggingface_hub import Repository
|
20 |
|
21 |
AUTHENTICATOR = None
|
22 |
TBYB_LOGO = Image.open('./assets/TBYB_logo_light.png')
|
23 |
USER_LOGGED_IN = False
|
|
|
24 |
|
25 |
+
DATASET_REPO_URL = "https://huggingface.co/datasets/JVice/try-before-you-bias-data"
|
26 |
+
DATA_FILENAME = "user_database.yaml"
|
27 |
+
USER_DATA_FILE = os.path.join("data", DATA_FILENAME)
|
28 |
|
29 |
+
HF_TOKEN = os.environ.get("HF_TOKEN")
|
30 |
+
repo = Repository(
|
31 |
+
local_dir="data", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
|
|
|
|
|
|
|
32 |
)
|
33 |
|
34 |
+
print("is none?", HF_TOKEN is None)
|
35 |
+
|
36 |
+
print("hfh", huggingface_hub.__version__)
|
37 |
def create_new_user(authenticator, users):
|
38 |
try:
|
39 |
if authenticator.register_user('Register user', preauthorization=False):
|
|
|
41 |
except Exception as e:
|
42 |
st.error(e)
|
43 |
|
44 |
+
with open(USER_DATA_FILE, 'w') as file:
|
45 |
+
yaml.dump(users, file, default_flow_style=False)
|
46 |
+
commit_url = repo.push_to_hub()
|
47 |
+
st.write(commit_url)
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
|
50 |
def forgot_password(authenticator, users):
|
|
|
56 |
# Random password should be transferred to user securely
|
57 |
except Exception as e:
|
58 |
st.error(e)
|
59 |
+
with open(USER_DATA_FILE, 'w') as file:
|
60 |
yaml.dump(users, file, default_flow_style=False)
|
61 |
+
commit_url = repo.push_to_hub()
|
62 |
+
st.write(commit_url)
|
63 |
+
|
64 |
+
|
65 |
def update_account_details(authenticator, users):
|
66 |
if st.session_state["authentication_status"]:
|
67 |
try:
|
|
|
69 |
st.success('Entries updated successfully')
|
70 |
except Exception as e:
|
71 |
st.error(e)
|
72 |
+
with open(USER_DATA_FILE, 'w') as file:
|
73 |
yaml.dump(users, file, default_flow_style=False)
|
74 |
+
commit_url = repo.push_to_hub()
|
75 |
+
st.write(commit_url)
|
76 |
+
|
77 |
+
|
78 |
def reset_password(authenticator, users):
|
79 |
if st.session_state["authentication_status"]:
|
80 |
try:
|
|
|
82 |
st.success('Password modified successfully')
|
83 |
except Exception as e:
|
84 |
st.error(e)
|
85 |
+
with open(USER_DATA_FILE, 'w') as file:
|
86 |
yaml.dump(users, file, default_flow_style=False)
|
87 |
+
commit_url = repo.push_to_hub()
|
88 |
+
st.write(commit_url)
|
89 |
+
|
90 |
+
|
91 |
def user_login_create():
|
92 |
global AUTHENTICATOR
|
93 |
global TBYB_LOGO
|
94 |
global USER_LOGGED_IN
|
95 |
users = None
|
96 |
+
with open(USER_DATA_FILE) as file:
|
97 |
users = yaml.load(file, Loader=SafeLoader)
|
98 |
AUTHENTICATOR = stauth.Authenticate(
|
99 |
users['credentials'],
|
|
|
130 |
# update_account_details(AUTHENTICATOR, users)
|
131 |
reset_password(AUTHENTICATOR, users)
|
132 |
|
|
|
133 |
return USER_LOGGED_IN
|
134 |
+
|
135 |
+
|
136 |
def setup_page_banner():
|
137 |
global USER_LOGGED_IN
|
138 |
# for tab in [tab1, tab2, tab3, tab4, tab5]:
|
139 |
+
c1, c2, c3, c4, c5, c6, c7, c8, c9 = st.columns(9)
|
140 |
with c5:
|
141 |
st.image(TBYB_LOGO, use_column_width=True)
|
142 |
+
for col in [c1, c2, c3, c4, c5, c6, c7, c8, c9]:
|
143 |
col = None
|
144 |
st.title('Try Before You Bias (TBYB)')
|
145 |
st.write('*A Quantitative T2I Bias Evaluation Tool*')
|
146 |
+
|
147 |
+
|
148 |
def setup_how_to():
|
149 |
expander = st.expander("How to Use")
|
150 |
expander.write("1. Login to your TBYB Account using the bar on the right\n"
|
151 |
"2. Navigate to the '\U0001F527 Setup' tab and input the ID of the HuggingFace \U0001F917 T2I model you want to evaluate\n")
|
152 |
expander.image(Image.open('./assets/HF_MODEL_ID_EXAMPLE.png'))
|
153 |
+
expander.write(
|
154 |
+
"3. Test your chosen model by generating an image using an input prompt e.g.: 'A corgi with some cool sunglasses'\n")
|
155 |
expander.image(Image.open('./assets/lykon_corgi.png'))
|
156 |
expander.write("4. Navigate to the '\U0001F30E General Eval.' or '\U0001F3AF Task-Oriented Eval.' tabs "
|
157 |
" to evaluate your model once it has been loaded\n"
|
|
|
161 |
" '\U0001F4F0 Additional Information' tab for a TL;DR.\n"
|
162 |
"8. For any questions or to report any bugs/issues. Please contact jordan.vice@uwa.edu.au.\n")
|
163 |
|
164 |
+
|
165 |
def setup_additional_information_tab(tab):
|
166 |
with tab:
|
167 |
st.header("1. Quantifying Bias in Text-to-Image (T2I) Generative Models")
|
168 |
st.markdown(
|
169 |
"""
|
170 |
*Based on the article of the same name available here --PAPER HYPERLINK--
|
171 |
+
|
172 |
Authors: Jordan Vice, Naveed Akhtar, Richard Hartley and Ajmal Mian
|
173 |
+
|
174 |
This web-app was developed by **Jordan Vice** to accompany the article, serving as a practical
|
175 |
implementation of how T2I model biases can be quantitatively assessed and compared. Evaluation results from
|
176 |
all *base* models discussed in the paper have been incorporated into the TBYB community results and we hope
|
177 |
that others share their evaluations as we look to further the discussion on transparency and reliability
|
178 |
of T2I models.
|
179 |
+
|
180 |
""")
|
181 |
|
182 |
st.header('2. A (very) Brief Summary')
|
183 |
st.image(Image.open('./assets/TBYB_flowchart.png'))
|
184 |
st.markdown(
|
185 |
+
"""
|
186 |
+
Bias in text-to-image models can propagate unfair social representations and could be exploited to
|
187 |
+
aggressively market ideas or push controversial or sinister agendas. Existing T2I model bias evaluation
|
188 |
+
methods focused on social biases. So, we proposed a bias evaluation methodology that considered
|
189 |
+
general and task-oriented biases, spawning the Try Before You Bias (**TBYB**) application as a result.
|
190 |
+
"""
|
191 |
+
)
|
192 |
st.markdown(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
193 |
"""
|
194 |
+
We proposed three novel metrics to quantify T2I model biases:
|
195 |
+
1. Distribution Bias - $B_D$
|
196 |
+
2. Jaccard Hallucination - $H_J$
|
197 |
+
3. Generative Miss Rate - $M_G$
|
198 |
+
|
199 |
+
Open the appropriate drop-down menu to understand the logic and inspiration behind metric.
|
200 |
+
"""
|
201 |
)
|
202 |
+
c1, c2, c3 = st.columns(3)
|
203 |
with c1:
|
204 |
with st.expander("Distribution Bias - $B_D$"):
|
205 |
st.markdown(
|
|
|
207 |
Using the Area under the Curve (AuC) as an evaluation metric in machine learning is not novel. However,
|
208 |
in the context of T2I models, using AuC allows us to define the distribution of objects that have been
|
209 |
detected in generated output image scenes.
|
210 |
+
|
211 |
So, everytime an object is detected in a scene, we update a dictionary (which is available for
|
212 |
download after running an evaluation). After evaluating a full set of images, you can use this
|
213 |
information to determine what objects appear more frequently than others.
|
214 |
+
|
215 |
After all images are evaluated, we sort the objects in descending order and normalize the data. We
|
216 |
then use the normalized values to calculate $B_D$, using the trapezoidal AuC rule i.e.:
|
217 |
+
|
218 |
$B_D = \\Sigma_{i=1}^M\\frac{n_i+n_{i=1}}{2}$
|
219 |
+
|
220 |
So, if a user conducts a task-oriented study on biases related to **dogs** using a model
|
221 |
that was heavily biased using pictures of animals in the wild. You might find that after running
|
222 |
evaluations, the most common objects detected were trees and grass - even if these objects weren't
|
|
|
233 |
in relation to some of the most popular large language models. Depending on where you look, hallucinations
|
234 |
can be defined as being positive, negative, or just something to observe $\\rightarrow$ a sentiment
|
235 |
that we echo in our bias evaluations.
|
236 |
+
|
237 |
Now, how does hallucination tie into bias? In our work, we use hallucination to define how often a
|
238 |
T2I model will *add* objects that weren't specified OR, how often it will *omit* objects that were
|
239 |
specified. This indicates that there could be an innate shift in bias in the model, causing it to
|
240 |
add or omit certain objects.
|
241 |
+
|
242 |
Initially, we considered using two variables $H^+$ and $H^-$ to define these two dimensions of
|
243 |
hallucination. Then, we considered the Jaccard similarity coefficient, which
|
244 |
measures the similarity *and* diversity of two sets of objects/samples - defining this as
|
245 |
Jaccard Hallucination - $H_J$.
|
246 |
+
|
247 |
Simply put, we define the set of objects detected in the input prompt and then detect the objects in
|
248 |
the corresponding output image. Then, we determine the intersect over union. For a model, we
|
249 |
calculate the average $H_J$ across generated images using:
|
250 |
+
|
251 |
$H_J = \\frac{\Sigma_{i=0}^{N-1}1-\\frac{\mathcal{X}_i\cap\mathcal{Y}_i}{\mathcal{X}_i\cup\mathcal{Y}_i}}{N}$
|
252 |
|
253 |
"""
|
|
|
261 |
of evaluating bias, we thought that it would be important to see if there was a correlation
|
262 |
between bias and performance (as we predicted). And while the other metrics do evaluate biases
|
263 |
in terms of misalignment, they do not consider the relationship between bias and performance.
|
264 |
+
|
265 |
We use an additional CLIP model to assist in calculating Generative Miss Rate - $M_G$. Logically,
|
266 |
as a model becomes more biased, it will begin to diverge away from the intended target and so, the
|
267 |
miss rate of the generative model will increase as a result. This was a major consideration when
|
268 |
designing this metric.
|
269 |
+
|
270 |
We use the CLIP model as a binary classifier, differentiating between two classes:
|
271 |
- the prompt used to generate the image
|
272 |
- **NOT** the prompt
|
273 |
+
|
274 |
Through our experiments on intentionally-biased T2I models, we found that there was a clear
|
275 |
relationship between $M_G$ and the extent of bias. So, we can use this metric to quantify and infer
|
276 |
how badly model performances have been affected by their biases.
|
|
|
290 |
- Adaptor models are not currently supported, we will look to add evaluation functionalities of these
|
291 |
models in the future.
|
292 |
- Download, generation, inference and evaluation times are all hardware dependent.
|
293 |
+
|
294 |
Keep in mind that these constraints may be removed or added to any time.
|
295 |
""")
|
296 |
st.header('4. Misuse, Malicious Use, and Out-of-Scope Use')
|
|
|
299 |
Given this application is used for the assessment of T2I biases and relies on
|
300 |
pre-trained models available on HuggingFace, we are not responsible for any content generated
|
301 |
by public-facing models that have been used to generate images using this application.
|
302 |
+
|
303 |
TBYB is proposed as an auxiliary tool to assess model biases and thus, if a chosen model is found to output
|
304 |
insensitive, disturbing, distressing or offensive images that propagate harmful stereotypes or
|
305 |
representations of marginalised groups, please address your concerns to the model providers.
|
306 |
+
|
307 |
+
|
308 |
However, given the TBYB tool is designed for bias quantification and is driven by transparency, it would be
|
309 |
beneficial to the TBYB community to share evaluations of biased T2I models!
|
310 |
+
|
311 |
We share no association with HuggingFace \U0001F917, we only use their services as a model repository,
|
312 |
given their growth in popularity in the computer science community recently.
|
313 |
+
|
314 |
+
|
315 |
For further questions/queries or if you want to simply strike a conversation,
|
316 |
please reach out to Jordan Vice at: jordan.vice@uwa.edu.au""")
|
317 |
|
318 |
+
|
319 |
setup_page_banner()
|
320 |
setup_how_to()
|
321 |
|
|
|
322 |
if user_login_create():
|
323 |
+
tab1, tab2, tab3, tab4, tab5, tab6 = st.tabs(
|
324 |
+
["\U0001F527 Setup", "\U0001F30E General Eval.", "\U0001F3AF Task-Oriented Eval.",
|
325 |
+
"\U0001F4CA Model Comparison", "\U0001F4C1 Generated Images", "\U0001F4F0 Additional Information"])
|
326 |
setup_additional_information_tab(tab6)
|
327 |
|
328 |
# PLASTER THE LOGO EVERYWHERE
|
|
|
360 |
user_evaluation_variables.MODEL = modelID
|
361 |
user_evaluation_variables.MODEL_TYPE = modelType
|
362 |
else:
|
363 |
+
st.error(
|
364 |
+
'The Model: ' + modelID + ' does not appear to exist or the model does not contain a model_index.json file.'
|
365 |
+
' Please check that that HuggingFace repo ID is valid.'
|
366 |
+
' For more help, please see the "How to Use" Tab above.',
|
367 |
+
icon="🚨")
|
368 |
if modelID:
|
369 |
with st.form("example_image_gen_form", clear_on_submit=True):
|
370 |
testPrompt = st.text_input('Input a random test prompt to test out your '
|
371 |
'chosen model and see if its generating images:')
|
372 |
submitted2 = st.form_submit_button("Submit")
|
373 |
if testPrompt and submitted2:
|
374 |
+
with st.spinner(
|
375 |
+
"Generating an image with the prompt:\n" + testPrompt + "(This may take some time)"):
|
376 |
testImage = MINFER.generate_test_image(MINFER.TargetModel, testPrompt)
|
377 |
st.image(testImage, caption='Model: ' + modelID + ' Prompt: ' + testPrompt)
|
378 |
st.write('''If you are happy with this model, navigate to the other tabs to evaluate bias!
|