Packages

class SentenceDetectorSaTModel extends AnnotatorModel[SentenceDetectorSaTModel] with HasBatchedAnnotate[SentenceDetectorSaTModel] with WriteOnnxModel with WriteSentencePieceModel with HasEngine

Spark NLP sentence detection annotator based on the wtpsplit / SaT transformer models.

Supports segment-any-text/sat-12l-sm and segment-any-text/sat-12l (and any other SaT model exported as ONNX with an XLM-R SentencePiece tokenizer).

Example

import com.johnsnowlabs.nlp.base.DocumentAssembler
import com.johnsnowlabs.nlp.annotators.sbd.sat.SentenceDetectorSaTModel
import org.apache.spark.ml.Pipeline

val documentAssembler = new DocumentAssembler()
  .setInputCol("text")
  .setOutputCol("document")

val satModel = SentenceDetectorSaTModel
  .loadSavedModel("/path/to/sat-12l-sm", spark)
  .setInputCols("document")
  .setOutputCol("sentence")
  .setThreshold(0.25f)

val pipeline = new Pipeline().setStages(Array(documentAssembler, satModel))
val result   = pipeline.fit(data).transform(data)
result.selectExpr("explode(sentence.result)").show(false)
Ordering
  1. Grouped
  2. Alphabetic
  3. By Inheritance
Inherited
  1. SentenceDetectorSaTModel
  2. HasEngine
  3. WriteSentencePieceModel
  4. WriteOnnxModel
  5. HasBatchedAnnotate
  6. AnnotatorModel
  7. CanBeLazy
  8. RawAnnotator
  9. HasOutputAnnotationCol
  10. HasInputAnnotationCols
  11. HasOutputAnnotatorType
  12. ParamsAndFeaturesWritable
  13. HasFeatures
  14. DefaultParamsWritable
  15. MLWritable
  16. Model
  17. Transformer
  18. PipelineStage
  19. Logging
  20. Params
  21. Serializable
  22. Serializable
  23. Identifiable
  24. AnyRef
  25. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new SentenceDetectorSaTModel()
  2. new SentenceDetectorSaTModel(uid: String)

    uid

    Required UID for Spark ML serialization.

Type Members

  1. type AnnotationContent = Seq[Row]

    internal types to show Rows as a relevant StructType Should be deleted once Spark releases UserDefinedTypes to @developerAPI

    internal types to show Rows as a relevant StructType Should be deleted once Spark releases UserDefinedTypes to @developerAPI

    Attributes
    protected
    Definition Classes
    AnnotatorModel
  2. type AnnotatorType = String
    Definition Classes
    HasOutputAnnotatorType

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def $[T](param: Param[T]): T
    Attributes
    protected
    Definition Classes
    Params
  4. def $$[T](feature: StructFeature[T]): T
    Attributes
    protected
    Definition Classes
    HasFeatures
  5. def $$[K, V](feature: MapFeature[K, V]): Map[K, V]
    Attributes
    protected
    Definition Classes
    HasFeatures
  6. def $$[T](feature: SetFeature[T]): Set[T]
    Attributes
    protected
    Definition Classes
    HasFeatures
  7. def $$[T](feature: ArrayFeature[T]): Array[T]
    Attributes
    protected
    Definition Classes
    HasFeatures
  8. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  9. def _transform(dataset: Dataset[_], recursivePipeline: Option[PipelineModel]): DataFrame
    Attributes
    protected
    Definition Classes
    AnnotatorModel
  10. def afterAnnotate(dataset: DataFrame): DataFrame

    When explodeSentences is true, explode the output column so each sentence annotation lands on its own Dataset row.

    When explodeSentences is true, explode the output column so each sentence annotation lands on its own Dataset row. Mirrors SentenceDetectorDLModel.afterAnnotate.

    Attributes
    protected
    Definition Classes
    SentenceDetectorSaTModel → AnnotatorModel
  11. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  12. def batchAnnotate(batchedAnnotations: Seq[Array[Annotation]]): Seq[Seq[Annotation]]

    takes a document and annotations and produces new annotations of this annotator's annotation type

    takes a document and annotations and produces new annotations of this annotator's annotation type

    batchedAnnotations

    Annotations in batches that correspond to inputAnnotationCols generated by previous annotators if any

    returns

    any number of annotations processed for every batch of input annotations. Not necessary one to one relationship IMPORTANT: !MUST! return sequences of equal lengths !! IMPORTANT: !MUST! return sentences that belong to the same original row !! (challenging)

    Definition Classes
    SentenceDetectorSaTModel → HasBatchedAnnotate
  13. def batchProcess(rows: Iterator[_]): Iterator[Row]
    Definition Classes
    HasBatchedAnnotate
  14. val batchSize: IntParam

    Size of every batch (Default depends on model).

    Size of every batch (Default depends on model).

    Definition Classes
    HasBatchedAnnotate
  15. def beforeAnnotate(dataset: Dataset[_]): Dataset[_]
    Attributes
    protected
    Definition Classes
    AnnotatorModel
  16. val blockSize: IntParam

    Number of real sub-word tokens per ONNX window (Default: 510).

    Number of real sub-word tokens per ONNX window (Default: 510).

    XLM-R has a 512-position limit. Every window adds <s> + tokens + </s>, so the maximum number of real tokens per window is 510.

  17. final def checkSchema(schema: StructType, inputAnnotatorType: String): Boolean
    Attributes
    protected
    Definition Classes
    HasInputAnnotationCols
  18. final def clear(param: Param[_]): SentenceDetectorSaTModel.this.type
    Definition Classes
    Params
  19. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  20. def copy(extra: ParamMap): SentenceDetectorSaTModel

    requirement for annotators copies

    requirement for annotators copies

    Definition Classes
    RawAnnotator → Model → Transformer → PipelineStage → Params
  21. def copyValues[T <: Params](to: T, extra: ParamMap): T
    Attributes
    protected
    Definition Classes
    Params
  22. final def defaultCopy[T <: Params](extra: ParamMap): T
    Attributes
    protected
    Definition Classes
    Params
  23. val engine: Param[String]

    This param is set internally once via loadSavedModel.

    This param is set internally once via loadSavedModel. That's why there is no setter

    Definition Classes
    HasEngine
  24. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  25. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  26. def explainParam(param: Param[_]): String
    Definition Classes
    Params
  27. def explainParams(): String
    Definition Classes
    Params
  28. val explodeSentences: BooleanParam

    Whether to split each detected sentence into its own Dataset row (Default: true).

  29. final val extraInputCols: StringArrayParam
    Attributes
    protected
    Definition Classes
    HasInputAnnotationCols
  30. def extraValidate(structType: StructType): Boolean
    Attributes
    protected
    Definition Classes
    RawAnnotator
  31. def extraValidateMsg: String

    Override for additional custom schema checks

    Override for additional custom schema checks

    Attributes
    protected
    Definition Classes
    RawAnnotator
  32. final def extractParamMap(): ParamMap
    Definition Classes
    Params
  33. final def extractParamMap(extra: ParamMap): ParamMap
    Definition Classes
    Params
  34. val features: ArrayBuffer[Feature[_, _, _]]
    Definition Classes
    HasFeatures
  35. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  36. def get[T](feature: StructFeature[T]): Option[T]
    Attributes
    protected
    Definition Classes
    HasFeatures
  37. def get[K, V](feature: MapFeature[K, V]): Option[Map[K, V]]
    Attributes
    protected
    Definition Classes
    HasFeatures
  38. def get[T](feature: SetFeature[T]): Option[Set[T]]
    Attributes
    protected
    Definition Classes
    HasFeatures
  39. def get[T](feature: ArrayFeature[T]): Option[Array[T]]
    Attributes
    protected
    Definition Classes
    HasFeatures
  40. final def get[T](param: Param[T]): Option[T]
    Definition Classes
    Params
  41. def getBatchSize: Int

    Size of every batch.

    Size of every batch.

    Definition Classes
    HasBatchedAnnotate
  42. def getBlockSize: Int

  43. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  44. final def getDefault[T](param: Param[T]): Option[T]
    Definition Classes
    Params
  45. def getEngine: String

    Definition Classes
    HasEngine
  46. def getExplodeSentences: Boolean

  47. def getInputCols: Array[String]

    returns

    input annotations columns currently used

    Definition Classes
    HasInputAnnotationCols
  48. def getLazyAnnotator: Boolean
    Definition Classes
    CanBeLazy
  49. def getMaxSentenceLength: Int

  50. def getMinSentenceLength: Int

  51. def getModelIfNotSet: SaT
  52. final def getOrDefault[T](param: Param[T]): T
    Definition Classes
    Params
  53. final def getOutputCol: String

    Gets annotation column name going to generate

    Gets annotation column name going to generate

    Definition Classes
    HasOutputAnnotationCol
  54. def getParam(paramName: String): Param[Any]
    Definition Classes
    Params
  55. def getSatBatchSize: Int

  56. def getStride: Int

  57. def getThreshold: Float

  58. def getTrimWhitespace: Boolean

  59. def getWeighting: String

  60. final def hasDefault[T](param: Param[T]): Boolean
    Definition Classes
    Params
  61. def hasParam(paramName: String): Boolean
    Definition Classes
    Params
  62. def hasParent: Boolean
    Definition Classes
    Model
  63. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  64. def initializeLogIfNecessary(isInterpreter: Boolean, silent: Boolean): Boolean
    Attributes
    protected
    Definition Classes
    Logging
  65. def initializeLogIfNecessary(isInterpreter: Boolean): Unit
    Attributes
    protected
    Definition Classes
    Logging
  66. val inputAnnotatorTypes: Array[String]

    Annotator reference id.

    Annotator reference id. Used to identify elements in metadata or to refer to this annotator type

    Definition Classes
    SentenceDetectorSaTModel → HasInputAnnotationCols
  67. final val inputCols: StringArrayParam

    columns that contain annotations necessary to run this annotator AnnotatorType is used both as input and output columns if not specified

    columns that contain annotations necessary to run this annotator AnnotatorType is used both as input and output columns if not specified

    Attributes
    protected
    Definition Classes
    HasInputAnnotationCols
  68. final def isDefined(param: Param[_]): Boolean
    Definition Classes
    Params
  69. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  70. final def isSet(param: Param[_]): Boolean
    Definition Classes
    Params
  71. def isTraceEnabled(): Boolean
    Attributes
    protected
    Definition Classes
    Logging
  72. val lazyAnnotator: BooleanParam
    Definition Classes
    CanBeLazy
  73. def log: Logger
    Attributes
    protected
    Definition Classes
    Logging
  74. def logDebug(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  75. def logDebug(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  76. def logError(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  77. def logError(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  78. def logInfo(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  79. def logInfo(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  80. def logName: String
    Attributes
    protected
    Definition Classes
    Logging
  81. def logTrace(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  82. def logTrace(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  83. def logWarning(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  84. def logWarning(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  85. val maxSentenceLength: IntParam

    Maximum sentence length in characters (Default: 0 = no maximum).

    Maximum sentence length in characters (Default: 0 = no maximum).

    See minSentenceLength: setting either bound activates length-constrained segmentation and disables the threshold.

  86. val minSentenceLength: IntParam

    Minimum sentence length in characters (Default: 0 = no minimum).

    Minimum sentence length in characters (Default: 0 = no minimum).

    When minSentenceLength or maxSentenceLength is > 0, the model switches to length-constrained (Viterbi) segmentation and the threshold is ignored: it instead finds the globally highest-probability set of boundaries such that every sentence falls within [minSentenceLength, maxSentenceLength] characters.

  87. def msgHelper(schema: StructType): String
    Attributes
    protected
    Definition Classes
    HasInputAnnotationCols
  88. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  89. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  90. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  91. def onWrite(path: String, spark: SparkSession): Unit
  92. val optionalInputAnnotatorTypes: Array[String]
    Definition Classes
    HasInputAnnotationCols
  93. val outputAnnotatorType: String
  94. final val outputCol: Param[String]
    Attributes
    protected
    Definition Classes
    HasOutputAnnotationCol
  95. lazy val params: Array[Param[_]]
    Definition Classes
    Params
  96. var parent: Estimator[SentenceDetectorSaTModel]
    Definition Classes
    Model
  97. val satBatchSize: IntParam

    Number of windows to batch together in one ONNX call (Default: 8).

  98. def save(path: String): Unit
    Definition Classes
    MLWritable
    Annotations
    @Since( "1.6.0" ) @throws( ... )
  99. def set[T](feature: StructFeature[T], value: T): SentenceDetectorSaTModel.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  100. def set[K, V](feature: MapFeature[K, V], value: Map[K, V]): SentenceDetectorSaTModel.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  101. def set[T](feature: SetFeature[T], value: Set[T]): SentenceDetectorSaTModel.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  102. def set[T](feature: ArrayFeature[T], value: Array[T]): SentenceDetectorSaTModel.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  103. final def set(paramPair: ParamPair[_]): SentenceDetectorSaTModel.this.type
    Attributes
    protected
    Definition Classes
    Params
  104. final def set(param: String, value: Any): SentenceDetectorSaTModel.this.type
    Attributes
    protected
    Definition Classes
    Params
  105. final def set[T](param: Param[T], value: T): SentenceDetectorSaTModel.this.type
    Definition Classes
    Params
  106. def setBatchSize(size: Int): SentenceDetectorSaTModel.this.type

    Size of every batch.

    Size of every batch.

    Definition Classes
    HasBatchedAnnotate
  107. def setBlockSize(value: Int): SentenceDetectorSaTModel.this.type

  108. def setDefault[T](feature: StructFeature[T], value: () ⇒ T): SentenceDetectorSaTModel.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  109. def setDefault[K, V](feature: MapFeature[K, V], value: () ⇒ Map[K, V]): SentenceDetectorSaTModel.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  110. def setDefault[T](feature: SetFeature[T], value: () ⇒ Set[T]): SentenceDetectorSaTModel.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  111. def setDefault[T](feature: ArrayFeature[T], value: () ⇒ Array[T]): SentenceDetectorSaTModel.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  112. final def setDefault(paramPairs: ParamPair[_]*): SentenceDetectorSaTModel.this.type
    Attributes
    protected
    Definition Classes
    Params
  113. final def setDefault[T](param: Param[T], value: T): SentenceDetectorSaTModel.this.type
    Attributes
    protected[org.apache.spark.ml]
    Definition Classes
    Params
  114. def setExplodeSentences(value: Boolean): SentenceDetectorSaTModel.this.type

  115. def setExtraInputCols(value: Array[String]): SentenceDetectorSaTModel.this.type
    Definition Classes
    HasInputAnnotationCols
  116. final def setInputCols(value: String*): SentenceDetectorSaTModel.this.type
    Definition Classes
    HasInputAnnotationCols
  117. def setInputCols(value: Array[String]): SentenceDetectorSaTModel.this.type

    Overrides required annotators column if different than default

    Overrides required annotators column if different than default

    Definition Classes
    HasInputAnnotationCols
  118. def setLazyAnnotator(value: Boolean): SentenceDetectorSaTModel.this.type
    Definition Classes
    CanBeLazy
  119. def setMaxSentenceLength(value: Int): SentenceDetectorSaTModel.this.type

  120. def setMinSentenceLength(value: Int): SentenceDetectorSaTModel.this.type

  121. def setModelIfNotSet(spark: SparkSession, onnxWrapper: OnnxWrapper, spp: SentencePieceWrapper): SentenceDetectorSaTModel.this.type

    Set the fully-initialised SaT inference object.

    Set the fully-initialised SaT inference object. Called by loadSavedModel and by the Spark ML deserialization reader.

  122. final def setOutputCol(value: String): SentenceDetectorSaTModel.this.type

    Overrides annotation column name when transforming

    Overrides annotation column name when transforming

    Definition Classes
    HasOutputAnnotationCol
  123. def setParent(parent: Estimator[SentenceDetectorSaTModel]): SentenceDetectorSaTModel
    Definition Classes
    Model
  124. def setSatBatchSize(value: Int): SentenceDetectorSaTModel.this.type

  125. def setStride(value: Int): SentenceDetectorSaTModel.this.type

  126. def setThreshold(value: Float): SentenceDetectorSaTModel.this.type

  127. def setTrimWhitespace(value: Boolean): SentenceDetectorSaTModel.this.type

  128. def setWeighting(value: String): SentenceDetectorSaTModel.this.type

  129. val stride: IntParam

    Number of tokens to advance between consecutive windows (Default: 256).

    Number of tokens to advance between consecutive windows (Default: 256).

    A smaller stride means more overlap and smoother boundary probabilities.

  130. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  131. val threshold: FloatParam

    Boundary probability threshold (Default: 0.25 for sat-12l-sm).

    Boundary probability threshold (Default: 0.25 for sat-12l-sm).

    A token boundary is emitted when sigmoid(logit) >= threshold. Typical values:

    • sat-12l-sm -> 0.25
    • sat-12l -> 0.025
    • LoRA merged -> 0.5
  132. def toString(): String
    Definition Classes
    Identifiable → AnyRef → Any
  133. final def transform(dataset: Dataset[_]): DataFrame

    Given requirements are met, this applies ML transformation within a Pipeline or stand-alone Output annotation will be generated as a new column, previous annotations are still available separately metadata is built at schema level to record annotations structural information outside its content

    Given requirements are met, this applies ML transformation within a Pipeline or stand-alone Output annotation will be generated as a new column, previous annotations are still available separately metadata is built at schema level to record annotations structural information outside its content

    dataset

    Dataset[Row]

    Definition Classes
    AnnotatorModel → Transformer
  134. def transform(dataset: Dataset[_], paramMap: ParamMap): DataFrame
    Definition Classes
    Transformer
    Annotations
    @Since( "2.0.0" )
  135. def transform(dataset: Dataset[_], firstParamPair: ParamPair[_], otherParamPairs: ParamPair[_]*): DataFrame
    Definition Classes
    Transformer
    Annotations
    @Since( "2.0.0" ) @varargs()
  136. final def transformSchema(schema: StructType): StructType

    requirement for pipeline transformation validation.

    requirement for pipeline transformation validation. It is called on fit()

    Definition Classes
    RawAnnotator → PipelineStage
  137. def transformSchema(schema: StructType, logging: Boolean): StructType
    Attributes
    protected
    Definition Classes
    PipelineStage
    Annotations
    @DeveloperApi()
  138. val trimWhitespace: BooleanParam

    Strip leading/trailing whitespace from each detected sentence (Default: true).

  139. val uid: String
    Definition Classes
    SentenceDetectorSaTModel → Identifiable
  140. def validate(schema: StructType): Boolean

    takes a Dataset and checks to see if all the required annotation types are present.

    takes a Dataset and checks to see if all the required annotation types are present.

    schema

    to be validated

    returns

    True if all the required types are present, else false

    Attributes
    protected
    Definition Classes
    RawAnnotator
  141. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  142. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  143. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  144. val weighting: Param[String]

    Window-overlap weighting strategy (Default: "hat").

    Window-overlap weighting strategy (Default: "hat").

    Supported values:

    • "hat" - centre tokens get higher weight than edge tokens.
    • "uniform" - every token in a window has equal weight 1.0.
  145. def wrapColumnMetadata(col: Column): Column
    Attributes
    protected
    Definition Classes
    RawAnnotator
  146. def write: MLWriter
    Definition Classes
    ParamsAndFeaturesWritable → DefaultParamsWritable → MLWritable
  147. def writeOnnxModel(path: String, spark: SparkSession, onnxWrapper: OnnxWrapper, suffix: String, fileName: String): Unit
    Definition Classes
    WriteOnnxModel
  148. def writeOnnxModels(path: String, spark: SparkSession, onnxWrappersWithNames: Seq[(OnnxWrapper, String)], suffix: String): Unit
    Definition Classes
    WriteOnnxModel
  149. def writeSentencePieceModel(path: String, spark: SparkSession, spp: SentencePieceWrapper, suffix: String, filename: String): Unit
    Definition Classes
    WriteSentencePieceModel

Inherited from HasEngine

Inherited from WriteSentencePieceModel

Inherited from WriteOnnxModel

Inherited from CanBeLazy

Inherited from HasOutputAnnotationCol

Inherited from HasInputAnnotationCols

Inherited from HasOutputAnnotatorType

Inherited from ParamsAndFeaturesWritable

Inherited from HasFeatures

Inherited from DefaultParamsWritable

Inherited from MLWritable

Inherited from Model[SentenceDetectorSaTModel]

Inherited from Transformer

Inherited from PipelineStage

Inherited from Logging

Inherited from Params

Inherited from Serializable

Inherited from Serializable

Inherited from Identifiable

Inherited from AnyRef

Inherited from Any

Parameters

Parameter setters

Parameter getters

Ungrouped