So I'm working on implementing a recipe that will periodically fire off retraining batch jobs and reload the trained model in a modified textcat.teach recipe.
When I detect the presence of a newly trained model I want to create a new sorter and feed it with newly scored examples and then yield those to the UI. I'd like to use the
prefer_uncertain sorter and yield its output from my custom sorter.
roughly something like this:
class ModelSwappingIterator: ... def __call__(self, stream, batch_size=None): sorted_stream = prefer_uncertain(self.model(stream)) while True: if self.new_model_exists(): self.swap_model() # newly trained self.model sorted_stream = prefer_uncertain(self.model(stream)) yield next(sorted_stream)
Whenever I try something like this I am told that ExpMovingAverage is not an iterator. If I try to call it instead I'm told that it's not callable.
Is there any way I can manually pull sorted examples out of the sorters?