Skip to content

Commit d7d5f19

Browse files
committed
create method to evaluate big five's weight in text
1 parent 55f2f50 commit d7d5f19

File tree

3 files changed

+1589
-2
lines changed

3 files changed

+1589
-2
lines changed

examples/embedding_distance.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import numpy as np
2+
import ollama
3+
4+
def cosine_distance(vector1, vector2):
5+
return np.dot(vector1, vector2) / (np.linalg.norm(vector1) * np.linalg.norm(vector2))
6+
7+
def softmax(x, temperature=0.2):
8+
if temperature <= 0:
9+
raise ValueError("Temperature must be positive.")
10+
11+
x = np.array(x)
12+
exp_x = np.exp(x/temperature)
13+
return exp_x / np.sum(exp_x)
14+
15+
input = '''Ellie moved gracefully through the community garden, noticing a young woman struggling with several heavy bags of soil. Without hesitation, she offered her assistance, smiling warmly as she introduced herself and insisted on carrying the heavier load despite the woman's gentle protests. As they worked together, Ellie listened attentively to the stranger's innovative ideas for vertical gardening using recycled materials, her eyes lighting up with genuine fascination. Later, when another gardener expressed frustration about the placement of certain plants, Ellie patiently mediated the disagreement, finding a compromise that satisfied everyone while incorporating elements from various global gardening traditions she'd studied during her travels. At the garden's planning meeting that evening, she enthusiastically supported each person's vision, building upon their ideas with thoughtful suggestions drawn from her eclectic knowledge of permaculture, indigenous farming practices, and contemporary sustainable agriculture—all while making sure the quieter members had opportunities to share their perspectives and ensuring that everyone felt their contributions were valued.'''
16+
17+
similarity_array = []
18+
19+
personality_traits = {
20+
"openness": ["curious", "creative", "imaginative", "artistic", "insightful", "original", "unconventional", "innovative", "reflective", "adventurous"],
21+
22+
"conscientiousness": ["organized", "responsible", "disciplined", "efficient", "thorough", "reliable", "precise", "methodical", "deliberate", "persevering"],
23+
24+
"extraversion": ["sociable", "energetic", "talkative", "assertive", "enthusiastic", "outgoing", "gregarious", "expressive", "lively", "confident"],
25+
26+
"agreeableness": ["kind", "cooperative", "compassionate", "considerate", "empathetic", "generous", "trusting", "forgiving", "patient", "modest"],
27+
28+
"neuroticism": ["anxious", "moody", "irritable", "vulnerable", "self-conscious", "sensitive", "tense", "restless", "insecure", "worrying"]
29+
}
30+
31+
response_input = ollama.embed(
32+
model="nomic-embed-text",
33+
input=input
34+
)
35+
36+
# print("Embedding:", response_input)
37+
38+
input_embedding = np.array(response_input['embeddings'][0])
39+
40+
41+
for key in personality_traits:
42+
response_personality = ollama.embed(
43+
model="nomic-embed-text",
44+
input=personality_traits[key]
45+
)
46+
personality_embedding = np.array(response_personality['embeddings'][0])
47+
similarity_score = cosine_distance(input_embedding, personality_embedding)
48+
similarity_array.append(similarity_score)
49+
50+
51+
print(softmax(similarity_array))

examples/knowledge_graph.html

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)