Generating functions...need some help here

A textbook defines the generating function f of a random variable X as:

$\displaystyle f(\theta) = E[\theta^X] = \sum_{k} \theta^kP(X=k)$

Can anybody please explain that to me?

So far I know:

Generating function of random variable X can also be defined as:

$\displaystyle X(\theta) = x_0 + x_1 \theta + x_2 \theta^2 + x_3 \theta^3 + ...$

So if we do differentiation:

$\displaystyle X'(\theta) = x_1 + 2x_2 \theta + 3x_3 \theta^2 + ... = \sum_{k} kx_k \theta^{k-1}$

Taking $\displaystyle \theta = 1$,

$\displaystyle X'(1) = \sum_{k} kx_k = E[X]$

How is this related to the very first equation?

Any help is much appreciated.