Spiegare i modelli generativi basati su chat

Explainable AI in Python

Fouad Trad

Machine Learning Engineer

Modelli generativi basati su chat

  • Usati per generare testo
  • Predicono in base a contesto e conoscenza

 

Immagine che mostra un utente che invia un prompt a un modello generativo e riceve una risposta.

Explainable AI in Python

Prompt chain-of-thought

  • Incoraggia il modello a esplicitare il ragionamento

Immagine che mostra come un prompt chain-of-thought chieda al modello di risolvere un problema passo dopo passo e l'output contenga il ragionamento per ogni passo.

Explainable AI in Python

Creare un prompt chain-of-thought

prompt = """A shop starts with 20 apples. It sells 5 apples and then receives 8 more. 
How many apples does the shop have now? Show your reasoning step-by-step."""

response = get_response(prompt)
print(response)
To find out how many apples the shop has now, let's follow the transactions step-by-step:

1- The shop begins with 20 apples.
2- The shop sells 5 apples. We subtract this number from the starting quantity: 20 - 5 = 15
3- The shop receives 8 apples. We add this number to the remaining apples: 15 + 8 = 23
So, after these transactions, the shop has 23 apples.
Explainable AI in Python

Self-consistency

Valuta la confidenza del modello nelle risposte generate

Immagine che mostra che un prompt di self-consistency consiste nell'inviare più volte lo stesso prompt al modello, ognuno con una risposta.

Explainable AI in Python

Self-consistency nella classificazione del testo

Utile per attività di classificazione del testo

Immagine che mostra un esempio di self-consistency in cui il modello deve classificare una recensione utente come positiva o negativa e fornisce più risposte.

Explainable AI in Python

Self-consistency nella classificazione del testo

Utile per attività di classificazione del testo

Immagine che mostra un esempio di self-consistency in cui il modello deve classificare una recensione come positiva o negativa e fornisce più risposte. La confidenza è calcolata come proporzione di ogni categoria sul totale delle risposte.

Explainable AI in Python

Creare prompt di self-consistency

prompt = """Classify the following review as positive or negative. 
You should reply with either "positive" or "negative", nothing else.
Review: 'The customer service was great, but the product itself did not meet my expectations.'"""

responses = []
for i in range(5): sentiment = get_response(review)
responses.append(sentiment.lower())
confidence = { 'positive': responses.count('positive') / len(responses), 'negative': responses.count('negative') / len(responses) }
Explainable AI in Python

Creare prompt di self-consistency

print(confidence)
{
    'positive': 0.6,
    'negative': 0.4
}
Explainable AI in Python

Passiamo alla pratica!

Explainable AI in Python

Preparing Video For Download...