build transition graph with frequency as weight