Simultaneous Learning of Trees and Representations for Extreme Classification and Density Estimation