snorkel-team / snorkel

A system for quickly generating training data with weak supervision
https://snorkel.org
Apache License 2.0
5.81k stars 857 forks source link

labeling_function as a method on class #1721

Closed SomewhereInTheVastUniverse closed 1 year ago

SomewhereInTheVastUniverse commented 1 year ago

Hi i want to know the method labeling function decorator with class tutorial and guide have only function based example

i want to use like following example.

class LabelingFunctions: @labeling_function() def something(self, x): return 1

but in this case, it occur a error like 'TypeError: LabelingFunctions.something() missing 1 required positional argument: 'x' because it has 'self' as a parameter on method. how can i use class based labeling

thank you

vkrishnamurthy11 commented 1 year ago

@SomewhereInTheVastUniverse

Can you modify your example like the following:

@labeling_function()
def something(x):
    return 1

If you look at the documentation in https://github.com/snorkel-team/snorkel/blob/61c60e8496a057057c663912bafb0614ed2fc98a/snorkel/labeling/lf/core.py#L84, you can see that when defining the function, you only pass in 'x' as the argument and not self.

SomewhereInTheVastUniverse commented 1 year ago

@SomewhereInTheVastUniverse

Can you modify your example like the following:

@labeling_function()
def something(x):
    return 1

If you look at the documentation in

https://github.com/snorkel-team/snorkel/blob/61c60e8496a057057c663912bafb0614ed2fc98a/snorkel/labeling/lf/core.py#L84

, you can see that when defining the function, you only pass in 'x' as the argument and not self.

okay then, i can use only function case. thank you.