Skip to content

Commit ff930cc

Browse files
committed
add visualization of embedding_distance.py
1 parent 7d7cf2e commit ff930cc

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

examples/embedding_distance.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import numpy as np
22
import ollama
3+
import matplotlib.pyplot as plt
34

45
def cosine_distance(vector1, vector2):
56
return np.dot(vector1, vector2) / (np.linalg.norm(vector1) * np.linalg.norm(vector2))
@@ -48,4 +49,33 @@ def softmax(x, temperature=0.2):
4849
similarity_array.append(similarity_score)
4950

5051

51-
print(softmax(similarity_array))
52+
openness_array = []
53+
conscientiousness_array = []
54+
extraversion_array = []
55+
agreeableness_array = []
56+
neuroticism_array = []
57+
58+
temperatures = np.arange(0.05, 1.05, 0.05)
59+
60+
for temp in temperatures:
61+
openness_array.append(softmax(similarity_array, temp)[0])
62+
conscientiousness_array.append(softmax(similarity_array, temp)[1])
63+
extraversion_array.append(softmax(similarity_array, temp)[2])
64+
agreeableness_array.append(softmax(similarity_array, temp)[3])
65+
neuroticism_array.append(softmax(similarity_array, temp)[4])
66+
67+
plt.figure(figsize=(12, 9))
68+
plt.plot(temperatures, openness_array, label='Openness', marker='o')
69+
plt.plot(temperatures, conscientiousness_array, label='Conscientiousness', marker='s')
70+
plt.plot(temperatures, extraversion_array, label='Extraversion', marker='^')
71+
plt.plot(temperatures, agreeableness_array, label='Agreeableness', marker='d')
72+
plt.plot(temperatures, neuroticism_array, label='Neuroticism', marker='v')
73+
74+
plt.xticks(np.arange(0, 1.05, 0.05))
75+
plt.yticks(np.arange(0, 0.75, 0.05))
76+
plt.xlabel('Temperature')
77+
plt.ylabel('Softmax Probability')
78+
plt.title('Personality Traits Probabilities vs Temperature')
79+
plt.legend()
80+
plt.grid(True)
81+
plt.show()

0 commit comments

Comments
 (0)