Skip to content

Label dependent features #216

Description

@daniel-guggenheim

Hello,

I am trying to implement a linear-chain CRF with pystruct and I encountered a problem with the way of defining features, even with more complex models such as EdgeFeatureGraphCRF. In general literature, I have observed the feature function in linear-chain CRF defined as : f(i, y, y-1, x), where i = indice of the current position in the chain, y = label at position i, y-1 = label at position i-1, x = input at position i.

In pystruct, I don't know how to make features that are dependent on the label. Unary features and pairwise features seem they need to be defined in an "absolute" way, without any dependency on the selected label. Whereas in my case, I will have different features for each tuple of (i, y, y-1, x). Basically, the observation for a particular node varies for each of the possible label.

For example:
Unary features:
f(i=0, x=1, y=5) = [1,2]
f(i=0, x=1, y=10) = [3,4]
...

Pairwise features:
f(i=2, x=1, y=5, y-1=10) = [1,2,3]
f(i=2, x=1, y=15, y-1=20) = [4,5,6]
...

In this example, you can note that for a specific index and x, the features change depending on the label. In this example, x could be arbitrary, y could be ranging from 0 to 20 but there would only be 2 + 3 = 5 features, so 5 weights to learn.

What could I do to solve this problem? Can I subclass for example the class EdgeFeatureGraphCRF and modify the function joint_feature?

Thank you very much for your help. Let me know if anything was not clear, or if I did not understand something correctly.

Daniel

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions