Take a look in the War Academy, at articles:
http://www.civfanatics.com/civ4/strategy/city_specialization.php
and
http://www.civfanatics.com/civ4/strategy/specialization.php
for the functions of specialized cities.
In terms of deciding how to specialize a city, well, this is something you really should do before you found it. Look at the terrain surrounding potential city sites. Lots of hills, copper/iron/horses, and just enough food to work those tiles -> production city. Lots of flatland, especially riverside grassland or flood plains -> commerce city (either via cottaging, or farming and running specialists). Several food resources, capable of running high food surplus at low population (often true of captured capitals) -> excellent GP farm.
Place the appropriate tile improvements, and build the appropriate national wonders, and you've got city specialization. A lot of times you'll have a hybrid city rather than a fully specialized one -- this is fine. But if you can't tell how your cities are specialized by just looking at the domestic advisor scrren, you're not doing it well enough. Some examples from a recent game:
Production-biased Bangalore:

Bangalore would ultimately receive the ironworks national wonder, and run 5 Angor Wat-boosted Priest specialists.
The science city and GP farm -- a cool synergy -- Bombay:

Bombay eventually ran over 10 scientist specialists before I had to switch out of Caste System to Emancipation. All tiles were farmed post-Biology, including the Iron.
I'm rather new to the game, but I know that these are by no means definitive examples of specialization -- there was one game I played where my production city had only one commerce produced from a worked tile -- the city center (all other commerce came from trade routes). That's sort of the ideal. Also, the cottage commerce city is often an easier starting point than the specialist commerce city. But I thought I'd show my examples from this game, which was my first win on Monarch, and my first strong usage of the specialist economy, because it shows somewhat how specialists can also determine the orientation of a city.