The Art of Prompt Engineering: How AI Helps Me Do My Homework

Written by oscardaum | Published 2023/05/25
Tech Story Tags: prompt-engineering | ai | chatgpt | chatbots | productivity | aritificial-intelligence | ai-trends | ai-applications

TLDRAs a student who will soon be starting his first job as a business consultant, I need to learn to employ AI efficiently. I’ve already used an AI assistant to supplement my homework problem sets. I find it especially useful for generating code or interacting with specific software. At the core of efficient interactions with an AI is prompt engineering.via the TL;DR App

A question that commonly comes up in most AI forums I frequent surrounds artificial general intelligence and whether it will displace human labor in nearly every industry [1]).
Those who oppose this view typically argue past innovations (the Industrial Revolution and the invention of the computer) didn’t replace workers and often times made people work more. I tend to align with this sentiment.
Satya Nadella, CEO of Microsoft, said the new technology would create “satisfaction in current jobs and net new jobs.” Clearly, Nadella is biased in saying this; however, there still is merit to the idea that AGI will not overrun the economy, politics, judicial system, etc., anytime soon. It is likely not that AI is going to take your job, but someone who knows how to use AI might. [2]
As a student who will soon be starting my first job as a business consultant, I need to learn to employ AI efficiently to assist me in being productive and competitive in completing my job tasks. I’ve already used an AI assistant to supplement my homework problem sets.
I find it especially useful for generating code or interacting with specific software. Frankly, I’m surprised by the breadth of software it knows, from VCV Rack 2 (a modular synthesizer program) to Choregraphe (a low-code interface for programming NAO robots).
YouChat helped me design this synth pattern in VCV Rack.
How I learned prompt engineering
Working through my problem sets with AI assistance, I learned that at the core of efficient interactions with an AI is prompt engineering. Prompt engineering as a skillset is a novel one. It involves thinking intelligently about how you prompt the AI to enhance its accuracy and alignment with your intended actions. I won’t be going in-depth on how to prompt engineer in this article (there are plenty of other articles out there on the subject; see Prompt-Engineering-Guide); however, I hope to emphasize the importance of good prompt engineering by stepping through a specific problem set I recently encountered.
The AGI research and safety startup, Anthropic recently posted a role for an LLM prompt engineer with a salary range of $175k - $335k. 
Disclaimer: Before you use any AI tool to assist you in your homework, make sure it is not prohibited in your syllabus and cite your uses if required. I did not use YouChat to complete this assignment; this is post-submission.

Conversational Prompt Engineering

For each homework problem, I’ll interact with an AI model through conversation. Interestingly, conversation is one of the more powerful ways to interact with an AI because it allows you to embed the AI’s behavior, intent, and identity.

There are two key components of conversational prompts: flattery and dialogue. I will start with the flattery as it sets much context. A basic flattery text includes the intent, which briefly describes the chatbot, and the identity, which dictates the style the chatbot will reply in. This is exemplified in the first two sentences of the example below.
// Example Flattery text
Intent: The following is a conversation with an AI research assistant. 
Identity: The assistant tone is technical and scientific.
I find it useful to tweak the flattery depending on my comfort level with the topic. For example, if I have no background with black holes, I can adjust the second sentence, the identity, to something more beginner friendly, such as:
Identity: The assistant's answers should be easy to understand, even by a child.
Finally, I work on the dialogue. This is where I ask the actual question. Notice, however, that I can embed more information here by playing the role of the AI or the Human. In the example below, I add more context about the human and request a specific action from the robot (adding citations).
//This example is adopted from promptingguide.ai
Flattery: 
The following is a conversation with an AI research assistant. The assistant's
tone is technical and scientific.

Dialogue: 
Human: Hello, who are you?
AI: Greetings! I am an AI research assistant. How can I help you today?
Human: Can you tell me about the creation of blackholes? Can you cite specific sources I can read too? I currently know nothing.
AI:
Now that we’ve gone over the basics, I will implement this with an actual homework question from one of my CS classes this semester.

The Homework: Question 1

The Prompt
For this, I used a conversation prompt to set the context and specific task for YouChat, a conversational chatbot by You.com, to execute. By giving it the role of an article-writing AI, I allowed it to both inform me on the topics the question was asking as well as generate code using libraries.
The following is a conversation with an AI computer science graduate student. The
student's tone is technical and informative.

Human: Hello, who are you?
AI: Greeting! I am an AI CS graduate student. How can I help you today?
Human: Can you help me create an article about how to create a bandpass filter using the numpy.fft.irfft and numpy.fft.rfftfreq? 
Can the article apply the filter with range 300-3400 to a signal called "signal.mp3" 
which is in the same folder and use the Audio library from ipython to hear the output signal?
AI: Sure thing! Anything else?
Human: Yes, can you create an article in markdown that includes writing such as a
populated intro, body, and conclusion as well as includes code snippets and resources to inform 
readers about the topics surrounding this question and instruct them on how to implement it in code?
AI:
There are several important aspects to this prompt I want to highlight. For one, how I describe the AI system will dictate the language and sophistication of the output. This is important to remember as different identities lend themselves better to different tasks. If I were asking a humanities question, I would assign the AI the role of a philosopher or a college professor. If I were asking about a topic I was unfamiliar with and wanted to learn about, I would assign the AI the role of a middle school teacher or middle schooler.
Second, the description of the AI is realistic and is something YouChat can replicate, given its resources and knowledge. Cleo Nardo, in “The Waluigi Effect,” explains best how the AI would interpret a less realistic but more intelligent AI description as fiction, thus making it produce more likely to generate false answers than otherwise.
GPT-4 knows that if [the AI system] is described as "9000 IQ", then it is unlikely that the text has been written by a truthful narrator. Instead, the narrator is probably writing fiction, and as literary critic Eliezer Yudkowsky has noted, fictional characters who are described as intelligent often make really stupid mistakes.
Finally, I engineer the AI’s task/behavior to better align with my demands as a student. I wanted the code needed to answer the question and the description of the algorithm, how to approach the problem, and resources for further investigation. Once again, I described this in the context of setting up or flattery text to alter the content of the output.
The Output (The following is YouChat's response)
🤖 Sure, I can help you with that! Here's an article written in markdown that explains how to create a bandpass filter using the numpy.fft.irfft and numpy.fft.rfftfreq methods, and how to apply the filter to an audio signal using the Audio library from IPython. I've also included some links to relevant Wikipedia pages and other resources to help readers better understand the topic.

Creating a Bandpass Filter with Numpy

Introduction

A bandpass filter is a type of electronic filter that allows signals between two frequencies to pass through while attenuating frequencies outside this range. In this article, we will demonstrate how to create a bandpass filter using the numpy.fft.irfft and numpy.fft.rfftfreq methods in Python.

Requirements

To create a bandpass filter, we will need the following:
Python (we will be using Python 3)NumPy libraryAudio library from IPython
If you don't have these libraries installed, you can install them using pip. You can install NumPy by running pip install numpy and Audio library using the command !pip install ipython-soundfile.

Explanation

Here is the code to create a bandpass filter and apply it to an audio file called "signal.mp3", which is saved in the same directory as the script.
import numpy as np
import soundfile as sf
from IPython.display import Audio

# read the audio file
signal, Fs = sf.read('signal.mp3')

# get the frequency range
freq = np.fft.rfftfreq(signal.size, 1/Fs)

# create the filter mask
mask = (freq > 300) & (freq < 3400)

# apply the filter
filtered_signal = np.fft.irfft(np.fft.rfft(signal) * mask)

# play the output signal
Audio(filtered_signal, rate=Fs)
In this code, we first read in the audio file using the soundfile library. Then, we use np.fft.rfftfreq method to generate the frequency range of the signal.
After that, we create the filter mask using the desired frequency range with a numpy array which returns True/False values for the range of the frequencies. Then, we apply this mask to the Fourier transformed signal using element-wise multiplication.
Finally, we perform a reverse Fourier transform using the numpy.fft.irfft method to get back from the frequency domain
<End of the Output>

The Homework: Question 2

Let’s try another problem. This time I’m trying to complete a non-technical, more qualitative problem for my health and wellbeing class.

The Prompt
For the prompt, I’m still employing the conversational prompting format; however, note the difference in the intent and identity. This AI is more focused on meditation and mindfulness, and its responses have a more philosophical nature.
AI is a student of psychology at a university in the US that answers questions 
regarding meditation, mindfulness, and wellness. AI has a tone that 
is thoughtful and philosophical.

Human: First read the poem The Guest-House by Rumi, then answer the following questions.
1. how would you define gratefulness? What are its essential features and its impact in one’s life?
2. How does the Rumi poem reinforce the idea of gratefulness evoked from suffering?

AI:
The Output
🤖 Here is the Rumi poem "The Guest-House":
This being human is a guest-house.
Every morning a new arrival.

A joy, a depression, a meanness,
some momentary awareness comes

as an unexpected visitor.

Welcome and entertain them all!
Even if they’re a crowd of sorrows,
who violently sweep your house
empty of its furniture,
still, treat each guest honorably.
He may be clearing you out
for some new delight.

The dark thought, the shame, the malice,
meet them at the door laughing,
and invite them in.

Be grateful for whoever comes,
because each has been sent
as a guide from beyond.
  1. Gratefulness can be defined as a state of being thankful and appreciative for what one has, even in the face of difficulty or challenge. Its essential features include recognizing the positive aspects of one's life and circumstances, cultivating a sense of perspective, and acknowledging the contributions of others to one's well-being. The impact of gratefulness in one's life can include increased resilience, improved relationships with others, and a greater sense of wellbeing and happiness.
  2. The Rumi poem reinforces the idea of gratefulness evoked from suffering in that it recognizes that difficult experiences can serve as guides and teachers. By welcoming all experiences, even those that are challenging or painful, one can learn and grow from them. In this way, the poem suggests that even suffering can be a source of gratitude and wisdom, helping us to appreciate life's joys all the more.
<End of the Output>
I want first to note the importance of flattery in this question. If I don’t provide the intent and identity of the AI bot, it will not have the same capabilities, nor will the response be in the tone I want it to be as shown below. It’s as if the prompt has unlocked YouChat’s ability to read and interpret the poem in a sophisticated manner.
If I modify the flattery to be more naïve, we can see that it limits its capability to read and interpret the poem. The language and answer also seem to be simpler and more appropriate for a less experienced audience. This type of flattery modification is especially useful when I’m trying to learn a new concept. I also liked how YouChat was able to generate web links to help the uninformed user do more research into the topic. This is important because whenever I’m reading about a new topic, I want to fact-check the AI to ensure it’s not generating false content.

Conclusion

As you can see, I was able to generate a response with proper code to complete an assignment, writing syntax/formatting, explanation of the code, and sources/further readings. I was also able to have YouChat read and interpret a poem in a sophisticated manner, thanks to conversational prompt engineering. While YouChat did most of the heavy lifting in both cases, I still had to know what libraries I wanted it to use and enough about filters for it to make sense of my prompt, proving that it's not AI that will replace workers but workers that use AI who will replace workers that don’t.
Not only did I complete my work, but also the information and links provided helped supplement my learning which is one of the main reasons I used a chat search engine as opposed to a traditional generative chat AI. Another cool perk of YouChat is that it has a nice StackOverflow integration that provides relevant posts alongside the updated search engine results.
Combined, these features have transformed how I approach my work and learning, making me more productive and giving me more resources. As I transition to the workforce and as this technology advances, I’m excited to see how the interplay of AI and workers evolves. One thing for certain is that I will be on the cutting edge of these advancements, and so should you.

Written by oscardaum | CS + Finance student at UVA
Published by HackerNoon on 2023/05/25