Explainable AI in Python
Fouad Trad
Machine Learning Engineer


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 = 153- The shop receives 8 apples. We add this number to the remaining apples: 15 + 8 = 23So, after these transactions, the shop has 23 apples.
Assesses model's confidence in generated answers

Useful for text classification tasks

Useful for text classification tasks

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) }
print(confidence)
{
'positive': 0.6,
'negative': 0.4
}
Explainable AI in Python