Modelling cultural shift: application to language decline and extinction