A nyelvi modellek gyorsan javultak az elmúlt években, és a nagy nyelvi modellek (LLM), például a GPT-3 és a GPT-4 kerültek a középpontba. Ezek a modellek azért váltak népszerűvé, mert rendkívül sokféle feladatot képesek elvégezni hihetetlen hozzáértéssel. Továbbá, mivel ezen modellek paramétereinek száma (milliárdokban!) nőtt, ezek a modellek beláthatatlanul új képességekre tettek szert.

Ebben a cikkben megvizsgáljuk az LLM-eket, az általuk elvégezhető feladatokat, hiányosságaikat és a különféle azonnali tervezési stratégiákat.

Mik azok az LLM-ek?

Az LLM-ek neurális hálózatok, amelyeket hatalmas mennyiségű szöveges adatra képeztek ki. A betanítási folyamat lehetővé teszi a modellek számára, hogy megtanuljanak mintákat a szövegben, beleértve a nyelvtant, a szintaxist és a szótársításokat. A modellek ezeket a tanult mintákat használják emberszerű szöveg létrehozására, így ideálisak természetes nyelvi feldolgozási (NLP) feladatokhoz.

Mely LLM-ek állnak rendelkezésre?

Számos LLM áll rendelkezésre, ezek közül a GPT-4 a legnépszerűbb. További modellek közé tartozik a LLaMA, a PaLM, a BERT és a T5. Mindegyik modellnek megvannak a maga erősségei és gyengeségei, ezek egy része nyitott, mások zártak, és csak API-n keresztül használhatók.

Az LLM-ek hiányosságai

Lenyűgöző teljesítményük ellenére az LLM-eknek számos korlátja van. Az egyik jelentős hátrány, hogy képtelenek a felszólításban megadott információkon túlmenően érvelni. Ezenkívül az LLM-ek elfogult szöveget generálhatnak a képzésben részesült adatok alapján. Az LLM-ek kimenetének szabályozása is kihívást jelent, ezért azonnali tervezési stratégiákat kell alkalmazni a kívánt kimenet eléréséhez.

Milyen feladatokat tud elvégezni?

Az LLM-eket konkrét feladatok elvégzésére irányíthatjuk, ha minden esetre formázzuk a promptokat. Itt található ezeknek a feladatoknak a listája, valamint mindegyikhez sablonok és példák.

Szöveg Összegzés

Az LLM-ek hosszú szövegekből összefoglalókat készíthetnek, megkönnyítve a tartalom megértését és megemésztését. Kérhetjük egy szöveg összefoglalását a következő prompt sablonnal:

Template

<Full text>
Summarize the text above: / Explain the text above in <N> sentences:

Például kérhetjük, hogy foglaljuk össze ezt a szöveget a következő felszólítással:

Prompt

In a mechanical watch the watch's gears are turned by a spiral spring called a mainspring. In a manual watch energy is stored in the mainspring by turning a knob, the crown on the side of the watch. Then the energy from the mainspring powers the watch movement until it runs down, requiring the spring to be wound again.
A self-winding watch movement has a mechanism which winds the mainspring using the natural motions of the wearer's body. The watch contains an oscillating weight that turns on a pivot. The normal movements of the watch in the user's pocket (for a pocketwatch) or on the user's arm (for a wristwatch) cause the rotor to pivot on its staff, which is attached to a ratcheted winding mechanism. The motion of the watch is thereby translated into circular motion of the weight which, through a series of reverser and reducing gears, eventually winds the mainspring. There are many different designs for modern self-winding mechanisms. Some designs allow winding of the watch to take place while the weight swings in only one direction while other, more advanced, mechanisms have two ratchets and wind the mainspring during both clockwise and anti-clockwise weight motions.
Explain the text above in 2 sentences:

Ami a következő kimenetet adja:

Output

A mechanical watch uses a mainspring to power the movement of the watch's gears. In a manual watch, the mainspring is wound by turning a knob, while a self-winding watch uses the natural motion of the wearer's body to wind the mainspring through an oscillating weight and ratcheted winding mechanism.

Információ kinyerése

Az LLM-ek nagy mennyiségű szövegből azonosíthatnak és kinyerhetnek konkrét információkat. Ez olyan területeken hasznos, mint az újságírás és az üzleti intelligencia. A következő sablon információk kinyerésére utasítja a modellt:

Template

<Full text>
Mention X in the text above: / List X in the text above:

Például megkérhetjük a helyek nevének kinyerését a következő szövegből:

Prompt

The earliest credible evidence for a successful design is the watch made by the Swiss watchmaker Abraham-Louis Perrelet, who lived in Le Locle. In late 1776 or early 1777, he invented a self-winding mechanism for pocket watches using an oscillating weight inside the watch that moved up and down. The Geneva Society of Arts, reporting on this watch in 1777, stated that 15 minutes walking was necessary to fully wind the watch.
List the names of places in the text above:

A kimenet pedig:

Output

Le Locle, Geneva.

Kérdés válaszadás

Az LLM-ek kérdésekre is válaszolhatnak a promptban megadott információk alapján. A következő sablon használható az LLM-nek egy kérdés megválaszolására:

Template

Answer the question based on the context below. <Other instructions>. Respond "Not sure" if not sure about the answer.
Context: <Context>
Q: <Question>
A:

Például a következő prompttal:

Prompt

Answer the question based on the context below. Answer in a single sentence. Respond "Not sure" if not sure about the answer.
Context: An automatic watch, also known as a self-winding watch or simply an automatic, is a mechanical watch where the natural motion of the wearer provides energy to wind the mainspring, making manual winding unnecessary if worn enough. It is distinguished from a manual watch in that a manual watch must have its mainspring wound by hand at regular intervals.
Q: Do automatic watches need to be manually wound?
A:

A ChatGPT pedig a következőkkel válaszol:

Output

No, automatic watches do not need to be manually wound if worn enough because the natural motion of the wearer provides energy to wind the mainspring.

Szöveg osztályozás

Az LLM-ek előre meghatározott kategóriákba sorolhatják a szöveget, mint például a hangulatelemzés vagy a spamészlelés. A szöveges osztályozási utasítást a következőképpen formázhatja:

Template

Classify the text into <List of choices>:
Text: <Full text>
Classification:

Például megpróbálhatunk besorolni egy szöveget, hogy pozitív, semleges vagy negatív hangulatú-e:

Prompt

Classify the text into positive, neutral or negative:
Text: That shot selection was awful
Classification:

Output

Negative

Beszélgetés

Az LLM-ek emberszerű beszélgetéseket generálhatnak, így hasznosak lehetnek chatbotokban és ügyfélszolgálati alkalmazásokban. Utasíthatjuk az LLM-et, hogy meghatározott módon kövesse a beszélgetést.

Template

The following is a conversation with <Actor>. The <Actor> should answer <Further instructions>.
Person: <Conversation>
<Actor>: <Response>
Person: <Conversation>
<Actor>:

Az LLM annak a színésztípusnak a válaszát tölti ki, akire utasítottuk, és folytathatjuk a beszélgetést úgy, hogy a teljes beszélgetést az új válaszokkal ismét átadjuk neki. Például:

Prompt

The following is a conversation with a lawyer. The lawyer should answer simply and in layman terms.
Person: Hello, I would like to know how to dispute a parking ticket
Lawyer:

Output

Sure, I can help. The first step is to check the ticket for any errors or mistakes. If you find any, you can use those as grounds to dispute the ticket. If there are no mistakes, you can still dispute the ticket by providing evidence to support your case, such as photos or witness statements. You can also request a hearing to present your case in person.

Prompt

The following is a conversation with a lawyer. The lawyer should answer simply and in layman terms.
Person: Hello, I would like to know how to dispute a parking ticket
Lawyer: Sure, I can help. The first step is to check the ticket for any errors or mistakes. If you find any, you can use those as grounds to dispute the ticket. If there are no mistakes, you can still dispute the ticket by providing evidence to support your case, such as photos or witness statements. You can also request a hearing to present your case in person.
Person: How do I request a hearing?
Lawyer:

Output

To request a hearing, you'll need to follow the instructions on the back of the ticket or on the website provided. Usually, you'll need to submit a written request within a certain timeframe, along with any evidence or supporting documents you have. Once your request is received, you'll be notified of the date, time, and location of your hearing.

Kódgenerálás

Az LLM-ek kódot generálhatnak, ami megkönnyíti a fejlesztők számára az összetett szoftverprogramok létrehozását. Írhatunk egy kód megjegyzést, amely leírja, hogy mit kívánunk a kódtól, és az LLM a legjobb tudása szerint meg tudja tenni helyettünk. Minél összetettebb dolgokat kívánunk a kódtól, annál specifikusabbnak és leíróbbnak kell lennünk a gyors megjegyzésben.

A sablon a létrehozni kívánt programozási nyelvtől függően változhat, de azt tanácsolom, hogy nagyjából kövesse ezt a sablont:

Template

<Comment symbol of your language of choice (/* or ''' or #)>
Method: <Name of the method>
Language: <Programming language>
Description: <Description of what the method must do>
Parameters: <Parameters that the method will receive>
Context: <Further information needed to implement the method (URLs, databases, etc.)>
Output: <Output of the method>
<Comment symbol of your language of choice (/* or ''' or #)>

Például, ha egy oldalszámozással rendelkező API-t szeretnénk lekérni, a következő megjegyzést írhatjuk:

Prompt

/* Method: fetchFirst5Pages
 * Language: Javascript
 * Description: Fetch the first 5 pages from this paginated API: http://example.com/pages/?n=x
 * Context: This API accepts the following URL parameters:
 *   n: the number of the page to fetch
 * Output: the content of the first 5 pages
 */

Output

Here's an example implementation of the fetchFirst5Pages method in JavaScript, assuming the use of the fetch function:

async function fetchFirst5Pages() {
  const baseUrl = 'http://example.com/pages/?n=';
  const pages = [];
  for (let i = 1; i <= 5; i++) {
    const url = baseUrl + i;
    const response = await fetch(url);
    if (!response.ok) {
      throw new Error(`Error fetching page ${i}`);
    }
    const pageData = await response.json();
    pages.push(pageData);
  }
  return pages;
}

This function uses a loop to fetch the first 5 pages from the API by appending the page number to the base URL. It checks if the response from the server is okay and throws an error if it's not. Then, it parses the JSON data from the response and adds it to an array of pages. Finally, it returns the array of pages.

Érvelés

Az LLM-ek megküzdhetnek néhány alapvető feladattal, például számtani problémákkal. Ha azonban megkérjük az LLM-et, hogy indokolja válaszát, segíthetünk neki a helyes válasz megtalálásában. Ezt a sablont ajánlom:

Template

Q: <Question>
A: Let's work this out in a step by step way to be sure we have the right answer. First, <Instructions>.

Ebben a példában láthatjuk, hogy egy egyszerű aritmetikai kérdés meghiúsul, ha érvelés nélkül tesszük fel:

Prompt

Answer the following question. Respond "Not sure" if not sure about the answer.
Q: The sum of prime numbers in the following list are a multiple of 3: [2, 4, 6, 7, 9, 14]
A: [Yes or No]

Output

No. The sum of prime numbers in the list [2, 4, 6, 7, 9, 14] is not a multiple of 3. Therefore, the answer is "No".

Ha azonban arra utasítjuk az LLM-et, hogy indokolja meg a választ, egészen más eredményt kapunk:

Prompt

Q: The sum of prime numbers in the following list are a multiple of 3: [2, 4, 6, 7, 9, 14]
A: Let's work this out in a step by step way to be sure we have the right answer. First, we find the prime numbers in the list and add them together. Then we check whether the resulting number can be divided by 3.

Output

Sure, let's work this out step by step.
The prime numbers in the list are 2 and 7. So we can add them together:
2 + 7 = 9
The resulting number is 9. Now we need to check whether it is a multiple of 3. We can do this by checking if the remainder of 9 divided by 3 is equal to 0:
9 % 3 = 0
Since the remainder is 0, we know that 9 is indeed a multiple of 3.
Therefore, the answer is "Yes", the sum of prime numbers in the list [2, 4, 6, 7, 9, 14] is a multiple of 3.

Stratégiák

Bár ezek a sablonok segítenek az LLM-ekben rejlő lehetőségek kiaknázásában az Ön igényei szerint, néha még mindig megküzdhetnek bizonyos összetett feladatokkal. Néhány technikát fejlesztettek ki annak érdekében, hogy segítsenek az LLM-eknek kielégítő választ adni. Eddig csak a nullapontos felszólítást használtuk, amit most definiálunk. Használhatunk azonban bonyolultabb technikákat is.

Zero-shot felszólítás

A cikkben szereplő összes példa esetében nulla-shot felszólítást használtunk. A nullapontos felszólítás azt jelenti, hogy egy felszólítást adunk át az LLM-nek, csak azzal a kérdéssel, amelyet meg akarunk válaszolni, anélkül, hogy példákat mutatna be arra vonatkozóan, hogyan kell reagálnia más esetekben. Például egy korábbi példában ezt tettük:

Prompt

Classify the text into positive, neutral or negative:
Text: That shot selection was awful
Classification:

Output

Negative

Lehetséges, hogy ez nem elég kontextus ahhoz, hogy a modell pontosan úgy válaszoljon, ahogyan szeretnénk. Lássuk, milyen alternatíváink vannak.

Kevés lövésű felszólítás

A zero-shot felszólítástól eltérően a néhány lépéses felszólítással néhány példát mutatunk az LLM-nek arra vonatkozóan, hogyan kell válaszolnia, mielőtt feltennénk a kérdést. Tegyük fel például, hogy az előző példához hasonlóan szeretnénk osztályozni egy szöveg hangulatát. De azt akarjuk, hogy minden alkalommal egy nagyon konkrét formátumban adja meg a választ. Előzetesen hozhatnánk rá néhány példát, például:

Prompt

Classify the text into positive, neutral or negative:
Text: Today the weather is fantastic
Classification: Pos
Text: The furniture is small.
Classification: Neu
Text: I don't like your attitude
Classification: Neg
Text: That shot selection was awful
Classification:

Output

Neg

Gondolatlánc késztetés

Még összetettebb feladatoknál kombinálhatjuk a néhány lépéses felszólítást a modell válaszának indoklásával. Ugyanazt a példát használhatjuk, mint korábban, hogy megnézzük, hogyan befolyásolja az érvelés és a néhány lépéses felszólítás az eredményt:

Prompt

Q: The sum of prime numbers in the following list are a multiple of 3: [2, 4, 6, 7, 9, 14]
A: The prime numbers in the list are 2 and 7. Their sum is 9. 9 % 3 = 0. The answer is yes.
Q: The sum of prime numbers in the following list are a multiple of 3: [1, 2, 4, 7, 8, 10]
A: The prime numbers in the list are 1, 2 and 7. Their sum is 10. 10 % 3 = 1. The answer is no.
Q: The sum of prime numbers in the following list are a multiple of 3: [1, 2, 3, 4]
A: The prime numbers in the list are 1, 2 and 3. Their sum is 6. 6 % 3 = 0. The answer is yes.
Q: The sum of prime numbers in the following list are a multiple of 3: [5, 6, 7, 8]
A:

Output

The prime numbers in the list are 5 and 7. Their sum is 12. 12 % 3 = 0. The answer is yes.

Végső megjegyzés

Az LLM-ek forradalmasították a természetes nyelvi feldolgozás területét, de lehetőségük maximalizálásához elengedhetetlen a gyors tervezés. Az LLM-ek által végrehajtható feladatok, azok hiányosságainak és különféle azonnali tervezési stratégiáinak megértésével a fejlesztők kihasználhatják az LLM-ek erejét innovatív és hatékony megoldások létrehozására. A közeljövőben valószínűleg több stratégiát és technikát fognak kidolgozni, ezért figyeljen a további fejlesztésekre ezen a területen, hogy még jobban maximalizálja az LLM-ben rejlő lehetőségeket. Sőt, ahogy az LLM-ek folyamatosan nőnek, több milliárd további paraméterrel, valószínű, hogy több olyan feladat is megoldható lesz, amelyre most nem is gondolunk. Lenyűgöző belegondolni, hogy mi lesz lehetséges ezen új eszközök használatával, és milyen használati eseteket fognak szolgálni a jövőben