170170 CORPUSFILE_VERSION = - 1
171171
172172 def train_epoch_sg (model , corpus_file , offset , _cython_vocab , _cur_epoch , _expected_examples , _expected_words ,
173- _work , _neu1 , compute_loss ):
173+ _work , _neu1 ):
174174 raise RuntimeError ("Training with corpus_file argument is not supported" )
175175
176176 def train_epoch_cbow (model , corpus_file , offset , _cython_vocab , _cur_epoch , _expected_examples , _expected_words ,
177- _work , _neu1 , compute_loss ):
177+ _work , _neu1 ):
178178 raise RuntimeError ("Training with corpus_file argument is not supported" )
179179
180180
181181class Word2Vec (utils .SaveLoad ):
182182 def __init__ (self , sentences = None , corpus_file = None , vector_size = 100 , alpha = 0.025 , window = 5 , min_count = 5 ,
183183 max_vocab_size = None , sample = 1e-3 , seed = 1 , workers = 3 , min_alpha = 0.0001 ,
184184 sg = 0 , hs = 0 , negative = 5 , ns_exponent = 0.75 , cbow_mean = 1 , hashfxn = hash , epochs = 5 , null_word = 0 ,
185- trim_rule = None , sorted_vocab = 1 , batch_words = MAX_WORDS_IN_BATCH , compute_loss = False , callbacks = (),
185+ trim_rule = None , sorted_vocab = 1 , batch_words = MAX_WORDS_IN_BATCH , callbacks = (),
186186 comment = None , max_final_vocab = None ):
187187 """Train, use and evaluate neural networks described in https://code.google.com/p/word2vec/.
188188
@@ -282,9 +282,6 @@ def __init__(self, sentences=None, corpus_file=None, vector_size=100, alpha=0.02
282282 Target size (in words) for batches of examples passed to worker threads (and
283283 thus cython routines).(Larger batches will be passed if individual
284284 texts are longer than 10000 words, but the standard cython code truncates to that maximum.)
285- compute_loss: bool, optional
286- If True, computes and stores loss value which can be retrieved using
287- :meth:`~gensim.models.word2vec.Word2Vec.get_latest_training_loss`.
288285 callbacks : iterable of :class:`~gensim.models.callbacks.CallbackAny2Vec`, optional
289286 Sequence of callbacks to be executed at specific stages during training.
290287
@@ -325,8 +322,7 @@ def __init__(self, sentences=None, corpus_file=None, vector_size=100, alpha=0.02
325322 self .negative = int (negative )
326323 self .ns_exponent = ns_exponent
327324 self .cbow_mean = int (cbow_mean )
328- self .compute_loss = bool (compute_loss )
329- self .running_training_loss = 0
325+ self .epoch_loss = 0.0
330326 self .min_alpha_yet_reached = float (alpha )
331327 self .corpus_count = 0
332328 self .corpus_total_words = 0
@@ -380,7 +376,7 @@ def build_vocab_and_train(self, corpus_iterable=None, corpus_file=None, trim_rul
380376 self .train (
381377 corpus_iterable = corpus_iterable , corpus_file = corpus_file , total_examples = self .corpus_count ,
382378 total_words = self .corpus_total_words , epochs = self .epochs , start_alpha = self .alpha ,
383- end_alpha = self .min_alpha , compute_loss = self . compute_loss , callbacks = callbacks )
379+ end_alpha = self .min_alpha , callbacks = callbacks )
384380
385381 def build_vocab (self , corpus_iterable = None , corpus_file = None , update = False , progress_per = 10000 ,
386382 keep_raw_vocab = False , trim_rule = None , ** kwargs ):
@@ -838,10 +834,10 @@ def _do_train_epoch(self, corpus_file, thread_id, offset, cython_vocab, thread_p
838834
839835 if self .sg :
840836 examples , tally , raw_tally = train_epoch_sg (self , corpus_file , offset , cython_vocab , cur_epoch ,
841- total_examples , total_words , work , neu1 , self . compute_loss )
837+ total_examples , total_words , work , neu1 )
842838 else :
843839 examples , tally , raw_tally = train_epoch_cbow (self , corpus_file , offset , cython_vocab , cur_epoch ,
844- total_examples , total_words , work , neu1 , self . compute_loss )
840+ total_examples , total_words , work , neu1 )
845841
846842 return examples , tally , raw_tally
847843
@@ -866,9 +862,9 @@ def _do_train_job(self, sentences, alpha, inits):
866862 work , neu1 = inits
867863 tally = 0
868864 if self .sg :
869- tally += train_batch_sg (self , sentences , alpha , work , self . compute_loss )
865+ tally += train_batch_sg (self , sentences , alpha , work )
870866 else :
871- tally += train_batch_cbow (self , sentences , alpha , work , neu1 , self . compute_loss )
867+ tally += train_batch_cbow (self , sentences , alpha , work , neu1 )
872868 return tally , self ._raw_word_count (sentences )
873869
874870 def _clear_post_train (self ):
@@ -877,7 +873,7 @@ def _clear_post_train(self):
877873
878874 def train (self , corpus_iterable = None , corpus_file = None , total_examples = None , total_words = None ,
879875 epochs = None , start_alpha = None , end_alpha = None , word_count = 0 ,
880- queue_factor = 2 , report_delay = 1.0 , compute_loss = False , callbacks = (),
876+ queue_factor = 2 , report_delay = 1.0 , callbacks = (),
881877 ** kwargs ):
882878 """Update the model's neural weights from a sequence of sentences.
883879
@@ -931,9 +927,6 @@ def train(self, corpus_iterable=None, corpus_file=None, total_examples=None, tot
931927 Multiplier for size of queue (number of workers * queue_factor).
932928 report_delay : float, optional
933929 Seconds to wait before reporting progress.
934- compute_loss: bool, optional
935- If True, computes and stores loss value which can be retrieved using
936- :meth:`~gensim.models.word2vec.Word2Vec.get_latest_training_loss`.
937930 callbacks : iterable of :class:`~gensim.models.callbacks.CallbackAny2Vec`, optional
938931 Sequence of callbacks to be executed at specific stages during training.
939932
@@ -959,8 +952,7 @@ def train(self, corpus_iterable=None, corpus_file=None, total_examples=None, tot
959952 total_examples = total_examples ,
960953 total_words = total_words )
961954
962- self .compute_loss = compute_loss
963- self .running_training_loss = 0.0
955+ self .epoch_loss = 0.0
964956
965957 for callback in callbacks :
966958 callback .on_train_begin (self )
@@ -1820,17 +1812,6 @@ def save(self, *args, **kwargs):
18201812 kwargs ['ignore' ] = kwargs .get ('ignore' , []) + ['cum_table' , ]
18211813 super (Word2Vec , self ).save (* args , ** kwargs )
18221814
1823- def get_latest_training_loss (self ):
1824- """Get current value of the training loss.
1825-
1826- Returns
1827- -------
1828- float
1829- Current training loss.
1830-
1831- """
1832- return self .running_training_loss
1833-
18341815 @classmethod
18351816 def load (cls , * args , rethrow = False , ** kwargs ):
18361817 """Load a previously saved :class:`~gensim.models.word2vec.Word2Vec` model.
0 commit comments