We present a novel method for predicting the secondary structure of a protein from its amino acid sequence. Most existing methods predict each position in turn based on a local window of residues, sliding this window along the length of the sequence. In contrast, we formulate secondary structure prediction as a general Bayesian inference problem. We present a parameterization of protein sequence/structure relationships in terms of structural segments, and produce predictions of secondary structure by optimal segmentation of the input sequence. In contrast to existing methods, our approach is model-based, permitting development of explicit probabilistic models for alpha-helices, beta-strands, and other classes of secondary structure. Our model allows direct incorporation of experimentally and empirically observed aspects of protein structure such as helical capping signals, side chain correlations, and segment length distributions. We develop a model which is Markovian in the segments themselves, permitting efficient exact calculation of the posterior probability distribution over all possible segmentations of the sequence using dynamic programming. Final predictions are made by marginalization and maximization over this posterior distribution. We apply this model to a database of 452 non-homologous structures, achieving accuracies as high as most currently available methods along with precise estimates of prediction uncertainty. We conclude by discussing an extension of this framework to model non-local interactions in protein structures, providing a clear direction for future improvements in secondary structure prediction accuracy.