This is nice. One interesting choice is the decision to compute the number of observed words, N, as the default value of an optional argument, thereby ensuring that it is only computed once, while still limiting its scope to the function in which it is needed. Perhaps this is a common pattern but it's one I haven't stumbled across before.
The short circuiting `or` chain is also pleasantly virtuosic. Sometimes a little flashiness is tolerable when it works this well!