CRF implementation ported from Breeze.