THis problem is usually caused by a bad sensor. Either the transmission input shaft or output shaft may be bad causing your problem. In my experience, 9 times out of 10 one one or both of these sensors will fix this problem. If not, it will be an internal transmission failure.
I would start by ohming both of these sensors out. If they ohm out above 800 ohms, replace the sensor.