Class: Word2Vec::WordClusters
- Inherits:
-
Object
- Object
- Word2Vec::WordClusters
- Defined in:
- lib/word2vec/word_clusters.rb
Instance Attribute Summary collapse
-
#clusters ⇒ Object
Returns the value of attribute clusters.
-
#vocab ⇒ Object
Returns the value of attribute vocab.
Class Method Summary collapse
Instance Method Summary collapse
- #[](word) ⇒ Object
- #get_cluster(word) ⇒ Object
- #get_words_on_cluster(cluster) ⇒ Object
-
#initialize(vocab:, clusters:) ⇒ WordClusters
constructor
A new instance of WordClusters.
- #ix(word) ⇒ Object
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
#clusters ⇒ Object
Returns the value of attribute clusters.
5 6 7 |
# File 'lib/word2vec/word_clusters.rb', line 5 def clusters @clusters end |
#vocab ⇒ Object
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
16 17 18 |
# File 'lib/word2vec/word_clusters.rb', line 16 def [](word) raise NotImplementedError end |
#get_cluster(word) ⇒ Object
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
12 13 14 |
# File 'lib/word2vec/word_clusters.rb', line 12 def ix(word) raise NotImplementedError end |