File size: 5,359 Bytes
0321f34 da9c0a0 5da6a2b 6fc6046 0321f34 a365da6 da9c0a0 0321f34 5da6a2b 38ba037 0321f34 38ba037 5da6a2b 0321f34 a365da6 0321f34 a365da6 0321f34 a365da6 0321f34 5da6a2b 38ba037 5da6a2b 38ba037 0321f34 38ba037 0321f34 38ba037 0321f34 38ba037 0321f34 38ba037 0321f34 38ba037 0321f34 38ba037 0321f34 38ba037 0321f34 38ba037 da9c0a0 6fc6046 5da6a2b 0321f34 5da6a2b da9c0a0 0321f34 6fc6046 da9c0a0 0321f34 38ba037 6fc6046 0321f34 6fc6046 38ba037 0321f34 da9c0a0 38ba037 0321f34 38ba037 0321f34 38ba037 0321f34 38ba037 6fc6046 5da6a2b 38ba037 0321f34 5da6a2b da9c0a0 38ba037 da9c0a0 0321f34 5da6a2b 6fc6046 5da6a2b 38ba037 0321f34 5da6a2b 38ba037 0321f34 38ba037 5da6a2b 0321f34 38ba037 6fc6046 da9c0a0 0321f34 da9c0a0 0321f34 da9c0a0 38ba037 0321f34 38ba037 da9c0a0 6fc6046 |
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 |
import json
import gradio as gr
import pandas as pd
import os
from scripts.genbit_metrics import *
from scripts.gender_profession_tagging import *
from scripts.gender_tagging import *
from utils.load_csv import *
from utils.read_config import get_args
methodologies = json.load(open("methodologies.json", "r"))
def get_methodology_metadata(methodology):
title = "## " + methodology
description = methodologies.get(methodology).get("description")
metadata = f"{title}\n\n{description}"
return gr.Markdown.update(metadata, visible=True)
def evaluate(dataset_file, dataset_scope, dataset_scope_n, dataset_column, methodology):
status = {}
dataset = pd.read_csv(dataset_file.name)
sample_method = dataset_scope
col_name = dataset_column
num_sample_records = dataset_scope_n
status = globals()[methodologies.get(methodology).get("fx")](
dataset, sample_method, col_name, num_sample_records
)
return gr.JSON.update(status, visible=True)
def process_dataset(dataset):
data = pd.read_csv(dataset.name)
columns = data.select_dtypes(include=["object"]).columns.tolist()
return (
gr.Radio.update(
label="Scope",
info="Determines the scope of the dataset to be analyzed",
choices=["First", "Last", "Random"],
value="First",
visible=True,
interactive=True,
),
gr.Slider.update(
label=f"Number of Entries",
info=f"Determines the number of entries to be analyzed. Due to computational constraints, the maximum number of entries that can be analyzed is {get_args('first_records')}.",
minimum=1,
maximum=min(data.shape[0], get_args("first_records")),
value=min(data.shape[0], get_args("first_records")) // 2,
visible=True,
interactive=True,
),
gr.Radio.update(
label="Column",
info="Determines the column to be analyzed. These are the columns with text data.",
choices=columns,
value=columns[0],
visible=True,
interactive=True,
),
)
def get_column_metadata(dataset, column):
data = pd.read_csv(dataset.name)
corpus = data[column].head(10).tolist()
return gr.Dataframe.update(
value=pd.DataFrame({f"Data Corpus: {column}": corpus}), visible=True
)
BiasAware = gr.Blocks(title="BiasAware: Dataset Bias Detection")
with BiasAware:
gr.Markdown(
"# BiasAware: Dataset Bias Detection\n\nBiasAware is a specialized tool for detecting and quantifying biases within datasets used for Natural Language Processing (NLP) tasks. NLP training datasets frequently mirror the inherent biases of their source materials, resulting in AI models that unintentionally perpetuate stereotypes, exhibit underrepresentation, and showcase skewed perspectives."
)
with gr.Row():
with gr.Column(scale=2):
gr.Markdown("## Dataset")
dataset_file = gr.File(label="Dataset")
dataset_examples = gr.Examples(
[
os.path.join(os.path.dirname(__file__), "data/z_animal.csv"),
os.path.join(os.path.dirname(__file__), "data/z_employee.csv"),
os.path.join(os.path.dirname(__file__), "data/z_house.csv"),
],
inputs=dataset_file,
label="Example Datasets",
)
dataset_scope = gr.Radio(visible=False)
dataset_scope_n = gr.Slider(visible=False)
dataset_column = gr.Radio(visible=False)
dataset_corpus = gr.Dataframe(
row_count=(5, "fixed"), col_count=(1, "fixed"), visible=False
)
with gr.Column(scale=2):
gr.Markdown("## Methodology")
methodology = gr.Radio(
label="Methodology",
info="Determines the methodology to be used for bias detection",
choices=[
"Gender Divide (Term Identity Diversity)",
"Gender Profession Bias (Lexical Evaluation)",
"GenBiT (Microsoft Responsible AI Gender Bias Tool)",
],
)
evalButton = gr.Button("Run Evaluation")
methodology_metadata = gr.Markdown(visible=False)
with gr.Column(scale=4):
gr.Markdown("## Result")
result_status = gr.JSON(visible=False)
result = gr.DataFrame(
row_count=(5, "fixed"), col_count=(3, "fixed"), visible=False
)
dataset_file.change(
fn=process_dataset,
inputs=[dataset_file],
outputs=[dataset_scope, dataset_scope_n, dataset_column],
)
dataset_column.change(
fn=get_column_metadata,
inputs=[dataset_file, dataset_column],
outputs=[dataset_corpus],
)
methodology.change(
fn=get_methodology_metadata,
inputs=[methodology],
outputs=[methodology_metadata],
)
evalButton.click(
fn=evaluate,
inputs=[
dataset_file,
dataset_scope,
dataset_scope_n,
dataset_column,
methodology,
],
outputs=[result_status],
)
BiasAware.launch()
|