This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| py_binary( | |
| name = “word2vec”, | |
| srcs = [“word2vec.py”], | |
| deps = [“:gen_word2vec”, ...], | |
| ... | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| native.py_library( | |
| name = "gen_word2vec", | |
| src = ["gen_word2vec.py"] | |
| ... | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| native.genrule( | |
| name = "gen_word2vec_pygenrule", | |
| tools = ["gen_gen_word2vec_py_wrappers_cc"], | |
| out = ["gen_word2vec.py"], | |
| ... | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| native.cc_binary( | |
| name = "gen_gen_word2vec_py_wrappers_cc", | |
| deps = [":word2vec_ops", ...], | |
| ... | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| tf_gen_op_wrapper_py( | |
| name = "gen_word2vec", | |
| out = "gen_word2vec.py", | |
| deps = [":word2vec_ops"], | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| node { | |
| name: "Cast_1" | |
| op: "Cast" | |
| input: "Skipgram:4" | |
| attr { | |
| key: "DstT" | |
| value { | |
| type: DT_FLOAT | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| lr = opts.learning_rate * tf.maximum(0.0001, 1.0 — tf.cast(self._words, tf.float32) / words_to_train) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| REGISTER_OP(“Skipgram”) | |
| .Output(“vocab_word: string”) | |
| .Output(“vocab_freq: int32”) | |
| .Output(“words_per_epoch: int64”) | |
| .Output(“current_epoch: int32”) | |
| .Output(“total_words_processed: int64”) | |
| .Output(“examples: int32”) | |
| .Output(“labels: int32”) | |
| .Attr(“filename: string”) | |
| .Attr(“batch_size: int”) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (words, counts, words_per_epoch, self._epoch, self._words, examples, labels) = word2vec.skipgram(filename=opts.train_data, | |
| batch_size=opts.batch_size, | |
| window_size=opts.window_size, | |
| min_count=opts.min_count, | |
| subsample=opts.subsample) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # example input: | |
| sentence = 'The quick brown fox jumped over the lazy dog.' | |
| # tokenize and normalize words, building the set of all vocabulary ever seen | |
| words_set = {} | |
| def tokenize(sentence): | |
| return map(str.lower, sentence[0:-1].split(' ')) | |
| for word in tokenize(sentence): | |
| words_set[word] = True |