Don’t forget yield keyword to generate batch data

TeeTracker
Mar 10, 2022

--

Since we are recently reviewing RNN and LSTM etc., we have been exposed to some practical codes. In particular, I came across a “The Penn Treebank dataset”. There is a tool function to extract its data for training, and it uses yield to extract batches. Interested parties can search online for themselves, so I won’t go into details here.

Suddenly I found python’s yield keyword very interesting and useful, it’s like a built-in observer pattern implementation base.

I thought I’d give it a try myself and explain the use of yield in depth.
This notebook of mine is an example of how to use this keyword to provide batch data for machine learning asynchronously.

--

--

TeeTracker
TeeTracker

No responses yet