Class: FastText::Vectorizer

Inherits:
Model
  • Object
show all
Defined in:
lib/fasttext/vectorizer.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  lr: 0.5,
  lr_update_rate: 100,
  dim: 100,
  ws: 5,
  epoch: 5,
  min_count: 1,
  min_count_label: 0,
  neg: 5,
  word_ngrams: 1,
  loss: "ns",
  model: "skipgram",
  bucket: 2000000,
  minn: 3,
  maxn: 6,
  thread: 3,
  t: 0.0001,
  verbose: 2,
  pretrained_vectors: "",
  save_output: false,
  # seed: 0
}

Instance Method Summary collapse

Methods inherited from Model

#dimension, #initialize, #quantized?, #save_model, #sentence_vector, #subword_id, #subwords, #word_id, #word_vector, #words

Constructor Details

This class inherits a constructor from FastText::Model

Instance Method Details

#analogies(word_a, word_b, word_c, k: 10) ⇒ Object



36
37
38
# File 'lib/fasttext/vectorizer.rb', line 36

def analogies(word_a, word_b, word_c, k: 10)
  m.analogies(k, word_a, word_b, word_c).map(&:reverse).to_h
end

#fit(x) ⇒ Object



26
27
28
29
30
# File 'lib/fasttext/vectorizer.rb', line 26

def fit(x)
  input = input_path(x)
  @m ||= Ext::Model.new
  m.train(DEFAULT_OPTIONS.merge(@options).merge(input: input))
end

#nearest_neighbors(word, k: 10) ⇒ Object



32
33
34
# File 'lib/fasttext/vectorizer.rb', line 32

def nearest_neighbors(word, k: 10)
  m.nearest_neighbors(word, k).map(&:reverse).to_h
end