A [comment](https://news.ycombinator.com/item?id=7214408) left by the author of the summarization algorithm I used has explained how to reduce the loops when ranking words.