Pyramidal neurons receive input from thousands of synapses spread throughout dendritic branches with diverse integration properties. The majority of these synapses have negligible impact on the soma. It is therefore a mystery how pyramidal neurons integrate the input from all these synapses, and what kind of network behavior this enables in cortical tissue. It has been previously proposed that active dendrites enable neurons to recognize multiple independent patterns. In this paper we extend this idea. We propose a model where patterns detected on active basal dendrites act as predictions by slightly depolarizing the soma without generating an action potential. A single neuron can then predict its activation in hundreds of independent contexts. We show how a network of pyramidal neurons combined with fast local inhibition and branch specific plasticity mechanisms can learn complex time-based sequences and form precise predictive codes. The algorithm scales well, learns continuously and demonstrates excellent performance on real-world data. We then extend the idea to handle sensorimotor sequences. Sensory inputs can change due to external factors or they can change due to our own behavior. Interpreting behavior-generated changes requires knowledge of how the body is moving, whereas interpreting externally-generated changes relies solely on the temporal sequence of input patterns. We show that our predictive network mechanism can learn both pure external temporal sequences as well as sensorimotor sequences. When the contextual input includes information derived from efference motor copies, the cells learn sensorimotor sequences. If the contextual input consists of nearby cellular activity, the cells learn temporal sequences. Through simulation we show that a network containing both types of contextual input can automatically separate and learn sensory sequences containing a blended mixture of both types of input patterns. We discuss the relationship to experimental data and testable predictions made by the model. Given the prevalence of pyramidal neurons throughout the neocortex and the importance of prediction in inference and behavior, we propose that this form of sequence memory may be a universal property of neocortical tissue.