Skip to content

Commit e694cfd

Browse files
author
Miltos Allamanis
committed
Visualize computed embeddings in ICLR20-style.
Still missing: CI to compute the embeddings/tSNE.
1 parent d6a768b commit e694cfd

File tree

4 files changed

+109
-4
lines changed

4 files changed

+109
-4
lines changed

etc/compute_embeddings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def parse_arguments():
3535

3636
np.random.seed(args.seed)
3737
all_embeddings = np.array(all_embeddings)
38-
out = sklearn.manifold.TSNE(n_components=2).fit_transform(all_embeddings)
38+
out = sklearn.manifold.TSNE(n_components=2, metric="cosine").fit_transform(all_embeddings)
3939

4040
for i, paper_info in enumerate(data):
4141
paper_info['tsne_embedding'] = out[i].tolist()

paper-abstracts.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ layout:
33
title:
44
---
55
[
6-
{% for publication in site.publications %}{"key": "{{ publication.bibkey }}", "year": {{ publication.year }}, "title":{{ publication.title | jsonify }}, "abstract": {{ publication.content | jsonify }} }{% if forloop.rindex0 > 0 %},{% endif %}
6+
{% for publication in site.publications %}{"key": "{{ publication.bibkey }}", "year": "{{ publication.year }}", "title":{{ publication.title | jsonify }}, "abstract": {{ publication.content | jsonify }}, "tags": {{ publication.tags | jsonify }} }{% if forloop.rindex0 > 0 %},{% endif %}
77
{% endfor %}
88
]
99

public/css/hyde.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,11 @@ tr:hover .externallinks {
279279
tag {
280280
padding: .15rem .3rem;
281281
font-size: 70%;
282-
color: #fff;
282+
color: #000;
283283
background-color: #f3f3f3;
284284
border-radius: .15rem;
285285
}
286286

287287
tag > a {
288288
color: #fff;
289-
}
289+
}

tsne-viz.html

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
---
2+
layout: default
3+
title: Visualization of Publications on Machine Learning for Source Code
4+
description: A tSNE visualization of all the ML4Code papers
5+
---
6+
<h2>2D Map of Papers</h2>
7+
Each dot represents one paper in this survey. Hover your mouse over each point to look
8+
at the details. Click on a point to go to the paper information page.
9+
<div id="paperviz"></div>
10+
11+
Please consider <a href="/contributing.html">contributing</a> by updating
12+
the information of existing papers or adding new work.
13+
14+
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.js"></script>
15+
<script src="https://cdn.jsdelivr.net/npm/tippy.js@6/dist/tippy.umd.min.js"></script>
16+
<script src="https://d3js.org/d3.v4.js"></script>
17+
18+
<script>
19+
// set the dimensions and margins of the graph
20+
var margin = {top: 10, right: 30, bottom: 30, left: 60},
21+
width = 600 - margin.left - margin.right,
22+
height = 500 - margin.top - margin.bottom;
23+
24+
var svg = d3.select("#paperviz")
25+
.append("svg")
26+
.attr("width", width + margin.left + margin.right)
27+
.attr("height", height + margin.top + margin.bottom);
28+
29+
//Read the data
30+
d3.json("./etc/tsne.json", function(data) {
31+
// Add X axis
32+
var x = d3.scaleLinear()
33+
.domain([-15, 15])
34+
.range([ 0, width ]);
35+
36+
// Add Y axisB
37+
var y = d3.scaleLinear()
38+
.domain([-15, 15])
39+
.range([height, 0]);
40+
41+
// Add a tooltip div. Here I define the general feature of the tooltip: stuff that do not depend on the data point.
42+
// Its opacity is set to 0: we don't see it by default.
43+
var tooltip = d3.select("#paperviz")
44+
.append("div")
45+
.style("opacity", 0)
46+
.attr("class", "tooltip")
47+
.style("background-color", "rgb(81, 81, 81)")
48+
.style("width", "450px")
49+
.style("height", "120px")
50+
.style("color", "white")
51+
.style("border-width", "0px")
52+
.style("border-radius", "10px")
53+
.style("padding", "10px")
54+
.style("position", "absolute");
55+
56+
// A function that change this tooltip when the user hover a point.
57+
// Its opacity is set to 1: we can now see it. Plus it set the text and position of tooltip depending on the datapoint (d)
58+
var mouseover = function(d) {
59+
tooltip
60+
.style("opacity", 1)
61+
}
62+
63+
var mousemove = function(d) {
64+
tags = ""
65+
for (i=0; i<d.tags.length; i++) {
66+
tags += "<tag>" + d.tags[i] + "</tag>&nbsp;"
67+
}
68+
tooltip
69+
.html("<p>" + d.title + " " + tags + "</p>")
70+
.style("left", (d3.mouse(this)[0]+40) + "px")
71+
.style("top", (d3.mouse(this)[1]) + "px");
72+
d3.selectAll("circle").filter(dd => dd.key == d.key).style("fill", "#000");
73+
}
74+
75+
var mouseleave = function(d) {
76+
//tooltip
77+
// .transition()
78+
// .duration(300)
79+
// .style("opacity", 0)
80+
d3.selectAll("circle").filter(dd => dd.key == d.key).style("fill", "#69b3a2");
81+
}
82+
83+
var click_link = function(d) {
84+
window.location.href = "/publications/" + d.key + "/";
85+
}
86+
87+
// Add dots
88+
svg.append('g')
89+
.selectAll("dot")
90+
.data(data)
91+
.enter()
92+
.append("circle")
93+
.attr("cx", function (d) { return x(d.tsne_embedding[0]); } )
94+
.attr("cy", function (d) { return y(d.tsne_embedding[1]); } )
95+
.attr("r", 8)
96+
.style("fill", "#69b3a2")
97+
.style("opacity", 0.4)
98+
.style("stroke", "white")
99+
.on("mouseover", mouseover )
100+
.on("mousemove", mousemove )
101+
.on("mouseleave", mouseleave )
102+
.on("click", click_link)
103+
104+
});
105+
</script>

0 commit comments

Comments
 (0)