Working code to extract topic hierarchy