Question: import seaborn as sns import matplotlib.pyplot as plt # Data for the heatmap data = { 'Toxicity': [ 1 , 3 , 4 ] ,

import seaborn as sns
import matplotlib.pyplot as plt
# Data for the heatmap
data ={
'Toxicity': [1,3,4],
'Bias': [1,3,4],
'Misinformation': [2,4,4],
'Offensive Content': [2,3,4],
'Privacy Violation': [1,2,3]
}
index =['General Prompts', 'Adversarial Prompts', 'Targeted Prompts']
df = pd.DataFrame(data, index=index)
# Create a custom colormap to better reflect the probability levels
colors =[(255/255,255/255,204/255), # Light Yellow (Low)
(255/255,237/255,160/255), # Light Orange (Medium)
(254/255,178/255,76/255), # Orange (High)
(227/255,26/255,28/255)] # Red (Very High)
cmap = sns.color_palette(colors)
# Create the heatmap with seaborn
plt.figure(figsize=(12,8)) # Adjust figure size
sns.heatmap(df, annot=True, cmap=cmap, fmt=".0f", cbar_kws={'label': 'Risk Level'}, annot_kws={"fontsize": 12}) # Increased font size
# Add labels and title
plt.title('Enhanced Framework for Prompt-Based Risk Identification', fontsize=14)
plt.xlabel('Prompt Type', fontsize=12)
plt.ylabel('Risk Category', fontsize=12)
plt.xticks(fontsize=10)
plt.yticks(fontsize=10)
# Add bibliography references to each cell
for i in range(len(df)):
for j in range(len(df.columns)):
if df.values[i, j]==1:
plt.text(j +0.5, i +0.8,"A", ha="center", va="center")
elif df.values[i, j]==2:
plt.text(j +0.5, i +0.8,"A, G", ha="center", va="center")
elif df.values[i, j]==3:
if df.columns[j]== "Toxicity":
plt.text(j +0.5, i +0.8,"P", ha="center", va="center")
elif df.columns[j]== "Privacy Violation":
plt.text(j +0.5, i +0.8,"L", ha="center", va="center")
else:
plt.text(j +0.5, i +0.8,"P, Z", ha="center", va="center")
elif df.values[i, j]==4:
if df.columns[j] in ["Bias", "Privacy Violation"]:
plt.text(j +0.5, i +0.8,"L", ha="center", va="center")
elif df.columns[j]== "Toxicity":
plt.text(j +0.5, i +0.8,"G", ha="center", va="center")
else:
plt.text(j +0.5, i +0.8,"A, P", ha="center", va="center")
# Show the plot
plt.show() create this heatmap

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!