-
Notifications
You must be signed in to change notification settings - Fork 3
/
word2vec.js
49 lines (47 loc) · 1.62 KB
/
word2vec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var starting = [
['man', 'king', 'woman'],
['man', 'emperor', 'woman'],
['Japan', 'sushi', 'Germany'],
['cat', 'kitten', 'dog'],
['big', 'biggest', 'small'],
['Athens', 'Greece', 'Oslo'],
['brother', 'sister', 'grandson'],
['France', 'Paris', 'Japan'],
['Einstein', 'scientist', 'Mozart'],
['Einstein', 'scientist', 'Picasso'],
['Japan', 'sushi', 'Germany'],
['China', 'Beijing', 'Russia'],
['Microsoft', 'Steve_Ballmer', 'Apple'],
['Microsoft', 'Steve_Ballmer', 'Google'],
['Luke', 'Star_Wars', 'Picard'],
['Hipsters', 'New_York', 'Rednecks'],
['lawyer', 'liar', 'politician'],
['Arnold_Schwarzenegger', 'Predator', 'Sylvester_Stallone'],
['Metallica', 'rock', 'Snoop_Dog'],
['science', 'fact', 'politics']
];
var random = starting[Math.floor(Math.random()*starting.length)];
$('#first').val(random[0]);
$('#isto').val(random[1]);
$('#second').val(random[2]);
$('#analogy_form').submit(function () {
submitform();
return false;
});
function submitform(){
var formData = JSON.stringify($("#analogy_form").serializeArray());
var otherFormData = $("#analogy_form").serializeArray();
var negative = [otherFormData[0].value];
var positive = [otherFormData[1].value, otherFormData[2].value];
var analogy = {'positive': positive, 'negative': negative, 'topn': 10};
$.ajax({
url:'http://localhost:5000/most_similar',
type:'POST',
contentType: "application/json",
dataType:'json',
data: JSON.stringify(analogy),
success: function(json){
$('#result').val(json.result[0][0]);
}
});
}