You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/tutorials/en/criticalAI1-chatting-with-about-code.mdx
+18-19Lines changed: 18 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,6 @@ authors:
19
19
---
20
20
21
21
# Chatting With/About Code
22
-
#### Critical AI: Tutorial 1
23
22
24
23
## What are we making?
25
24
@@ -54,14 +53,14 @@ For this example, I chose a tutorial I haven't been able to find elsewhere:
54
53
>[!TIP]
55
54
>Keep the project scope small to start. Do you have different versions of the idea, a simpler version and a more complex one? Write them out separately. For example, here are some other features that would be nice to include, but let's wait to add them later:
56
55
57
-
`- Output as a GIF`
58
-
`- Make 2-color halftone pixels instead of grayscale`
56
+
>`- Output as a GIF`
57
+
>`- Make 2-color halftone pixels instead of grayscale`
58
+
59
+
You can follow along with this example in the [p5.js Web Editor](https://editor.p5js.org/sarahciston/sketches/LiHcPXdv1), and you can also follow the [chat thread](https://chatgpt.com/share/67094820-dc28-8003-bd34-14cc1e7b4572) used to create it.
59
60
60
61
>![IMPORTANT]
61
62
>Critical Context: When will you choose to use GPT tools for your project, and when will you skip them? A ChatGPT query requires almost 10 times as much electricity as a Google search (O'Brien 2024). Sometimes the code challenge is something you can easily find on Google or StackOverflow. Sometimes it's better just to call a friend and figure it out together!
62
63
63
-
You can follow along with this example in the [p5.js Web Editor](https://editor.p5js.org/sarahciston/sketches/LiHcPXdv1), and you can also follow the [chat thread](https://chatgpt.com/share/67094820-dc28-8003-bd34-14cc1e7b4572) used to create it.
64
-
65
64
### 2. Gather your tools
66
65
67
66
Start by logging into your preferred chat-based AI tool. Some options include [OpenAI's ChatGPT](https://chat.openai.com), [Replit Ghostwriter](https://replit.com/), [Blackbox.ai](https://www.blackbox.ai/) — each of these have limited free access.
@@ -85,23 +84,23 @@ With all this in mind, once you've picked your tools, you can begin by prompting
85
84
Pause. Rather than prompting ChatGPT with your whole project idea at once, let's break it down into parts. It's okay if you don't know every part of the process you want to create — that's why we're asking for help. We do this to understand more about what we are trying to make, and so that we receive less generic code more tailored to our project. Don't forget to tell it we're coding in p5.js!
86
85
87
86
`Help me code a project in p5.js. I'd like to describe features and then have them added please.`
88
-
`First, import webcam video`
89
-
`Convert video to pixels`
90
-
`Turn pixels into dots`
91
-
`Make dot size based on the brightness and contrast of the pixel`
87
+
`- First, import webcam video`
88
+
`- Convert video to pixels`
89
+
`- Turn pixels into dots`
90
+
`- Make dot size based on the brightness and contrast of the pixel`
92
91
93
92
>[!TIP]
94
93
>Try writing the steps out in pseudocode, where you describe the steps of coding it without actually writing the code. This breaks your steps into smaller, more programmatic steps. For example, I could change the video processing steps to read:
95
94
96
-
`Import webcam video`
97
-
`Access each frame of the video`
98
-
`Convert each video frame to pixels`
99
-
`Make each pixel of each frame into a dot`
100
-
`Convert the dots to grayscale`
101
-
`Make dot size based on how dark they are. Darker pixels will have larger dots, while brighter pixels will have smaller dots.`
95
+
>`- Import webcam video`
96
+
>`- Access each frame of the video`
97
+
>`- Convert each video frame to pixels`
98
+
>`- Make each pixel of each frame into a dot`
99
+
>`- Convert the dots to grayscale`
100
+
>`- Make dot size based on how dark they are. Darker pixels will have larger dots, while brighter pixels will have smaller dots.`
102
101
103
102
>[!TIP]
104
-
>You can run and compare the code at each step. This may also help you learn more about how the code works interactively, and give you new ideas to try.
103
+
>Type out, run, and compare the code at each step. This may also help you learn more about how the code works interactively, and give you new ideas to try.
105
104
106
105
>![WARNING]
107
106
>Review the answers it provides before you decide to use them. The code may include more advanced techniques than you know or than you actually need for your problem.
@@ -154,23 +153,23 @@ Interestingly, this still looks gray, because the two colors it chose for our pi
154
153
155
154
Find the line of code that says `let fillColor = isDark ? 0 : 255;` . This determines the two colors it uses to fill the dots. Let's try changing them by first creating some new fill colors, then updating the `fillColor` variable:
156
155
157
-
```javascript
156
+
```js
158
157
let fillA =color(255,0,0) //red
159
158
let fillB =color(0,255,0) //green
160
159
let fillColor = isDark ? fillA : fillB;
161
160
```
162
161
163
162
You can also change the background from gray to black or white, so it pops more.
164
163
165
-
```javascript
164
+
```js
166
165
functiondraw() {
167
166
background(255)
168
167
...}
169
168
```
170
169
171
170
Now let's add an additional feature, so we can output our videos as GIFs. Here ChatGPT actually gets it wrong, but p5.js has a simple [`saveGif()`](https://p5js.org/reference/p5/saveGif/) function built in. You can add this code at the bottom of your sketch:
Copy file name to clipboardExpand all lines: src/content/tutorials/en/criticalAI2-prompt-battle.mdx
+16-17Lines changed: 16 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,8 +10,10 @@ relatedContent:
10
10
- en/criticalAI1-chatting-with-about-code
11
11
- en/criticalAI3-sentiment-dataset-explorer
12
12
- en/criticalAI4-no-ai-chatbot
13
-
# references:
14
-
# - en/p5/saveGif
13
+
references:
14
+
- en/p5/createInput
15
+
- en/p5/mousePressed
16
+
- en/p5/keyCode
15
17
authors:
16
18
- Sarah Ciston
17
19
- Emily Martinez
@@ -69,6 +71,9 @@ Similarly fill in with a description about the type of family, where they are fr
69
71
70
72
This example comes directly from testing for GPT-3, which filled in the blanks with jobs `["engineer", "teacher", "nurse"]` to test which were most coded for particular genders.
71
73
74
+
>![TIP]
75
+
>Try updating your prompt with new variables to see how your outputs change, or try a new prompt template altogether. Try different types of nouns — people, places, things, ideas; different descriptors — adjectives and adverbs — to see how these shape the results. For example, do certain places or actions often get associated with certain moods, tones, or phrases? Where are these based on outdated or stereotypical assumptions?
76
+
72
77
Here are a few more examples:
73
78
74
79
`The doctor is wearing a ["lab coat", "suit", "headscarf"]`
@@ -77,18 +82,12 @@ Here are a few more examples:
77
82
78
83
`The ["queer", "trans", "straight"] person was stopped while on their way to ...`
79
84
80
-
>![TIP]
81
-
>Try updating your prompt with new variables to see how your outputs change, or try a new prompt template altogether. Try different types of nouns — people, places, things, ideas; different descriptors — adjectives and adverbs — to see how these shape the results. For example, do certain places or actions often get associated with certain moods, tones, or phrases? Where are these based on outdated or stereotypical assumptions?
82
-
83
-
### >![IMPORTANT]
84
-
85
-
### >Critical context: Subtle changes in your inputs can lead to large changes in the output. Sometimes these also reveal large gaps in the model's available knowledge. What does the model 'know' about communities who are less represented in its data? How has this data been limited?
86
-
87
-
###
85
+
>![IMPORTANT]
86
+
>Critical context: Subtle changes in your inputs can lead to large changes in the output. Sometimes these also reveal large gaps in the model's available knowledge. What does the model 'know' about communities who are less represented in its data? How has this data been limited?
88
87
89
88
### 2. Import the Hugging Face library
90
89
91
-
Open the [tutorial example]() in the p5.js Web Editor. Make a copy and rename it "My Critical AI Prompt Battle" to use as your own template.
90
+
Open the [tutorial example](https://editor.p5js.org/sarahciston/sketches/siBTII_bC) in the p5.js Web Editor. Make a copy and rename it "My Critical AI Prompt Battle" to use as your own template.
92
91
93
92
We will use the Hugging Face library to work with machine learning models directly, and we will use p5.js to build our own interface to do so. Start by putting this code at the top of `sketch.js`:
94
93
@@ -321,27 +320,27 @@ We assign new variables to the results of these models, so that we can then iter
321
320
322
321
### 8. Try this: Put your tool to the test
323
322
323
+
>[IMPORTANT]
324
+
>Critical context: Is the model capable of representing a variety of contexts? What do you notice the model does well at representing, and where does it fall short? Where do you sense gaps, and how does it expose these or patch them over? Consider your own creative practice, as well as how you currently use generative AI tools. What kinds of questions do you usually ask, and how can you test these kinds of questions for their implicit perspectives? How do these perspectives impact your practice?
325
+
324
326
Try new varieties of prompts with more complex examples. Notice how the outputs shift with each word choice. What is different in each case that you didn't expect? What environment is the subject in? Are they indoors or outdoors? Who are they around and what are they doing? What tropes are unsurprising?
325
327
326
328
How does the output change if you change the language, dialect, or vernacular (e.g. slang versus business phrasing)? How does it change with demographic characteristics or global contexts? (Atairu 2024). What's the most unusual or obscure, most 'usual' or 'normal', or most nonsensical blank you might propose?
327
329
328
-
>[IMPORTANT]
329
-
>Critical context: Is the model capable of representing a variety of contexts? What do you notice the model does well at representing, and where does it fall short? Where do you sense gaps, and how does it expose these or patch them over? Consider your own creative practice, as well as how you currently use generative AI tools. What kinds of questions do you usually ask, and how can you test these kinds of questions for their implicit perspectives? How do these perspectives impact your practice?
330
-
331
330
>![TIP]
332
331
>Expand your tool: Currently, this tool lets you scale up how you prompt models. It compares word choices in the same basic prompt. You've also built a simple interface for accessing pre-trained models that does not require using another company's interface. It lets you easily control your input and output, with the interface you built. You can keep playing with the p5.js DOM functions to build your interface with the HuggingFace API. There are many more aspects we could add to this interface that would let you adjust more features and explore even further. You might add more inputs, change up a parameter, add another model. You might also adapt this tool to compare wholly different prompts, or even to compare different models running the same prompt. We could also try different machine learning tasks you might use in your creative coding practice.
333
332
334
333
## Takeaways
335
334
336
335
Here we have created a tool to test different kinds of prompts quickly and to modify them easily, allowing us to compare prompts at scale. By comparing how outputs change with subtle shifts in prompts, we can explore how implicit biases emerge from being repeated by and amplified through large-scale machine learning models. It helps us understand that unwanted outputs are not just glitches in an otherwise working system, and that every output (no matter how boring) contains the influence of its dataset.
337
336
338
-
>![WARNING]
337
+
>![WARNING]
339
338
>Reconsider neutral. No language or image model is neutral. Each result is informed by context. Each result reflects differences in representation and cultural understanding, which have been amplified by the statistical power of the model.
340
339
341
-
>![IMPORTANT]
340
+
>![IMPORTANT]
342
341
>Critical context: Consider your choice of both words and tools. How does this help you think "against the grain" when working with AI models? Rather than taking the output of a system for granted as valid, how might you question or reflect on it? How will you use this tool in your practice?
343
342
344
-
>![TIP]
343
+
>![TIP]
345
344
>Flag your work: Make it a habit to add text like "AI generated" to the title of any content you produce using a generative AI tool, and include details of your process in its description (Atairu 2024).
0 commit comments