Refactoring a Machine Learning Model
This blog post is a tutorial that will take you from a naive implementation of a multilayer perceptron in PyTorch to an enlightened implementation that simultaneously leverages the power of PyTorch, Python's builtins, and some powerful third party Python packages. This tutorial isn't really about the theory nor application of machine learning models - it's just about the best ways to implement them. I'm also going to commit the sin of omitting docstrings and a lot of type annotations, since most of the MLP should be pretty obvious. Let's start with a naive implementation, that reflects some old habits from C or Java programming: MLP1 uses the dreaded range(len(...)) pattern, which can almost always be replaced with direct iteration. However, in this case, it uses the index to get the next element with it.
Feb-6-2022, 16:38:28 GMT
- Genre:
- Technology: