Skip to content

Commit

Permalink
remove on_batch_begin and on_batch_end callbacks (#3078)
Browse files Browse the repository at this point in the history
* remove on_batch_begin and on_batch_end callbacks

* Update gensim/models/callbacks.py

Co-authored-by: Radim Řehůřek <radimrehurek@seznam.cz>

* Update callbacks.py

* get rid of heading, sphinx dislikes it

* get rid of messy code

Co-authored-by: Radim Řehůřek <radimrehurek@seznam.cz>
  • Loading branch information
mpenkov and piskvorky authored Mar 19, 2021
1 parent 2589c5a commit 0dbfa80
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 30 deletions.
27 changes: 5 additions & 22 deletions gensim/models/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
8 changes: 0 additions & 8 deletions gensim/models/word2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,22 +1145,15 @@ 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:
progress_queue.put(None)
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)
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 0dbfa80

Please sign in to comment.