If you don't count artificial methods (like preventing player to build specific buildings or limit the amount of building that can be built by much higher cost), the way to naturally encourage players to specialize their cities is by adding bonuses that can stack higher than the total sums. There's no point in specializing if getting 1 science in science focused city is the same as getting 1 science in any other cities.
This bonus, however, can be either be or not be the same as the city's specialization (ex you can have city that gives a bonus of X science based on Y amount of science it's generating, or give bonus of gold or culture or food or production or all of them based on the current amount of science it's generating). Both cases would encourage players to focus all source of science into 1 city.
The choice of having either this yield or that yield isn't really specialization if there's no underlaying mechanic above in the first place, as there's no different in the total sums (assuming all choices are balanced)