Skip to content

Commit

Permalink
SPARKNLP-869 Adding threshold to properties for python module (#13890)
Browse files Browse the repository at this point in the history
  • Loading branch information
danilojsl authored Jul 18, 2023
1 parent 20d9f37 commit 4620feb
Showing 1 changed file with 21 additions and 0 deletions.
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

0 comments on commit 4620feb

Please sign in to comment.