Lesson 9 notes

If you have notes for lesson 9, please add them here! Many thanks for the great contributions so far - they’re really appreciated.

2 Likes

A Note on Software Engineering

In the course Deep Learning From the Foundations, there is much to learn about software engineering from the Fastai team.

Software engineering – in a nutshell – is the art of writing and testing efficient, understandable, reliable, reusable, and maintainable code.

Here are a few simple rules to help set you on the road to good software engineering practice.

  1. Use descriptive variable names. For example, instead of variables named n and m, use informative names such as n_rows and n_columns; instead of nh, use n_hidden, instead of c, use n_out.

Never use single character names for important variables.
Why? Suppose you have a variable named n, and you find that for some good reason, you need to rename n to n_iter. Imagine trying to do a ‘find and replace’ on n, one of the most commonly used characters in the English language?

  1. Pass numerical values into functions as keyword arguments.

For example, consider the following line of code:

s = Sampler(small_ds,3,False)

This code is not efficient for the reader, who will likely have no idea of what the values 3 and False represent. To find out, they’ll have to spend extra time examining the code for the Sampler object.

On the other hand, consider an alternative form:

s = Sampler(small_ds,batch_size=3,shuffle=False)

Calling the inputs as keyword arguments gives the reader a good idea of how these values control the behavior of Sampler.

  1. Document your code as you write. For each small block of code, provide a clear explanation of its function. Although it does slow you down a bit, documentation that records how your code was built and the decisions that went into its construction will be invaluable to you or anyone else who wants to understand, use, refactor, or repurpose your code at a later time.

Following rules such as these is well worth your while – especially when you come back to your code after a hiatus and try to remember what you did, or when you want to share your code with others.

Here are some notes on my blog I’ve made while working through this Lesson: https://jimypbr.github.io/2020/02/fast-ai-lesson-9-notes-training-in-depth
:slight_smile:

2 Likes

Great notes @jimypbr! Note that Runner is removed/refactored in lesson 1 IIRC, and replaced with just Learner.

1 Like