c

com.johnsnowlabs.legal.sequence_classification

LegalClassifierDLApproach

class LegalClassifierDLApproach extends ClassifierDLApproach

MedicalBertForSequenceClassification can load Bert Models with sequence classification/regression head on top (a linear layer on top of the pooled output) e.g. for multi-class document classification tasks.

Pretrained models can be loaded with pretrained of the companion object:

val sequenceClassifier = MedicalBertForSequenceClassification.pretrained()
  .setInputCols("token", "document")
  .setOutputCol("label")

The default model is "bert_sequence_classifier_ade", if no name is provided.

For available pretrained models please see the Models Hub.

Models from the HuggingFace 🤗 Transformers library are also compatible with Spark NLP 🚀. The Spark NLP Workshop example shows how to import them https://github.com/JohnSnowLabs/spark-nlp/discussions/5669.

Example

import spark.implicits._
import com.johnsnowlabs.nlp.base._
import com.johnsnowlabs.nlp.annotator._
import org.apache.spark.ml.Pipeline

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

val tokenizer = new Tokenizer()
  .setInputCols("document")
  .setOutputCol("token")

val sequenceClassifier = MedicalBertForSequenceClassification.pretrained()
  .setInputCols("token", "document")
  .setOutputCol("label")
  .setCaseSensitive(true)

val pipeline = new Pipeline().setStages(Array(
  documentAssembler,
  tokenizer,
  sequenceClassifier
))

val data = Seq("John Lenon was born in London and lived in Paris. My name is Sarah and I live in London").toDF("text")
val result = pipeline.fit(data).transform(data)

result.select("label.result").show(false)
+--------------------+
|result              |
+--------------------+
|[True, False]       |
+--------------------+
See also

MedicalBertForSequenceClassification for sequnece-level classification

Annotators Main Page for a list of transformer based classifiers

Linear Supertypes
ClassifierDLApproach, ClassifierEncoder, EvaluationDLParams, ParamsAndFeaturesWritable, HasFeatures, AnnotatorApproach[ClassifierDLModel], CanBeLazy, DefaultParamsWritable, MLWritable, HasOutputAnnotatorType, HasOutputAnnotationCol, HasInputAnnotationCols, Estimator[ClassifierDLModel], PipelineStage, Logging, Params, Serializable, Serializable, Identifiable, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. LegalClassifierDLApproach
  2. ClassifierDLApproach
  3. ClassifierEncoder
  4. EvaluationDLParams
  5. ParamsAndFeaturesWritable
  6. HasFeatures
  7. AnnotatorApproach
  8. CanBeLazy
  9. DefaultParamsWritable
  10. MLWritable
  11. HasOutputAnnotatorType
  12. HasOutputAnnotationCol
  13. HasInputAnnotationCols
  14. Estimator
  15. PipelineStage
  16. Logging
  17. Params
  18. Serializable
  19. Serializable
  20. Identifiable
  21. AnyRef
  22. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new LegalClassifierDLApproach()

    Annotator reference id.

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

  2. new LegalClassifierDLApproach(uid: String)

    uid

    required uid for storing annotator to disk

Type Members

  1. 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 _fit(dataset: Dataset[_], recursiveStages: Option[PipelineModel]): ClassifierDLModel
    Attributes
    protected
    Definition Classes
    AnnotatorApproach
  10. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  11. val batchSize: IntParam
    Definition Classes
    ClassifierEncoder
  12. def beforeTraining(spark: SparkSession): Unit
    Definition Classes
    AnnotatorApproach
  13. def buildDatasetWithLabels(dataset: Dataset[_], inputCols: String): (DataFrame, Array[String])
    Attributes
    protected
    Definition Classes
    ClassifierEncoder
  14. final def checkSchema(schema: StructType, inputAnnotatorType: String): Boolean
    Attributes
    protected
    Definition Classes
    HasInputAnnotationCols
  15. final def clear(param: Param[_]): LegalClassifierDLApproach.this.type
    Definition Classes
    Params
  16. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  17. val configProtoBytes: IntArrayParam
    Definition Classes
    ClassifierEncoder
  18. final def copy(extra: ParamMap): Estimator[ClassifierDLModel]
    Definition Classes
    AnnotatorApproach → Estimator → PipelineStage → Params
  19. def copyValues[T <: Params](to: T, extra: ParamMap): T
    Attributes
    protected
    Definition Classes
    Params
  20. final def defaultCopy[T <: Params](extra: ParamMap): T
    Attributes
    protected
    Definition Classes
    Params
  21. val description: String
    Definition Classes
    ClassifierDLApproach → AnnotatorApproach
  22. val dropout: FloatParam
    Definition Classes
    ClassifierDLApproach
  23. val enableOutputLogs: BooleanParam
    Definition Classes
    EvaluationDLParams
  24. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  25. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  26. val evaluationLogExtended: BooleanParam
    Definition Classes
    EvaluationDLParams
  27. def explainParam(param: Param[_]): String
    Definition Classes
    Params
  28. def explainParams(): String
    Definition Classes
    Params
  29. def extractInputs(encoder: ClassifierDatasetEncoder, dataframe: DataFrame): (Array[Array[Float]], Array[String])
    Attributes
    protected
    Definition Classes
    ClassifierEncoder
  30. final def extractParamMap(): ParamMap
    Definition Classes
    Params
  31. final def extractParamMap(extra: ParamMap): ParamMap
    Definition Classes
    Params
  32. val features: ArrayBuffer[Feature[_, _, _]]
    Definition Classes
    HasFeatures
  33. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  34. final def fit(dataset: Dataset[_]): ClassifierDLModel
    Definition Classes
    AnnotatorApproach → Estimator
  35. def fit(dataset: Dataset[_], paramMaps: Seq[ParamMap]): Seq[ClassifierDLModel]
    Definition Classes
    Estimator
    Annotations
    @Since( "2.0.0" )
  36. def fit(dataset: Dataset[_], paramMap: ParamMap): ClassifierDLModel
    Definition Classes
    Estimator
    Annotations
    @Since( "2.0.0" )
  37. def fit(dataset: Dataset[_], firstParamPair: ParamPair[_], otherParamPairs: ParamPair[_]*): ClassifierDLModel
    Definition Classes
    Estimator
    Annotations
    @Since( "2.0.0" ) @varargs()
  38. def get[T](feature: StructFeature[T]): Option[T]
    Attributes
    protected
    Definition Classes
    HasFeatures
  39. def get[K, V](feature: MapFeature[K, V]): Option[Map[K, V]]
    Attributes
    protected
    Definition Classes
    HasFeatures
  40. def get[T](feature: SetFeature[T]): Option[Set[T]]
    Attributes
    protected
    Definition Classes
    HasFeatures
  41. def get[T](feature: ArrayFeature[T]): Option[Array[T]]
    Attributes
    protected
    Definition Classes
    HasFeatures
  42. final def get[T](param: Param[T]): Option[T]
    Definition Classes
    Params
  43. def getBatchSize: Int
    Definition Classes
    ClassifierEncoder
  44. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  45. def getConfigProtoBytes: Option[Array[Byte]]
    Definition Classes
    ClassifierEncoder
  46. final def getDefault[T](param: Param[T]): Option[T]
    Definition Classes
    Params
  47. def getDropout: Float
    Definition Classes
    ClassifierDLApproach
  48. def getEnableOutputLogs: Boolean
    Definition Classes
    EvaluationDLParams
  49. def getInputCols: Array[String]
    Definition Classes
    HasInputAnnotationCols
  50. def getLabelColumn: String
    Definition Classes
    ClassifierEncoder
  51. def getLazyAnnotator: Boolean
    Definition Classes
    CanBeLazy
  52. def getLr: Float
    Definition Classes
    ClassifierEncoder
  53. def getMaxEpochs: Int
    Definition Classes
    ClassifierEncoder
  54. final def getOrDefault[T](param: Param[T]): T
    Definition Classes
    Params
  55. final def getOutputCol: String
    Definition Classes
    HasOutputAnnotationCol
  56. def getOutputLogsPath: String
    Definition Classes
    EvaluationDLParams
  57. def getParam(paramName: String): Param[Any]
    Definition Classes
    Params
  58. def getRandomSeed: Int
    Definition Classes
    ClassifierEncoder
  59. def getValidationSplit: Float
    Definition Classes
    EvaluationDLParams
  60. final def hasDefault[T](param: Param[T]): Boolean
    Definition Classes
    Params
  61. def hasParam(paramName: String): Boolean
    Definition Classes
    Params
  62. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  63. def initializeLogIfNecessary(isInterpreter: Boolean, silent: Boolean): Boolean
    Attributes
    protected
    Definition Classes
    Logging
  64. def initializeLogIfNecessary(isInterpreter: Boolean): Unit
    Attributes
    protected
    Definition Classes
    Logging
  65. val inputAnnotatorTypes: Array[AnnotatorType]
    Definition Classes
    ClassifierDLApproach → HasInputAnnotationCols
  66. final val inputCols: StringArrayParam
    Attributes
    protected
    Definition Classes
    HasInputAnnotationCols
  67. final def isDefined(param: Param[_]): Boolean
    Definition Classes
    Params
  68. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  69. final def isSet(param: Param[_]): Boolean
    Definition Classes
    Params
  70. def isTraceEnabled(): Boolean
    Attributes
    protected
    Definition Classes
    Logging
  71. val labelColumn: Param[String]
    Definition Classes
    ClassifierEncoder
  72. val lazyAnnotator: BooleanParam
    Definition Classes
    CanBeLazy
  73. def loadSavedModel(): TensorflowWrapper
    Definition Classes
    ClassifierDLApproach
  74. def log: Logger
    Attributes
    protected
    Definition Classes
    Logging
  75. def logDebug(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  76. def logDebug(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  77. def logError(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  78. def logError(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  79. def logInfo(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  80. def logInfo(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  81. def logName: String
    Attributes
    protected
    Definition Classes
    Logging
  82. def logTrace(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  83. def logTrace(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  84. def logWarning(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  85. def logWarning(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  86. val lr: FloatParam
    Definition Classes
    ClassifierEncoder
  87. val maxEpochs: IntParam
    Definition Classes
    ClassifierEncoder
  88. def msgHelper(schema: StructType): String
    Attributes
    protected
    Definition Classes
    HasInputAnnotationCols
  89. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  90. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  91. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  92. def onTrained(model: ClassifierDLModel, spark: SparkSession): Unit
    Definition Classes
    AnnotatorApproach
  93. def onWrite(path: String, spark: SparkSession): Unit
    Attributes
    protected
    Definition Classes
    ParamsAndFeaturesWritable
  94. val optionalInputAnnotatorTypes: Array[String]
    Definition Classes
    HasInputAnnotationCols
  95. val outputAnnotatorType: String
    Definition Classes
    ClassifierDLApproach → HasOutputAnnotatorType
  96. final val outputCol: Param[String]
    Attributes
    protected
    Definition Classes
    HasOutputAnnotationCol
  97. val outputLogsPath: Param[String]
    Definition Classes
    EvaluationDLParams
  98. lazy val params: Array[Param[_]]
    Definition Classes
    Params
  99. val randomSeed: IntParam
    Definition Classes
    ClassifierEncoder
  100. def save(path: String): Unit
    Definition Classes
    MLWritable
    Annotations
    @Since( "1.6.0" ) @throws( ... )
  101. def set[T](feature: StructFeature[T], value: T): LegalClassifierDLApproach.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  102. def set[K, V](feature: MapFeature[K, V], value: Map[K, V]): LegalClassifierDLApproach.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  103. def set[T](feature: SetFeature[T], value: Set[T]): LegalClassifierDLApproach.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  104. def set[T](feature: ArrayFeature[T], value: Array[T]): LegalClassifierDLApproach.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  105. final def set(paramPair: ParamPair[_]): LegalClassifierDLApproach.this.type
    Attributes
    protected
    Definition Classes
    Params
  106. final def set(param: String, value: Any): LegalClassifierDLApproach.this.type
    Attributes
    protected
    Definition Classes
    Params
  107. final def set[T](param: Param[T], value: T): LegalClassifierDLApproach.this.type
    Definition Classes
    Params
  108. def setBatchSize(batch: Int): LegalClassifierDLApproach.this.type
    Definition Classes
    ClassifierEncoder
  109. def setConfigProtoBytes(bytes: Array[Int]): LegalClassifierDLApproach.this.type
    Definition Classes
    ClassifierEncoder
  110. def setDefault[T](feature: StructFeature[T], value: () ⇒ T): LegalClassifierDLApproach.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  111. def setDefault[K, V](feature: MapFeature[K, V], value: () ⇒ Map[K, V]): LegalClassifierDLApproach.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  112. def setDefault[T](feature: SetFeature[T], value: () ⇒ Set[T]): LegalClassifierDLApproach.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  113. def setDefault[T](feature: ArrayFeature[T], value: () ⇒ Array[T]): LegalClassifierDLApproach.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  114. final def setDefault(paramPairs: ParamPair[_]*): LegalClassifierDLApproach.this.type
    Attributes
    protected
    Definition Classes
    Params
  115. final def setDefault[T](param: Param[T], value: T): LegalClassifierDLApproach.this.type
    Attributes
    protected[org.apache.spark.ml]
    Definition Classes
    Params
  116. def setDropout(dropout: Float): LegalClassifierDLApproach.this.type
    Definition Classes
    ClassifierDLApproach
  117. def setEnableOutputLogs(enableOutputLogs: Boolean): LegalClassifierDLApproach.this.type
    Definition Classes
    EvaluationDLParams
  118. def setEvaluationLogExtended(evaluationLogExtended: Boolean): LegalClassifierDLApproach.this.type
    Definition Classes
    EvaluationDLParams
  119. final def setInputCols(value: String*): LegalClassifierDLApproach.this.type
    Definition Classes
    HasInputAnnotationCols
  120. def setInputCols(value: Array[String]): LegalClassifierDLApproach.this.type
    Definition Classes
    HasInputAnnotationCols
  121. def setLabelColumn(column: String): LegalClassifierDLApproach.this.type
    Definition Classes
    ClassifierEncoder
  122. def setLazyAnnotator(value: Boolean): LegalClassifierDLApproach.this.type
    Definition Classes
    CanBeLazy
  123. def setLr(lr: Float): LegalClassifierDLApproach.this.type
    Definition Classes
    ClassifierEncoder
  124. def setMaxEpochs(epochs: Int): LegalClassifierDLApproach.this.type
    Definition Classes
    ClassifierEncoder
  125. final def setOutputCol(value: String): LegalClassifierDLApproach.this.type
    Definition Classes
    HasOutputAnnotationCol
  126. def setOutputLogsPath(path: String): LegalClassifierDLApproach.this.type
    Definition Classes
    EvaluationDLParams
  127. def setRandomSeed(seed: Int): LegalClassifierDLApproach.this.type
    Definition Classes
    ClassifierEncoder
  128. def setTestDataset(er: ExternalResource): LegalClassifierDLApproach.this.type
    Definition Classes
    EvaluationDLParams
  129. def setTestDataset(path: String, readAs: Format, options: Map[String, String]): LegalClassifierDLApproach.this.type
    Definition Classes
    EvaluationDLParams
  130. def setValidationSplit(validationSplit: Float): LegalClassifierDLApproach.this.type
    Definition Classes
    EvaluationDLParams
  131. def setVerbose(verbose: Level): LegalClassifierDLApproach.this.type
    Definition Classes
    EvaluationDLParams
  132. def setVerbose(verbose: Int): LegalClassifierDLApproach.this.type
    Definition Classes
    EvaluationDLParams
  133. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  134. val testDataset: ExternalResourceParam
    Definition Classes
    EvaluationDLParams
  135. def toString(): String
    Definition Classes
    Identifiable → AnyRef → Any
  136. def train(dataset: Dataset[_], recursivePipeline: Option[PipelineModel]): LegalClassifierDLModel
    Definition Classes
    LegalClassifierDLApproach → ClassifierDLApproach → AnnotatorApproach
  137. final def transformSchema(schema: StructType): StructType
    Definition Classes
    AnnotatorApproach → PipelineStage
  138. def transformSchema(schema: StructType, logging: Boolean): StructType
    Attributes
    protected
    Definition Classes
    PipelineStage
    Annotations
    @DeveloperApi()
  139. val uid: String
    Definition Classes
    LegalClassifierDLApproach → ClassifierDLApproach → Identifiable
  140. def validate(schema: StructType): Boolean
    Attributes
    protected
    Definition Classes
    AnnotatorApproach
  141. val validationSplit: FloatParam
    Definition Classes
    EvaluationDLParams
  142. val verbose: IntParam
    Definition Classes
    EvaluationDLParams
  143. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  144. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  145. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  146. def write: MLWriter
    Definition Classes
    ParamsAndFeaturesWritable → DefaultParamsWritable → MLWritable

Inherited from ClassifierDLApproach

Inherited from ClassifierEncoder

Inherited from EvaluationDLParams

Inherited from ParamsAndFeaturesWritable

Inherited from HasFeatures

Inherited from AnnotatorApproach[ClassifierDLModel]

Inherited from CanBeLazy

Inherited from DefaultParamsWritable

Inherited from MLWritable

Inherited from HasOutputAnnotatorType

Inherited from HasOutputAnnotationCol

Inherited from HasInputAnnotationCols

Inherited from Estimator[ClassifierDLModel]

Inherited from PipelineStage

Inherited from Logging

Inherited from Params

Inherited from Serializable

Inherited from Serializable

Inherited from Identifiable

Inherited from AnyRef

Inherited from Any

Members