Skip to content

Google Word2Vec Interface for Node.js with N-API

License

Notifications You must be signed in to change notification settings

Astro36/word2vec4node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Word2Vec4Node

Google Word2Vec Interface for Node.js with N-API

npm npm

Notice

Only Unix-like OS can use Word2Vec.train() method. pthread only working on POSIX, Windows can not use the method.

ChangeLog

See CHANGELOG

Installation

  • Install with npm:
npm install word2vec4node --save
  • Clone the repo:
git clone https://github.com/Astro36/word2vec4node.git

Usage

Example

Find the top-N most similar words:

const Word2Vec = require('word2vec4node');
const model = Word2Vec.load('./data/vectors.json');
// [서울] - [한국] + [일본]
console.log(model.analogy({ positive: ['서울', '일본'], negative: ['한국'] }, 5));

Which word from the words doesn’t match with the others:

const Word2Vec = require('word2vec4node');
const model = Word2Vec.load('./data/vectors.json');
console.log(model.findDifference(['봄', '여름', '가을', '얼음']));

Compute cosine distances from the words:

const Word2Vec = require('word2vec4node');
const model = Word2Vec.load('./data/vectors.json');
console.log(model.getVector('대한민국').distance(model.getVector('한국')));

License

Word2Vec4Node
Copyright (C) 2018  Astro

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program.  If not, see <http:https://www.gnu.org/licenses/>.