This project is basic on google word2vec trunk https://code.google.com/archive/p/word2vec/
- Install
docker
anddocker-compose
on your machine. https://www.docker.com/get-started - Download this project, go to the project directory and run.
docker-compose up
- go to
http://localhost:8088/
, and you should see the result of word2vec.
- Move the files inside
var/www/html
to your path. - Add below code to your .php file.
<?php include 'word2vec.php';?>
- Use the function inside the
word2vec.php
.
<?php
// if you want to train your own bin
train (...);
// run word2vec
distance (...);
?>
- You should also consider changing the path or managing folder permission for security reasons.
- run
distance
with bin and keyword
<?php
print_r(distance ( dirname ( __FILE__ ) . "/questions-words_vectors.bin", "good" ));
print_r(distance ( dirname ( __FILE__ ) . "/questions-words_vectors.bin", "bad" ));
?>
- result as below
Array
(
[0] => sharpest,0.706261
[1] => widest,0.699204
[2] => highest,0.695929
[3] => shortest,0.693608
...
)
Array
(
[0] => sweet,0.721250
[1] => dark,0.716362
[2] => strangest,0.712229
[3] => darkest,0.706598
...
)
- run
word_analogy
with bin and three keywords
<?php
print_r(word_analogy ( dirname ( __FILE__ ) . "/questions-words_vectors.bin", "good", "bad", "hot" ));
?>
- result as below
Array
(
[0] => youngest,0.972688
[1] => biggest,0.970707
[2] => largest,0.968398
[3] => cheaper,0.968350
...
)
- run
train
with text file
<?php
train ( dirname ( __FILE__ ) . "/google-word2vec-trunk/questions-words.txt" );
?>