fastText-grpc

所属分类:聚类算法
开发工具:C++
文件大小:19KB
下载次数:0
上传日期:2020-01-08 11:31:03
上 传 者sh-1993
说明:  fastText gRPC服务器
(fastText gRPC server)

文件列表:
config (0, 2020-01-08)
config\grpc.conf (192, 2020-01-08)
grpc (0, 2020-01-08)
grpc\CMakeLists.txt (485, 2020-01-08)
grpc\generate.sh (476, 2020-01-08)
grpc\include (0, 2020-01-08)
grpc\include\cfasttext.h (4055, 2020-01-08)
grpc\include\client.h (1339, 2020-01-08)
grpc\include\config.h (2542, 2020-01-08)
grpc\include\di.h (1747, 2020-01-08)
grpc\include\service.h (2269, 2020-01-08)
grpc\src (0, 2020-01-08)
grpc\src\CMakeLists.txt (1130, 2020-01-08)
grpc\src\client.cc (8003, 2020-01-08)
grpc\src\main.cc (1360, 2020-01-08)
grpc\src\sample.cc (591, 2020-01-08)
grpc\src\service.cc (9637, 2020-01-08)
php (0, 2020-01-08)
php\classes (0, 2020-01-08)
php\classes\ftext.cc (10579, 2020-01-08)
php\classes\ftext.h (1389, 2020-01-08)
php\clean.sh (534, 2020-01-08)
php\config.m4 (1533, 2020-01-08)
php\config.w32 (369, 2020-01-08)
php\fasttext.c (5148, 2020-01-08)
php\php_fasttext.h (609, 2020-01-08)
protos (0, 2020-01-08)
protos\ftext.proto (1761, 2020-01-08)

# fastText-grpc fastText-grpc is a PHP bindings for fastText and gRPC server. ## Requirements * [PHP 7.x](https://www.php.net/) * [fastText](https://fasttext.cc/) is a library for efficient learning of word representations and sentence classification. * [gRPC](https://grpc.io/) - An RPC library and framework * [Protocol Buffers](https://developers.google.com/protocol-buffers/) - Google's data interchange format ``` $ curl -fSL "https://github.com/facebookresearch/fastText/archive/v0.9.1.tar.gz" -o "./fastText-0.9.1.tgz" $ tar xf fastText-0.9.1.tgz $ cd fastText-0.9.1 $ mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Release $ make -j $(nproc) $ sudo make install ``` ## Building fastText for gRPC server & libclient ``` $ cd fastText-grpc/grpc $ ./generate.sh $ mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Release $ make -j $(nproc) $ sudo make install ``` ## Start gRPC server ``` $ fasttext-grpc-server -c config/grpc.conf ``` ## Building fastText for PHP ``` $ cd fastText-grpc/php $ phpize $ ./configure $ make -j $(nproc) $ sudo make install ``` edit your php.ini and add: ``` extension=fasttext.so ``` ## Class synopsis ```php fastText { public __construct ( string address ) public int load ( string filename ) public int getWordRows ( void ) public int getLabelRows ( void ) public int getWordId ( string word ) public string getWord ( int word_id ) public string getLabel ( int label_id ) public array getWordVectors ( string word ) public array getSentenceVectors ( string sentence ) public mixed getPredict ( streing word [, int k] ) public mixed getNN ( streing word [, int k] ) public mixed getAnalogies ( streing word [, int k] ) public mixed getNgrams ( streing word ) } ``` ## Table of Contents [fastText::__construct](#__construct) [fastText::load](#load) [fastText::getWordRows](#getwordrows) [fastText::getLabelRows](#getlabelrows) [fastText::getWordId](#getworded) [fastText::getWord](#getword) [fastText::getLabel](#getlabel) [fastText::getWordVectors](#getwordvectors) [fastText::getSentenceVectors](#getsentenceVectors) [fastText::getPredict](#getpredict) [fastText::getNN](#getnn) [fastText::getAnalogies](#getanalogies) [fastText::getNgrams](#getngramvectors) [return value format](#returnvalf) ----- ### fastText::__construct(string address) Instantiates a fastText object. ```php $address = '0.0.0.0:50051'; $ftext = new fastText($address); ``` ----- ### int fastText::load(string filename) load a model. ```php $model = 'model.bin'; $ftext->load($model); ``` ----- ### int fastText::getWordRows() get the number of vocabularies. ```php $rows = $ftext->getWordRows(); $words = []; for ($idx = 0; $idx < $rows; $idx++) { $words[$idx] = $ftext->getWord($idx); } ``` ----- ### int fastText::getLabelRows() get the number of labels. ```php $rows = $ftext->getLabelRows(); $labels = []; for ($idx = 0; $idx < $rows; $idx++) { $labels[$idx] = $ftext->getLabel($idx); } ``` ----- ### int fastText::getWordId(string word) get the word ID within the dictionary. ```php $word = 'Bern'; $rowId = $ftext->getWordId($word); ``` ----- ### string fastText::getWord(int word_id) converts a ID into a word. ```php $rows = $ftext->getWordRows(); $words = []; for ($idx = 0; $idx < $rows; $idx++) { $words[$idx] = $ftext->getWord($idx); } ``` ----- ### string fastText::getLabel(int label_id) converts a ID into a label. ```php $rows = $ftext->getLabelRows(); $labels = []; for ($idx = 0; $idx < $rows; $idx++) { $labels[$idx] = $ftext->getLabel($idx); } ``` ----- ### array fastText::getWordVectors(string word) get the vector representation of word. ```php $vectors = $ftext->getWordVectors('Beijing'); print_r($vectors); ``` ----- ### array fastText::getSentenceVectors(string sentence) get the vector representation of sentence. ```php $sentence = "It's fine day"; $vectors = $ftext->getSentenceVectors($sentence); print_r($vectors); ``` ----- ### fastText::getPredict * array fastText::getPredict(string word) * FALSE fastText::getPredict(string word) predict most likely labels with probabilities. ```php $probs = $ftext->getPredict('Berlin'); foreach ($probs as $row) { echo $row['label'].' '.$row['prob']; } ``` ----- ### fastText::getNN * array fastText::getNN(string word) * FALSE fastText::getNN(string word) query for nearest neighbors. ```php $probs = $ftext->getNN('Washington, D.C.'); foreach ($probs as $row) { echo $row['label'].' '.$row['prob']; } ``` ----- ### fastText::getAnalogies * array fastText::getAnalogies(string word) * FALSE fastText::getAnalogies(string word) query for analogies. ```php $probs = $ftext->getAnalogies('Paris + France - Spain'); foreach ($probs as $row) { echo $row['label'].' '.$row['prob']; } ``` ----- ### fastText::getNgrams * array fastText::getNgrams(string word) * FALSE fastText::getNgrams(string word) get the ngram vectors. ```php $res = $ftext->getNgrams('London'); print_r($res); ``` ----- ## return value format ```php $probs = [ ['label'=> '__label__1', 'prob'=> 0.4234 ], ['label'=> '__label__2', 'prob'=> 0.2345 ], ['label'=> '__label__3', 'prob'=> 0.1456 ], : : : ] ```

近期下载者

相关文件


收藏者