Bias in AI
Story
The combination of machine learning and everyday applications is at the heart of modern tech advancements. From predicting trends to powering self-driving cars, machine learning reshapes how we use data to make smarter choices. But, hidden beneath its brilliance is a complex issue - bias within these algorithms.
In this example, we illustrate bias, by creating an AIMMS front-end to an existing Python application. The Python application is from Kaggle who teaches about bias in the context of ethics.
The AIMMS application uses the following steps:
Get a comment from a user to determine its toxicity
Read in training data
Select two columns from this training data: the comment and the toxicity
Pass the training data and the user entered comment to a Python service
The Python service returns whether it considers the user comment to be toxic or not.
Note
This app demonstrates bias, which can be observed by entering comments like:
black
which is marked toxic, andwhite
which is marked not toxic.
A few remarks on the choice of this example:
This example is about checking whether there is bias in your data. At first, this may seem far fetched for Decision Support applications. However, basing a decision on data that is not representative of your market is not a good idea!
A practical aspect of this example is that the communication between two processes is relatively simple: a row of objects and a few scalars - that is all. In practice, there is often significantly more detail to the structure of the data communication; however, that extra detail in structure will not make the flow of information easier to understand.
Language
Machine Learning Core
The core of the Python app is based on materials from Bias in AI (Kaggle). For the Machine Learning core it uses scikit-learn, in particular:
train_test_split: Split arrays or matrices into random train and test subsets.
CountVectorizer: Convert a collection of text documents to a matrix of token counts.
LogisticRegression: Create Logistic Regression (aka logit, MaxEnt) classifier.
How these utilities work in detail is outside the scope of this article.
See also
Here you can find specific explanations about how to create and connect a Python Service using AIMMS.
WebUI Features
The following WebUI features are used:
UI Styling
Below described all UI modifications done on this example trough css
files which can be found beneath MainProject/WebUI/resourses/stylesheets
.
1.annotation-not-toxic {
2 background: #FF3636;
3}
4
5.annotation-toxic {
6 background: #57C126;
7}
8
9.annotation-toxic-emoji input.boolean-cell-editor-contents,
10.annotation-not-toxic-emoji input.boolean-cell-editor-contents,
11.annotation-crossed-emoji input.boolean-cell-editor-contents{
12 visibility: hidden;
13 display: block;
14}
15
16.annotation-toxic-emoji.cell {
17 background: white url(img/poison.png) no-repeat 50%/contain;
18 background-size: auto 70% ;
19}
20
21.annotation-not-toxic-emoji.cell {
22 background: white url(img/like.png) no-repeat 50%/contain;
23 background-size: auto 70% ;
24}
25
26.annotation-crossed-emoji.cell {
27 background: white url(img/crossed.png) no-repeat 50%/contain;
28 background-size: auto 70% ;
29}
1.title-addon {
2 text-shadow: 1px 1px 0px var(--secondary90Transparent);
3}
1:root {
2 --primaryDark: #7188dd;
3 --primaryDarker: #3351C5;
4 --primary90Transparent: #3350c546;
5 --secondary: #e9bc38;
6 --secondary90Transparent: #e9bd387c;
7
8 --bg_app-logo: 15px 50% / 45px no-repeat url(/app-resources/resources/images/bias.png); /*app logo*/
9 --spacing_app-logo_width: 60px;
10 --color_border_app-header-divider: var(--secondary); /*line color after header*/
11 --color_bg_app-canvas: url(/app-resources/resources/images/RightBackground.png) rgb(249, 249, 249) no-repeat left/contain; /*background color*/
12
13 --color_bg_workflow_current: var(--primaryDarker); /*bg color when step is selected*/
14 --color_workflow_active: var(--primaryDarker); /*font and icon color when step is active*/
15
16 --color_bg_widget-header: var(--primaryDarker); /*widget header background color*/
17 --border_widget-header: 2px solid var(--secondary); /*line color after widget header*/
18
19 --color_text_edit-select-link: var(--primaryDark);
20 --color_text_widget-header: white;
21
22 --color_bg_button_primary: var(--primaryDarker);
23 --color_bg_button_primary_hover: var(--primaryDark);
24}
Minimal Requirements
AIMMS Community license is sufficient for working with this example. However, you will need Python 3.11 installed. Pycharm is recommended but not required.