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