Modeling echo chambers and polarization dynamics in social networks