A Practical Take on Prompt Engineering
Source: DALL-E 3 |
Imagine crafting a sleek, minimalist generative AI application designed to streamline our all-too-human shortcomings in spelling and grammar. Sounds practical, right? Well, here’s a lesson I learned along the way: utilize prompt engineering to ensure that the app avoids pesky hallucinations.
Agile development
I quickly assembled this app using just fifty-ish lines of Python code. I also crafted a system prompt to guide the large language model (LLM) towards generating the desired output.
Here’s a peek at the original prompt:
|
Well, perhaps too agile...
I discovered after running a few emails and blog posts through the app that its generated output was a bit too foot loose and fancy free. The LLM got confused about splitting the results into two distinct sections that I wanted. Plus, it started seeing spelling and grammar errors that were not there - classic LLM hallucinations.
Source: DALL-E 3 |
The hallucinations were more frequent when I submitted text that was clean in the first place. The LLM appeared confused, trying to please the boss by attempting to correct nonexistent errors.
Here is the original input text:
And here is the output the LLM generated. The blue box highlights an error that isn't, and the purple highlights corrected text that wasn't:
Making adjustments
No problem, though. I sharpened my pencil and rewrote the prompt to be more specific on what I wanted to see and how it should be formatted:
|
This revision of the prompt clearly states the requirements. It also emphasizes what the model should and should not return.
Cleaner output
With increased focus and direction, the LLM got its act together, emitting well-organized responses. The new prompt provided the necessary, additional context, eliminating hallucinations. Now, the generated content is consistent and reliable, just as we expect.
Feel free to fork
Curiosity piqued? Dive into the code on my GitHub and experiment with different models and prompts.
This fascinating example of AI refinement not only will enhance written communication, but also offers a glimpse into the future of personalized technology, accessible straight from your laptop. If you'd like to discuss this further, feel free to connect with me on LinkedIn.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.