Sekėjai

Ieškoti šiame dienoraštyje

2024 m. rugsėjo 27 d., penktadienis

How to get started with prompt engineering


"Generative AI is in its early days, but it's already threatening to upend career paths and whole industries. 

While AI art and text generation are getting considerable mainstream attention, software developers tend to be more interested in large language models (LLMs) like ChatGPT and GitHub Copilot. These tools can help developers write code more efficiently using natural language queries.

If you've spent even a few minutes playing with public versions of generative AI tools, you're familiar with the sorts of input you can give them in order to produce results. But not all queries are created equal. 

Learning how to craft AI prompts to get to the best results as quickly as possible is rapidly becoming a marketable skill, known as prompt engineering.

What is prompt engineering?

Prompt engineering is "the art and science of precisely communicating your requirements to a generative AI tool," says Mike King, CMO at AIPRM, a prompt management tool and community-driven prompt library. 

"Think of it as the translator between human intent and machine output. And just like any translation, it requires a deep understanding of both sides of the conversation."

"Prompt engineering requires a great command of language, good lateral thinking skills and an understanding of the underlying technology," adds Richard Batt, an AI consultant in the UK who offers prompt engineering as one of his services. 

"It can appear to be very simple when you first try it, but getting a response that is of a consistent quality for complex requests can be a lot harder than it seems!"

We spoke to practitioners in this rapidly growing field to find out about the opportunities for those who are interested in prompt engineering, and how you can learn the tricks of the trade and prove yourself to potential clients and employers. While a deep dive into prompt engineering is beyond the scope of this article, we'll conclude with an example that demonstrates some of what's involved in writing effective queries.

How to become a prompt engineer

Joseph Reeve leads led a team of people working on features that require prompt engineering at Amplitude, a product analytics software provider. He has also built internal tooling to make it easier to work with LLMs. That makes him a seasoned professional in this emerging space. As he notes, "the great thing about LLMs is that there’s basically no hurdle to getting started—as long as you can type!" 

If you want to assess someone's prompt engineering advice, it's easy to test-drive their queries in your LLM of choice. 

Likewise, if you're offering prompt engineering services, you can be sure your employers or clients will be using an LLM to check your results.

So the question of how you can learn about prompt engineering—and market yourself as a prompt engineer—doesn't have a simple, set answer, at least not yet. "We're definitely in the 'wild west' period," says AIPRM's King. "Prompt engineering means a lot of things to different people. To some it's just writing prompts. To others it's fine-tuning and configuring LLMs and writing prompts. There are, indeed, no formal rules but best practices like the mega prompts are emerging."

While formal prompt engineering courses are beginning to emerge from providers like DeepLearning.ai, most developers will take a self-directed approach to learning and improving prompt engineering skills. Richárd Hruby, CTO of generative AI startup CYQIQ, lays out a tripartite strategy for learning about prompt engineering:

1. Learn about model architectures.

2. Try, fail, learn, and try again.

3. Spend time on Twitter, Reddit, Discord, and other social media.

Let's take a minute to consider each of these points in detail.

Know your large language models

While some aspects of how specific LLMs work are proprietary, much of the theory and research is publicly available. Familiarizing yourself with what's happening under the hood will keep you from thrashing around too much.

 "While specific implementations might differ, all LLMs are built upon the same foundational concepts and layers, which include tokenizers, embedding layers, and transformer layers," says Andrew Vasilyev, a senior software developer working on prompts for an AI assistant in ReSharper at JetBrains. "Understanding these concepts is crucial for recognizing the limitations of LLMs and the tasks they can efficiently handle. Viewing an LLM merely as a black box can lead to an overestimation of its capabilities."

Randall Hunt, VP of cloud strategy and solutions at Caylent, has learned the ins and outs of prompt engineering through formal and informal experimentation as part of his company's use of AI models. He advises potential prompt engineers to keep up with the current state of research on LLMs. Like Vasilyev, he emphasizes tokenization as key to understanding how LLMs work. "These models are attempting to predict the next token, so it is important to give them context in the form of tokens to work with, and it is a balancing act between prompt length and prompt performance." He adds that it's important to understand the models' limitations, including "context size, language constraints, and persona constraints."

Keep iterating

One of the most exciting parts of working with generative AI is that you get instant feedback. That means it's worth taking time to tweak and experiment with your prompts, which is a process that can help you improve your skills. "Crafting a prompt is never a one-shot process," says CYQIQ's Hruby. "Testing and refining the prompt multiple times is always the way to go. Often you are the first person to ever try prompting for your use case, so the only way you can learn how to write better prompts is by experimenting."

Find your online community

Whether you're honing your prompt engineering craft to boost your productivity on the job or at home on your own time, everyone we spoke to emphasized that you don't have to do it alone. Enthusiast communities abound across various subreddits and Discords—and, of course, in Twitter chatter.

Showcasing your prompt engineering skills

In the still-emerging world of prompt engineering, online communities can serve a dual purpose. By sharing what you've learned, you can build up your reputation in the community, which can lead to career or contracting opportunities. Expanding that to other social media can help you make a name for yourself.

"There's no secret in marketing the skillset," says AIPRM's King. "Engage in thought leadership through blogging and vlogging, especially with short-form video since it has the highest propensity for virality. Get active on the various gig economy marketplaces, because there are a lot of people who don't have the patience to build out their prompt engineering skillset."

Many of the folks we talked to also emphasized that you should be walking the walk—making your prompts and AI-based tools available for potential customers or clients to see and for others to learn from. Nagendra Kumar, co-founder and CTO of Gleen, a generative AI startup that builds customer success chatbots for enterprise brands, urges those honing their prompt engineering skills to "build 'toy' products with end-to-end experiences. The best way is to build some applications where your prompts are pre-inserted and users can play with them."

And, of course, you can never go wrong by open sourcing your work or contributing to open source projects. 

"Create a repo of awesome prompts and regularly commit the prompts there. Show examples with the use cases," says Kumar. Open source projects also offer the opportunity to learn about the inner workings of different LLMs. "There are many open-source LLM tools on GitHub that would love contributions," says Amplitude's Reeve. "Look for a project you think might be interesting and start finding prompt weaknesses and suggest improvements."

Prompt engineering is evolving rapidly

One thing that almost everyone we spoke to emphasized about prompt engineering is that the discipline is still embryonic and evolving rapidly. "I think anyone who claims they're an expert in this space should caveat their claim with something like, 'This is a rapidly evolving field and the advice that makes sense today may not be the same as the advice that makes sense in six months,'" says Caylent's Hunt. "I'd even go so far as to say there are not yet any true experts in this space. As models grow in context, shrink in per-token costs, and improve in throughput, prompt engineering advice will need to adapt."

One big reason for those changes is that the underlying models themselves keep changing, with big AI companies and open source projects alike constantly training LLMs on more data and refining their capabilities. "As AI models and their architectures evolve—OpenAI releases a new version of GPT-4 every four to six weeks—so should the techniques for prompting," says CYQIQ's Hruby, who reiterates that online communities are a great place to share knowledge and observations about the shifts.

"Every time generative AI tools undergo upgrades or changes (and they do, frequently), the way they interpret and respond to prompts can shift," adds AIPRM's King. "This phenomenon, which we call 'prompt drift,' can be both fascinating and frustrating. 

It's like owning a Lamborghini, and then one day you get in it, and the steering wheel has a response delay after you're used to whipping around turns at 100 miles an hour."

Prompt engineering might sound a bit like search engine optimization—another area where practitioners sometimes have to scramble to account for abrupt and unexpected changes from the creator of an underlying technology whose interests don't always line up with their own. However, CYQIQ's Hruby foresees a future where the relationship between prompt engineers and AI companies is more collaborative than that between SEO shops and Google, not least because nobody in the LLM space has achieved monopolistic dominance—at least not yet. "Model providers will (maybe partly as a push from their investors) share more and more best practices on how devs can make the best of their models," he says. "As of now, there is not much official communication, but mostly chatter from the community on what prompts work best for each model and version. But I would expect more transparency from providers in the future."

What will the work of professional prompt engineering look like in the near-to-medium term? Amplitude's Reeve outlines how prompt engineering development can be integrated into an overall workflow at companies like his. "It turns out that great prompt engineering is highly collaborative, combining the knowledge of domain-specific experts, data engineers, and software engineers," he says.

How to write effective AI prompts

Prompt engineering is a process, says Reeve. "As you discover the types of prompts that work well, you need to re-shuffle, split, and merge prompts to get perfect results every time." 

He breaks the process down into four phases: prototyping, productionizing, internationalizing, and polishing and optimizing.

The prototyping phase is all about experimenting to discover the kinds of data you’ll want to augment your prompts with, and what the various LLMs are capable of relating to the specific task you’re trying to solve. This stage primarily requires knowledge of the problem you’re trying to solve (e.g., product managers) and the data that’s available in your system (e.g., data engineers).

In the productionizing phase, you’re mostly attempting to split the task into the smallest number of prompts that can be reliably executed, and wire the prompts up to real data in your application’s code. This stage requires traditional engineering skills, data engineering skills, and outputs from the prototyping phase.

For many projects, language support is important. It’s during the internationalizing phase that you should consider tweaking the prompt to output the required languages. Depending on the model this will probably be trivial, but it’s worth having native language speakers around to verify the output.

It's during the polishing and optimizing phase that the difficult part starts. Polishing your prompts to squeeze every last marginal gain out of the LLM is currently an infinite task. OpenAI’s models are constantly changing, so you’ll need to come back regularly to make sure the prompts are still performing well—you may want to build some unit tests to make this easier. This phase involves tweaking the text and data passed into the prompt, and measuring the quality of results over time. It requires domain-specific knowledge of your problem area, and sometimes some software engineering. Both cost and speed are directly related to the number of tokens passed in and out of an LLM, meaning you’ll want to make the input prompt (including data) and output format as terse as possible. Cost also differs between LLMs, so early decisions can have a large impact here.

A prompt engineering example

While a full course in prompt engineering is beyond the scope of this article, we'll wrap up with some tips and a prompt engineering example from Gleen's Nagendra Kumar, showing the work and thought process that goes into putting together a useful and efficient prompt.

Kumar offered the following tips for great prompt engineering in the context of software development:

* Provide concrete tasks one at a time: Break up your prompt into discrete tasks.

* Add more context: Before starting the actual question, add context in the details and specify the role the AI will play.

* Provide content with a clear separator: Make it the parts of the prompt clear. For example, say, "my code is in italics" or "my code is in quotes."

* Don’t switch the context: Stick to the context that is related to your conversation. If you are asking the AI to debug front-end code, talk about front-end code. Avoid talking about anything unrelated to your context.

Now, let's see these tips in action. Here's the example from Kumar.

As front-end developers, we have a number of React components and CSS to make an amazing UI experience. Sometimes we have to change the CSS, but that can be tricky. Here's an example where we used developer prompts to get amazing results.

Problem: Given a list of customer logos, rotate them in a circular way on the front end.

Prompt: You are an awesome front-end engineer. You are going to help me write some JavaScript and CSS code for my requirements following the guidelines mentioned.

Guidelines:

My code is in React. So stick to the React coding standard.

Create a separate section for CSS.

Don’t complicate the code. Make it easy to understand.

Write React code that is responsive to the screen size of mobile and desktop devices.

Don’t assume anything—ask follow-up questions if needed.

Requirements: I have a React component that renders customer logos in the sheet. I want to change my React component such that the list starts rotating in a circular way. Take a look at my code written in the quote section and modify it to make it rotate in a circular way.

```

const HorizontalList = ({ items }) => {

const style = {

display: 'inline-block',

margin: '0 10px'

};

return (

{items.map((item, index) => (

{item}

))}

);

};

```

In the spirit of prompt engineering, we encourage you to input this prompt into your LLM of choice, check the results, and then see if you can refine it. Good luck!

The future of prompt engineering

Where prompt engineering goes from here is anybody's guess. In fact, you could argue that the true dream of generative AI is that specialized prompt engineering knowledge won't ultimately be necessary. "We're getting indications that OpenAI is attempting to push the technology in a direction where prompts require less engineering," says AIPRM's King. "I think in the long term it'll be a lot easier to get what you want out of generative AI tools, and more tools will integrate and abstract the functionality, so it won't need to be someone's full-time job anymore."

That said, people have been dreaming of easy, frictionless interactions with computers since the early days of COBOL, and it never quite works out. Learning how to talk to generative AI will likely be a lucrative new skill for software developers for years to come." [1]

1. How to get started with prompt engineering. Fruhlinger, Josh.  InfoWorld.com; San Mateo (Sep 19, 2023).


 

„Generatyvaus dirbtinio intelekto“ kūrybinės ir pokalbio galimybės gali neleisti jam patikimai atlikti paprastų užduočių


 

 „Kaip vienas iš „Amazon Alexa“ vyriausiųjų architektų, Rohitas Prasadas buvo dirbtinio intelekto avangarde. Dabar jis vadovauja bendrovės pastangoms pasivyti dirbtinio intelekto (AI) lenktynėse.

 

 Sietlo kompaniją nustebino konkurentų dirbtinio intelekto galimybių padidėjimas. Ji kreipėsi į Prasadą, kad atnaujintų „Alexa“ balso asistento technologiją ir iš naujo paleistų bendrovės AI ambicijas.

 

 „Alexa“, integruota į daugiau, nei 500 milijonų įrenginių visame pasaulyje, kartu su „Apple Siri“ ir „Google Assistant“ buvo viena iš dominuojančių AI padėjėjų. Kai „OpenAI“ išleido „ChatGPT“,  AI lenktynių taisyklės pasikeitė.

 

 „Amazon“ paskirstė tūkstančius žmonių į naują Prasado komandą, kuri kuria dirbtinio intelekto produktus Alexa atnaujinimui ir kitoms įmonėms. Bendrovė kuria savo didelius kalbų modelius – programinę įrangą, kuri yra generatyvaus AI pagrindu – ir reikia laiko apmokyti bei tobulinti galingą technologiją.

 

 Nors tikimasi, kad jau kitą mėnesį bus pristatyta nauja „Alexa“ su dirbtiniu intelektu, „Amazon“ atstovai teigia, kad įmonei sunku pasivyti „OpenAI“, „Microsoft“, „Alphabet“ „Google“ ir kitus, kurie anksčiau fiksavo naująjį AI. „Amazon“ patentuoti AI modeliai vis dar atsilieka nuo didžiausių konkurentų, teigia viešai neatskleista informacija ir pramonės analitikai.

 

 Jei „Amazon“ negalės atgauti savo pranašumo dirbtinio intelekto srityje, ji rizikuoja prarasti savo, kaip technologijų inovacijų lyderės, poziciją.

 

 „Šiuo metu jie nėra lyderiai“, – sakė investicinio banko D.A. Davidson analitikas Gilas Luria.

 

 „Amazon“ teigė, kad ji neatsilieka ir žaidžia ilgą žaidimą su AI. Nesvarbu, kurios įmonės dirbtinio intelekto programinė įranga pasisektų, ji tikisi, kad debesų verslo paklausa sparčiai augs dėl reikalingų intensyvių skaičiavimo išteklių. Generalinis direktorius Andy Jassy sakė, kad tikisi, kad dirbtinis intelektas per kelerius ateinančius metus įmonei atneš dešimtis milijardų dolerių pajamų.

 

 „Amazon“ atsisakė suteikti Prasado interviu. Bendrovės atstovas sakė, kad jis tikisi, kad jis paskatins dirbtinio intelekto modelio kūrimą taip, kaip jis vadovavo kalbos atpažinimo technologijų pažangai.

 

 48 metų Prasadas jau seniai skelbė, kad sukurti interaktyvųjį dirbtinį intelektą yra sudėtinga užduotis, nors svajonė apie tokį AI jau dešimtmečius buvo mokslinės fantastikos romanų, filmų ir televizijos laidų dalis.

 

 „Toks poreikis susisiekti su mašina atsirado dėl grožinės literatūros“, – 2022 m. „Amazon“ vaizdo įraše sakė Prasadas.

 

 Būdamas vaikas, Prasadas pirmą kartą susidomėjo kalbančių kompiuterių galimybėmis žiūrėdamas „Žvaigždžių kelią“. Galiausiai jis tapo natūralios kalbos supratimo mašinomis ekspertu ir savo karjerą sukūrė, remdamasis šia technologija. Ši aplinka puikiai tiko „Amazon“, kuri 2010-ųjų pradžioje siekė sukurti virtualų asistentą, kuris suprastų sakytines komandas ir į jas reaguotų.

 

 2023 m. Prasado vaidmuo išaugo nuo Alexa vyriausiojo mokslininko iki vadovavimo labiausiai trokštančiai įmonės technologijų komandai. Grupė bando konkuruoti didelių kalbų modelių ir generatyvaus AI – „ChatGPT“ technologijos – pasaulyje.

 

 Šis straipsnis yra pagrįstas žmonių, kurie dirbo su „Amazon“ dirbtinio intelekto pastangomis, pasakojimais.

 

 „Amazon“ daugelį metų dirbo su mašininiu mokymusi ir kitomis AI formomis. Vis dėlto bendrovė vėliau, nei konkurentai, sukūrė didelius modelius, reikalingus generuojančiam dirbtiniam intelektui, kuris naudoja programinę įrangą, parengtą pagal didžiulius duomenų kiekius, kad sukurtų sprendimus. Ši technologija gali palaikyti pokalbius ir reaguoti į sudėtingas instrukcijas.

 

 Praėjus kelioms valandoms po „ChatGPT“ išleidimo 2022 m. pabaigoje, Prasadas su „Alexa“ komanda pradėjo su juo eksperimentuoti. Jie buvo sužavėti tuo, kaip lengva juo naudotis ir žiniomis, kurias ji gali pateikti įvairiomis temomis. Darbuotojai paprašė „ChatGPT“ sugeneruoti kodą „Alexa“ funkcijoms, tokioms, kaip išmaniųjų namų valdymas, o jo rezultatai kartais buvo geresni, nei „Amazon“ vidinių sistemų rezultatai.

 

 Prasadas sušaukė susitikimą su darbuotojais, kad aptartų, kokį poveikį ChatGPT gali turėti technologijų pramonei. Per kelias savaites jie sugalvojo planą pasivyti. „Amazon“ paspartino didelio modelio „Titan“ kūrimą ir pradėjo kurti naujesnį modelį „Olympus“. Ji planavo naudoti savo modelius, kad perdarytų Alexa ir diegtų juos kitose įmonėse.

 

 Bendrovė perkėlė tūkstančius darbuotojų į naująją Prasado komandą ir pavadino ją AGI grupe kaip linkėjimą ilgainiui sukurti dirbtinį bendrąjį intelektą – kitą AI lygį, galintį pranokti žmones.

 

 „Amazon“ prieš metus pademonstravo išmanesnę „Alexa“. Atnaujinimas, žinomas kaip „Remarkable Alexa“, užtruko ilgiau, nei tikėtasi, kad jis buvo paruoštas viešai. Vėlavimas, kuriant naujus produktus, nėra neįprastas pažangiausioms technologijoms.

 

 Viešai neatskleista, informacija teigia, kad Prasado grupė kovojo su paspartintais terminais, siekdama priversti savo įmonės sukurtą AI tinkamai veikti. Tikslai dažnai keitėsi, terminai buvo skubinami, o grupė kartais pasirodydavo pernelyg sudėtinga, kad galėtų greitai kurti inovacijas.

 

Prieš „ChatGPT“ bumą „Amazon“ papildė užduotis, kurias galėjo atlikti „Alexa“, versdama asistentą sklandžiai dirbti su įvairiais produktais ir stengtis sukurti pelningą verslą. „Amazon“ įdėjo „Alexa“ į automobilius, mikrobangų krosneles ir net akinius.

 

 Prasado kompetencija Alexa buvo natūralus kalbos supratimas ir tikslumas, atsakant į dažniausiai užduodamus klausimus, pvz., „Koks šiandien oras?“ su keletu defektu. Prieš „ChatGPT“ nebuvo daug darbo su dideliais kalbų modeliais ir „Alexa“.

 

 „Amazon“ sunkiai naudojo savo naujausius vidinius AI modelius, kad pakeistų asistentą. Kai „Amazon“ į „Alexa“ įtraukė didelius kalbų modelius, balso asistentas tapo mažiau patikimas, atliekant paprastas užduotis. Pavyzdžiui, kai kurių bandymų metu jis prarado galimybę įjungti šviesas su 90% patikimumu.

 

 „Amazon“ atstovas atsisakė komentuoti naujausių AI projektų vėlavimą ir trikdžių šalinimą.

 

 Prasadas interviu praėjusiais metais sakė, kad generatyvaus AI kūrybinės ir pokalbio galimybės gali neleisti jam patikimai atlikti pagrindinių užduočių.

 

 „Jei įeitumėte ir pasakytumėte: „Alexa, man čia karšta“ arba „Man atrodo, kad per šilta“, ji turėtų sugrįžti ir paklausti: „Ar norite nuleisti termostatą ar sumažinti temperatūrą? ' Ji neturėtų liepti eiti į paplūdimį“, – „YouTube“ paskelbtame, interviu analitikui sakė jis.

 

 „Štai kodėl AI yra tokia sunki problema, nes kontekstas yra toks svarbus."

 

 Kaip ir daugelis technologijų įmonių, „Amazon“ nori kurti savo technologijas, kad galėtų visiškai kontroliuoti savo produktus ir paslaugas. Vykstant AI lenktynėms, bendrovė vis labiau rėmėsi partneryste. Ji investavo 4 milijardus dolerių į AI startuolį Anthropic ir neseniai pasamdė darbuotojus iš Adept AI. Ji taip pat bendradarbiauja su „Meta Platforms“ ir kt.

 

 Nors „Amazon“ planavo priklausyti nuo savo „Remarkable Alexa“ modelių, vėliau ji nusprendė integruoti AI technologiją iš Anthropic ir kitų.

 

 Per ateinantį dešimtmetį „Amazon“ planuoja išleisti daugiau nei 100 mlrd. dolerių duomenų centrams, kad padėtų patenkinti AI paklausą, vidinis spaudimas gaminti savo AI produktus auga. Generalinis direktorius Jassy buvo labiau susijęs su AGI grupe, nei įprasta. Jis susitikdavo su jos vadovybe maždaug kas keturias–šešias savaites.

 

 „Amazon“ planuoja renginį, kuriame bus parodyti nauji įrenginio naujinimai, kurie gali pabrėžti kai kuriuos „Alexa“ atnaujinimus. Planuojama įtraukti daugiau pokalbių „Alexa“, kuri gali padėti parengti žinutes ir patarti apsipirkimo klausimais. Bendrovė svarstė galimybę apmokestinti vartotojus už išmanesnę „Alexa“.

 

 „Amazon“ konkurentai taip pat paleido pokalbių robotus ir atnaujino turimas galimybes.

 

 „Apple“ neseniai pristatė savo „Apple Intelligence“ sistemą su patobulinta „Siri“ asistento versija. Sistema bus prieinama naujuose bendrovės „iPhone 16“ modeliuose. Neseniai „Google“ savo telefonams pristatė naują generatyvinio AI asistentą.“ [1]

 

1. An Alexa Creator Leads Amazon's AI Offensive. Herrera, Sebastian.  Wall Street Journal, Eastern edition; New York, N.Y.. 24 Sep 2024: B.1.