Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPARKNLP-869 Adding threshold to properties for python module #13890

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions python/sparknlp/common/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ class HasClassifierActivationProperties:
"Whether to calculate logits via Multiclass(softmax) or Multilabel(sigmoid). Default is False i.e. Multiclass",
typeConverter=TypeConverters.toBoolean)

threshold = Param(Params._dummy(),
"threshold",
"Choose the threshold to determine which logits are considered to be positive or negative",
typeConverter=TypeConverters.toFloat)

def setActivation(self, value):
"""Sets whether to calculate logits via Softmax or Sigmoid. Default is Softmax

Expand Down Expand Up @@ -126,6 +131,22 @@ def getMultilabel(self):
"""
return self.getOrDefault(self.multilabel)

def setThreshold(self, value):
"""Set the threshold to determine which logits are considered to be positive or negative.
(Default: `0.5`). The value should be between 0.0 and 1.0. Changing the threshold value
will affect the resulting labels and can be used to adjust the balance between precision and
recall in the classification process.

Parameters
----------
value : float
The threshold to determine which logits are considered to be positive or negative.
(Default: `0.5`). The value should be between 0.0 and 1.0. Changing the threshold value
will affect the resulting labels and can be used to adjust the balance between precision and
recall in the classification process.
"""
return self._set(threshold=value)


class HasEmbeddingsProperties(Params):
dimension = Param(Params._dummy(),
Expand Down