modified the code to calculate the bag of words for different bins