首页 > 解决方案 > php中的word2vec

问题描述

我对 ML 相当陌生,不知道事情是如何工作的,我有一个带搜索栏的网页。我需要使用 word2vec 在搜索栏中完成用户输入。

我正在使用来自https://github.com/donlinglok/C-word2vec-php的代码

   <?php

$txtfilepath = fopen("options.txt", "r") or die("Unable to open file!");
echo fread($txtfilepath, filesize("options.txt"));
//fclose($txtfilepath);

function train($txtfilepath) {
    $cbow = 1;
    $size = 500;
    $window = 10;
    $negative = 10;
    $hs = 0;
    $sample = "1e-5";
    $threads = 40;
    $binary = 1;
    $iter = 3;
    $min_count = 10;

    exec ( "cd " . dirname ( __FILE__ ) . "/google-word2vec-trunk && ./word2vec " . " -train " . $txtfilepath . " -output " . dirname ( __FILE__ ) . "/vectors.bin " . " -cbow " . $cbow . " -size " . $size . " -window " . $window . " -negative " . $negative . " -hs " . $hs . " -sample " . $sample . " -threads " . $threads . " -binary " . $binary . " -iter " . $iter . " -min-count " . $min_count, $outputArray );
}
function distance($keyword) {
    exec ( "cd " . dirname ( __FILE__ ) . " && ./distancecli " . dirname ( __FILE__ ) . "/vectors.bin " . $keyword, $outputArray );
    if (isset ( $outputArray[0] )) {
        return $outputArray;
    } else {
        return distance ( $keyword );
    }
}

//train ( dirname ( __FILE__ ) . "/google-word2vec-trunk/questions-words.txt" );
echo json_encode ( distance ( "facebook" ), true );
?>

我下一步该怎么做?如何运行此代码并在搜索栏中获取结果?我从网络文件夹 http://localhost/trainmodel/word2vec.php 运行它并收到此错误致命错误:

第 23 行的 C:\xampp\htdocs\trainmodel\word2vec.php 中超过了 30 秒的最大执行时间

标签: phpword2vec

解决方案


推荐阅读