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,
  autotune_validation_file: "",
  autotune_metric: "f1",
  autotune_predictions: 1,
  autotune_duration: 60 * 5,
  autotune_model_size: ""
}

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



42
43
44
# File 'lib/fasttext/vectorizer.rb', line 42

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



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

def fit(x)
  @m ||= Ext::Model.new
  a = build_args(DEFAULT_OPTIONS)
  a.input, _ref = input_path(x)
  m.train(a)
end

#nearest_neighbors(word, k: 10) ⇒ Object



38
39
40
# File 'lib/fasttext/vectorizer.rb', line 38

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