Multidimensional counting grids: Inferring word order from disordered bags of words