ping98k commited on
Commit
fe3f9fe
·
1 Parent(s): 00182d4

Initialize textarea with random sentences and update K-Means clustering message format for improved clarity

Browse files
Files changed (3) hide show
  1. index.html +5 -11
  2. main.js +7 -6
  3. sentences.js +115 -0
index.html CHANGED
@@ -51,17 +51,11 @@
51
 
52
  <body>
53
  <h1>Embedding Similarity Heatmap</h1>
54
- <textarea id="input">Apple
55
- Banana
56
- Orange
57
-
58
- Dog
59
- Cat
60
- Hamster
61
-
62
- Car
63
- Bus
64
- Bicycle</textarea>
65
  <label for="kmeans-k" style="margin-left:10px;">Clusters:</label>
66
  <input id="kmeans-k" type="number" min="2" max="20" value="3" style="width:60px;">
67
  <button id="kmeans-btn">K-Means Clustering</button>
 
51
 
52
  <body>
53
  <h1>Embedding Similarity Heatmap</h1>
54
+ <textarea id="input"></textarea>
55
+ <script type="module">
56
+ import { sentences } from './sentences.js';
57
+ document.getElementById("input").value = sentences.join("\n");
58
+ </script>
 
 
 
 
 
 
59
  <label for="kmeans-k" style="margin-left:10px;">Clusters:</label>
60
  <input id="kmeans-k" type="number" min="2" max="20" value="3" style="width:60px;">
61
  <button id="kmeans-btn">K-Means Clustering</button>
main.js CHANGED
@@ -121,14 +121,14 @@ document.getElementById("kmeans-btn").onclick = async () => {
121
  progressBarInner.style.width = `${Math.round(((c) / k) * 100)}%`;
122
  const joined = clustered[c].join("\n");
123
  const messages = [
124
- { role: "system", content: "You are a helpful assistant." },
125
- { role: "user", content: `Given the following texts, provide a short, descriptive name for this group:\n\n${joined}` }
126
  ];
127
- const reasonEnabled = false;
128
  const inputs = tokenizer.apply_chat_template(messages, {
129
  add_generation_prompt: true,
130
  return_dict: true,
131
- enable_thinking: reasonEnabled,
132
  });
133
  const [START_THINKING_TOKEN_ID, END_THINKING_TOKEN_ID] = tokenizer.encode("<think></think>", { add_special_tokens: false });
134
  let state = "answering";
@@ -162,8 +162,9 @@ document.getElementById("kmeans-btn").onclick = async () => {
162
  });
163
  const outputTokens = await model.generate({
164
  ...inputs,
165
- max_new_tokens: 32,
166
- do_sample: false,
 
167
  streamer,
168
  });
169
  let rawName = tokenizer.decode(outputTokens[0], { skip_special_tokens: false }).trim();
 
121
  progressBarInner.style.width = `${Math.round(((c) / k) * 100)}%`;
122
  const joined = clustered[c].join("\n");
123
  const messages = [
124
+ { role: "system", content: "Given the following texts, provide a short 1-3 word summary in plaintext" },
125
+ { role: "user", content: `${joined}` }
126
  ];
127
+
128
  const inputs = tokenizer.apply_chat_template(messages, {
129
  add_generation_prompt: true,
130
  return_dict: true,
131
+ enable_thinking: false,
132
  });
133
  const [START_THINKING_TOKEN_ID, END_THINKING_TOKEN_ID] = tokenizer.encode("<think></think>", { add_special_tokens: false });
134
  let state = "answering";
 
162
  });
163
  const outputTokens = await model.generate({
164
  ...inputs,
165
+ max_new_tokens: 1024,
166
+ do_sample: true,
167
+ temperature: 0.6,
168
  streamer,
169
  });
170
  let rawName = tokenizer.decode(outputTokens[0], { skip_special_tokens: false }).trim();
sentences.js ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export const sentences = [
2
+ // Weather
3
+ "The sun peeked through the clouds after a drizzly morning.",
4
+ "A gentle breeze rustled the leaves as we walked along the shoreline.",
5
+ "Heavy rains caused flooding in several low-lying neighborhoods.",
6
+ "It was so hot that even the birds sought shade under the palm trees.",
7
+ "By midnight, the temperature had dropped below freezing.",
8
+ "Thunderstorms lit up the sky with flashes of lightning.",
9
+ "A thick fog settled over the city streets at dawn.",
10
+ "The air smelled of ozone after the sudden hailstorm.",
11
+ "I watched the snowflakes drift silently onto the ground.",
12
+ "A double rainbow appeared after the rain shower.",
13
+ "The humidity soared to uncomfortable levels by midday.",
14
+ "Dust devils formed in the dry desert plains.",
15
+ "The barometer readings indicated an approaching front.",
16
+ "A sudden gust of wind knocked over the garden chairs.",
17
+ "Light drizzle turned into a torrential downpour within minutes.",
18
+ // Technology
19
+ "The new smartphone features a foldable display and 5G connectivity.",
20
+ "In the world of AI, transformers have revolutionized natural language processing.",
21
+ "Quantum computing promises to solve problems beyond classical computers' reach.",
22
+ "Blockchain technology is being explored for secure voting systems.",
23
+ "Virtual reality headsets are becoming more affordable and accessible.",
24
+ "The rise of electric vehicles is reshaping the automotive industry.",
25
+ "Cloud computing allows businesses to scale resources dynamically.",
26
+ "Machine learning algorithms can now predict stock market trends with surprising accuracy.",
27
+ "Augmented reality applications are transforming retail experiences.",
28
+ "The Internet of Things connects everyday devices to the web for smarter living.",
29
+ "Cybersecurity threats are evolving, requiring constant vigilance.",
30
+ "3D printing is enabling rapid prototyping and custom manufacturing.",
31
+ "Edge computing reduces latency by processing data closer to the source.",
32
+ "Biometric authentication methods are enhancing security in devices.",
33
+ "Wearable technology is tracking health metrics in real-time.",
34
+ "Artificial intelligence is being used to create realistic deepfakes.",
35
+ // Cooking
36
+ "Preheat the oven to 375°F before you start mixing the batter.",
37
+ "She finely chopped the garlic and sautéed it in two tablespoons of olive oil.",
38
+ "A pinch of saffron adds a beautiful color and aroma to traditional paella.",
39
+ "If the soup is too salty, add a peeled potato to absorb excess sodium.",
40
+ "Let the bread dough rise for at least an hour in a warm, draft-free spot.",
41
+ "Marinate the chicken overnight in a blend of citrus and spices.",
42
+ "Use a cast-iron skillet to sear the steak on high heat.",
43
+ "Whisk the egg whites until they form stiff peaks.",
44
+ "Fold in the chocolate chips gently to keep the batter airy.",
45
+ "Brush the pastry with an egg wash for a golden finish.",
46
+ "Slow-roast the pork shoulder until it falls off the bone.",
47
+ "Garnish the salad with toasted nuts and fresh herbs.",
48
+ "Deglaze the pan with white wine for a rich sauce.",
49
+ "Simmer the curry paste until the aroma intensifies.",
50
+ "Let the risotto rest before serving to thicken slightly.",
51
+ // Sports
52
+ "He dribbled past two defenders and sank a three-pointer at the buzzer.",
53
+ "The marathon runner kept a steady pace despite the sweltering heat.",
54
+ "Their home team clinched the championship with a last-minute goal.",
55
+ "NASCAR fans cheered as the cars roared around the oval track.",
56
+ "She landed a perfect triple axel at the figure skating championship.",
57
+ "The cyclist pedaled up the steep hill in record time.",
58
+ "He pitched a no-hitter during the high school baseball game.",
59
+ "The quarterback threw a touchdown pass under heavy pressure.",
60
+ "They scored a hat-trick in the hockey final.",
61
+ "The boxer delivered a swift uppercut in the final round.",
62
+ "Surfers caught massive waves at dawn on the Pacific coast.",
63
+ "Fans erupted when the underdog scored the winning goal.",
64
+ "The swimmer broke the national record in the 200m freestyle.",
65
+ "The gymnast executed a flawless routine on the balance beam.",
66
+ "The rugby team celebrated their victory with a traditional haka.",
67
+ // Finance
68
+ "The stock market rallied after positive earnings reports.",
69
+ "Investors are closely watching interest rate changes by the Federal Reserve.",
70
+ "Cryptocurrency prices have been extremely volatile this year.",
71
+ "Diversification is key to managing investment risk effectively.",
72
+ "Inflation rates have reached a 40-year high, impacting consumer spending.",
73
+ "Many companies are adopting ESG criteria to attract socially conscious investors.",
74
+ "The bond market is reacting to geopolitical tensions and supply chain disruptions.",
75
+ "Venture capital funding for startups has surged in the tech sector.",
76
+ "Exchange-traded funds (ETFs) offer a way to invest in diversified portfolios.",
77
+ "The global economy is recovering from the pandemic, but challenges remain.",
78
+ "Central banks are exploring digital currencies to modernize payment systems.",
79
+ "Retail investors are increasingly participating in the stock market through apps.",
80
+ "Hedge funds are using complex algorithms to gain an edge in trading.",
81
+ "Real estate prices have skyrocketed in urban areas due to low inventory.",
82
+ "The startup raised $10 million in its Series A funding round.",
83
+ // Music
84
+ "The symphony orchestra played a hauntingly beautiful melody.",
85
+ "She strummed her guitar softly, filling the room with a warm sound.",
86
+ "The DJ mixed tracks seamlessly, keeping the crowd dancing all night.",
87
+ "His voice soared during the high notes of the ballad.",
88
+ "The band played an acoustic set in the intimate coffee shop.",
89
+ "Jazz musicians often improvise solos based on the chord changes.",
90
+ "The opera singer hit the high C with perfect pitch.",
91
+ "The choir harmonized beautifully, filling the church with sound.",
92
+ "He composed a symphony that was performed at the concert hall.",
93
+ "The singer-songwriter wrote heartfelt lyrics about love and loss.",
94
+ "The rock band headlined the festival, drawing a massive crowd.",
95
+ "Hip-hop artists use rhythm and rhyme to tell powerful stories.",
96
+ "The violinist played a virtuosic solo that left the audience in awe.",
97
+ "Folk music often reflects the culture and traditions of a community.",
98
+ "The gospel choir lifted spirits with their uplifting performance.",
99
+ // History
100
+ "The fall of the Berlin Wall in 1989 marked the end of the Cold War.",
101
+ "Ancient Egypt's pyramids are a testament to their architectural prowess.",
102
+ "Europe's Renaissance period sparked a revival in art and science.",
103
+ "The signing of the Declaration of Independence in 1776 established the United States.",
104
+ "The Industrial Revolution transformed economies and societies worldwide.",
105
+ "Rome was the center of a vast empire that influenced law and governance.",
106
+ "The discovery of the New World by Christopher Columbus in 1492 changed global trade.",
107
+ "The French Revolution in 1789 led to significant political and social change.",
108
+ "World War II was a global conflict that reshaped international relations.",
109
+ "The fall of the Roman Empire in 476 AD marked the beginning of the Middle Ages.",
110
+ "The invention of the printing press revolutionized the spread of knowledge.",
111
+ "The Cold War was characterized by political tension between the U.S. and the Soviet Union.",
112
+ "The ancient Silk Road connected East and West through trade routes.",
113
+ "The signing of the Magna Carta in 1215 established principles of due process.",
114
+ "Exploration during the Age of Discovery expanded European empires across the globe.",
115
+ ].sort(() => Math.random() - 0.5); // Shuffle sentences