pengfoo / word2vec-pytorch Goto Github PK
View Code? Open in Web Editor NEWA Skip-Gram model of Word2vec implemented in pytorch.
A Skip-Gram model of Word2vec implemented in pytorch.
in def gen_vocab(self) we select the vocab that have number of freq >=self.min_count like this:
index = 0
for item_id, freq in vocab_freq_dict.items():
if freq < self.min_count:
continue
vocab[item_id] = freq
word2id[item_id] = index
id2word[index] = item_id
index += 1
return vocab, word2id, id2word, total_word_count, total_sent_count`
can you please clarify this function (def gen_subsample_table(self))?
`
"""
sub sampling rate, higher than that would be sub sampled using
the word2vec paper using: p(w_i) = 1 - sqrt(sub_sampling / freq)
the word2vec code using: p(w_i) = 1 - (sqrt(sub_sampling / freq) + sub_sampling / freq)
we use word2vec code sub sampling method here.
:return: {word_id: sample_score}
"""
def sub_sampling(_freq):
return (self.sub_sampling_t / 1.0 / _freq) ** 0.5 + self.sub_sampling_t / 1.0 / _freq
# word freq count to word freq ratio
sub_sample_tbl = {item: freq / 1.0 / self.total_word_count
for item, freq in self.vocab.items()
if freq / 1.0 / self.total_word_count > self.sub_sampling_t}
# freq to score
sub_sample_tbl = {item: sub_sampling(_freq) for item, _freq in sub_sample_tbl.items()}
# word to id
sub_sample_tbl = {self.word2id[i]: j for i, j in sub_sample_tbl.items() if j < 1}
return sub_sample_tbl
`
line 9
9. def sub_sampling(_freq): it looks like it returns ( p(w_i) = (sqrt(sub_sampling / freq) + sub_sampling / freq) ) not ( p(w_i) = 1 - (sqrt(sub_sampling / freq) + sub_sampling / freq) ) right?
why this line ?
14. if freq / 1.0 / self.total_word_count > self.sub_sampling_t}
if we before used
4. if freq < self.min_count: in the def gen_vocab(self) function in the first part of the question
what is the meaning of this line?
sub_sample_tbl = {self.word2id[i]: j for i, j in sub_sample_tbl.items() if j < 1}
thank you!
Hi! Thanks for this repo - super useful.
I think you may have forgotten to use your subsampling table sub_sampling_table
:
word2vec-pytorch/word2vec/data_handler.py
Line 51 in 99269ae
I see it being defined but I can't find any references to it.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.