Class: Word2Vec::WordClusters

Inherits:
Object
  • Object
show all
Defined in:
lib/word2vec/word_clusters.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vocab:, clusters:) ⇒ WordClusters

Returns a new instance of WordClusters.



7
8
9
10
# File 'lib/word2vec/word_clusters.rb', line 7

def initialize(vocab:, clusters:)
  self.vocab = vocab
  self.clusters = clusters
end

Instance Attribute Details

#clustersObject

Returns the value of attribute clusters.



5
6
7
# File 'lib/word2vec/word_clusters.rb', line 5

def clusters
  @clusters
end

#vocabObject

Returns the value of attribute vocab.



5
6
7
# File 'lib/word2vec/word_clusters.rb', line 5

def vocab
  @vocab
end

Class Method Details

.from_text(fname) ⇒ Object



29
30
31
32
33
34
# File 'lib/word2vec/word_clusters.rb', line 29

def self.from_text(fname)
  csv = CSV.read(fname, col_sep: " ")
  vocab = csv.transpose[0]
  clusters = csv.transpose[1].map(&:to_i)
  self.new(vocab: vocab, clusters: clusters)
end

Instance Method Details

#[](word) ⇒ Object

Raises:

  • (NotImplementedError)


16
17
18
# File 'lib/word2vec/word_clusters.rb', line 16

def [](word)
  raise NotImplementedError
end

#get_cluster(word) ⇒ Object

Raises:

  • (NotImplementedError)


20
21
22
# File 'lib/word2vec/word_clusters.rb', line 20

def get_cluster(word)
  raise NotImplementedError
end

#get_words_on_cluster(cluster) ⇒ Object



24
25
26
27
# File 'lib/word2vec/word_clusters.rb', line 24

def get_words_on_cluster(cluster)
  indices = clusters.each_with_index.map { |clst, i| i if clst == cluster }.compact
  self.vocab.values_at(*indices)
end

#ix(word) ⇒ Object

Raises:

  • (NotImplementedError)


12
13
14
# File 'lib/word2vec/word_clusters.rb', line 12

def ix(word)
  raise NotImplementedError
end