From 0dbfa80669a64b620c76139e7853d25a068ad1a7 Mon Sep 17 00:00:00 2001 From: Michael Penkov Date: Fri, 19 Mar 2021 11:10:35 +0900 Subject: [PATCH] remove on_batch_begin and on_batch_end callbacks (#3078) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * remove on_batch_begin and on_batch_end callbacks * Update gensim/models/callbacks.py Co-authored-by: Radim Řehůřek * Update callbacks.py * get rid of heading, sphinx dislikes it * get rid of messy code Co-authored-by: Radim Řehůřek --- gensim/models/callbacks.py | 27 +++++---------------------- gensim/models/word2vec.py | 8 -------- 2 files changed, 5 insertions(+), 30 deletions(-) diff --git a/gensim/models/callbacks.py b/gensim/models/callbacks.py index ab2bb05d8e..42f250cb91 100644 --- a/gensim/models/callbacks.py +++ b/gensim/models/callbacks.py @@ -578,6 +578,11 @@ class CallbackAny2Vec: See examples at the module level docstring for how to define your own callbacks by inheriting from this class. + As of gensim 4.0.0, the following callbacks are no longer supported, and overriding them will have no effect: + + - on_batch_begin + - on_batch_end + """ def on_epoch_begin(self, model): """Method called at the start of each epoch. @@ -601,28 +606,6 @@ def on_epoch_end(self, model): """ pass - def on_batch_begin(self, model): - """Method called at the start of each batch. - - Parameters - ---------- - model : :class:`~gensim.models.word2vec.Word2Vec` or subclass - Current model. - - """ - pass - - def on_batch_end(self, model): - """Method called at the end of each batch. - - Parameters - ---------- - model : :class:`~gensim.models.word2vec.Word2Vec` or subclass - Current model. - - """ - pass - def on_train_begin(self, model): """Method called at the start of the training process. diff --git a/gensim/models/word2vec.py b/gensim/models/word2vec.py index 77be91e5c6..23c5b90429 100755 --- a/gensim/models/word2vec.py +++ b/gensim/models/word2vec.py @@ -1145,7 +1145,6 @@ def _worker_loop(self, job_queue, progress_queue): """ thread_private_mem = self._get_thread_working_mem() jobs_processed = 0 - callbacks = progress_queue.callbacks while True: job = job_queue.get() if job is None: @@ -1153,14 +1152,8 @@ def _worker_loop(self, job_queue, progress_queue): break # no more jobs => quit this worker data_iterable, alpha = job - for callback in callbacks: - callback.on_batch_begin(self) - tally, raw_tally = self._do_train_job(data_iterable, alpha, thread_private_mem) - for callback in callbacks: - callback.on_batch_end(self) - progress_queue.put((len(data_iterable), tally, raw_tally)) # report back progress jobs_processed += 1 logger.debug("worker exiting, processed %i jobs", jobs_processed) @@ -1410,7 +1403,6 @@ def _train_epoch( """ job_queue = Queue(maxsize=queue_factor * self.workers) progress_queue = Queue(maxsize=(queue_factor + 1) * self.workers) - progress_queue.callbacks = callbacks # messy way to pass along for just this session workers = [ threading.Thread(