lib/fasttext/vectorizer.rb in fasttext-0.2.1 vs lib/fasttext/vectorizer.rb in fasttext-0.2.2

- old
+ new

@@ -27,13 +27,14 @@ autotune_duration: 60 * 5, autotune_model_size: "" } def fit(x) - input = input_path(x) @m ||= Ext::Model.new - m.train(DEFAULT_OPTIONS.merge(@options).merge(input: input)) + a = build_args(DEFAULT_OPTIONS) + a.input, _ref = input_path(x) + m.train(a) end def nearest_neighbors(word, k: 10) m.nearest_neighbors(word, k).map(&:reverse).to_h end @@ -46,18 +47,18 @@ # separate example by newlines # https://github.com/facebookresearch/fastText/issues/518 def input_path(x) if x.is_a?(String) - x + [x, nil] else tempfile = Tempfile.new("fasttext") x.each do |xi| tempfile.write(xi.gsub("\n", " ")) # replace newlines in document tempfile.write("\n") end tempfile.close - tempfile.path + [tempfile.path, tempfile] end end end end