Learning words in groups: fusion algebras, tensor ranks and grokking