Skip to content
Dima Kudosh edited this page Feb 3, 2016 · 2 revisions

Usage

Firstly import word2vec.

extern crate word2vec;

Then you can create WordVector object using load_from_binary method. It has only one parameter - file_name and it return Result<WordVector, Word2VecError>.

let wordvectors = word2vec::wordvectors::WordVector::load_from_binary("vectors.bin");

WordVector object has 3 public methods:

  • get_vector(&self, word: &str) -> Option<&Vec<f32>> Return vector for specified word or None
  • cosine(&self, word: &str, n: usize) -> Option<Vec<(String, f32)>> Return n tuples with word and probability or None
  • analogy(&self, pos: Vec<&str>, neg: Vec<&str>, n: usize) -> Option<Vec<(String, f32)>> Return n tuples with word and probability or None

Also you can load word clusters from file. For this you must create WordClusters object using load_from_file method: let clusters = word2vec::wordclusters::WordClusters::load_from_file("classes.txt"); It's takes only one parameter (filename: &str) and return Result<WordClusters, Word2VecError>

WordClusters has 2 public method:

  • get_words_on_cluster(&self, index: i32) -> Option<&Vec<String>>
  • get_cluster(&self, word: &str) -> Option<&i32>
Clone this wiki locally