Autocoerenza per stimare la confidenza
Il prompt qui sotto chiede a ChatGPT di classificare il sentiment di una recensione. Devi stimare la confidenza di ChatGPT in ciascuna classe usando l'autocoerenza (self-consistency).
La funzione get_response() per comunicare con ChatGPT è già caricata per te.
Questo esercizio fa parte del corso
Explainable AI in Python
Istruzioni dell'esercizio
- Per ogni recensione, aggiungi il
sentimentalla listaresponses. - Calcola la confidenza per ciascun sentiment.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
prompt = """Classify the following review as positive or negative.
You should reply with either "positive" or "negative", nothing else.
Review: 'The coffee was excellent, but the service left much to be desired.'"""
responses = []
for i in range(5):
sentiment = get_response(prompt)
# Append the response to the responses list
____
# Compute the confidence for each sentiment
confidence = {
'positive': ____,
'negative': ____
}
print(confidence)