Class: SemanticTextChunker::Embedders::Null

Inherits:
Base
  • Object
show all
Defined in:
lib/semantic_text_chunker/embedders/null.rb

Instance Method Summary collapse

Methods inherited from Base

#cosine_similarity

Instance Method Details

#embed(texts) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/semantic_text_chunker/embedders/null.rb', line 4

def embed(texts)
  texts.map do |text|
    words = text.downcase.split.uniq
    vec   = Array.new(512, 0.0)
    words.each { |w| vec[w.hash.abs % 512] += 1.0 }
    norm = Math.sqrt(vec.sum { |x| x**2 })
    norm > 0 ? vec.map { |x| x / norm } : vec
  end
end