I am training a CRF classifier to classify document rows as a heading (1st level), heading (2nd level) or simple text.

I am using Conditional Random Fields for their ability to account sequential aspects.

Reading some tutorials, I noticed that usually, among the features, there are some features related to the preceeding or following token.

    if i > 0:
        word1 = sent[i-1][0]
        postag1 = sent[i-1][1]
            '-1:word.lower()': word1.lower(),
            '-1:word.istitle()': word1.istitle(),
            '-1:word.isupper()': word1.isupper(),
            '-1:postag': postag1,
            '-1:postag[:2]': postag1[:2],
        features['BOS'] = True

I wonder if the sequential aspect is learned from these features or is connate in CRF. In other words, do we need these features related to other tokens?


In other words, do we need these features related to other tokens?

No, these features are not needed. But they are often useful: CRFs handle sequential dependencies between the labels, however it's up to you to provide the relevant features, in particular some to represent the dependencies between (certain) features if needed.

With text, this relation between consecutive tokens is very often a relevant indicator. I'd suggest that you try both version, without and with this feature, and you're likely to observe a higher performance in the latter case. In my experience it's often worth trying different combinations, including trying features which go two or three steps back.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.