ping98k commited on
Commit
c305ab2
·
1 Parent(s): 34e0278

Add cluster name extraction for heatmap axis labels in K-Means clustering

Browse files
Files changed (1) hide show
  1. main.js +13 -2
main.js CHANGED
@@ -13,7 +13,16 @@ const task = "Given a textual input sentence, retrieve relevant categories that
13
 
14
  document.getElementById("run").onclick = async () => {
15
  const text = document.getElementById("input").value;
 
16
  const groups = text.split(/\n{3,}/);
 
 
 
 
 
 
 
 
17
  const groupEmbeddings = [];
18
  for (const g of groups) {
19
  const lines = g.split(/\n/).filter(x => x.trim() != "");
@@ -41,7 +50,9 @@ document.getElementById("run").onclick = async () => {
41
  }
42
  sim.push(row);
43
  }
44
- const data = [{ z: sim, type: "heatmap", colorscale: "Viridis", zmin: 0, zmax: 1 }];
 
 
45
  Plotly.newPlot("plot-heatmap", data, {
46
  xaxis: { title: "Group", scaleanchor: "y", scaleratio: 1 },
47
  yaxis: { title: "Group", scaleanchor: "x", scaleratio: 1 },
@@ -208,4 +219,4 @@ document.getElementById("kmeans-btn").onclick = async () => {
208
  // Re-run heatmap after updating textarea
209
  document.getElementById("run").onclick();
210
  }
211
- };
 
13
 
14
  document.getElementById("run").onclick = async () => {
15
  const text = document.getElementById("input").value;
16
+
17
  const groups = text.split(/\n{3,}/);
18
+
19
+ // Extract cluster names from lines starting with ##
20
+ const clusterNames = text.split(/\n/)
21
+ .map(x => x.trim())
22
+ .filter(x => x && x.startsWith('##'))
23
+ .map(x => x.replace(/^##\s*/, ''));
24
+
25
+
26
  const groupEmbeddings = [];
27
  for (const g of groups) {
28
  const lines = g.split(/\n/).filter(x => x.trim() != "");
 
50
  }
51
  sim.push(row);
52
  }
53
+ // If clusterNames exist and match group count, use as axis labels
54
+ let xLabels = clusterNames && clusterNames.length === n ? clusterNames : Array.from({length: n}, (_, i) => `Group ${i+1}`);
55
+ const data = [{ z: sim, type: "heatmap", colorscale: "Viridis", zmin: 0, zmax: 1, x: xLabels, y: xLabels }];
56
  Plotly.newPlot("plot-heatmap", data, {
57
  xaxis: { title: "Group", scaleanchor: "y", scaleratio: 1 },
58
  yaxis: { title: "Group", scaleanchor: "x", scaleratio: 1 },
 
219
  // Re-run heatmap after updating textarea
220
  document.getElementById("run").onclick();
221
  }
222
+ };