Packages

class GenericClassifierApproach extends AnnotatorApproach[GenericClassifierModel] with CheckLicense

Trains a TensorFlow model for generic classification of feature vectors. It takes FEATURE_VECTOR annotations from FeaturesAssembler as input, classifies them and outputs CATEGORY annotations. Please see the Parameters section for required training parameters.

For a more extensive example please see the Spark NLP Workshop.

Example

val features_asm = new FeaturesAssembler()
  .setInputCols(Array("feature_1", "feature_2", "...", "feature_n"))
  .setOutputCol("features")

val gen_clf = new GenericClassifierApproach()
  .setLabelColumn("target")
  .setInputCols("features")
  .setOutputCol("prediction")
  .setModelFile("/path/to/graph_file.pb")
  .setEpochsNumber(50)
  .setBatchSize(100)
  .setFeatureScaling("zscore")
  .setlearningRate(0.001f)
  .setFixImbalance(true)
  .setOutputLogsPath("logs")
  .setValidationSplit(0.2f) // keep 20% of the data for validation purposes

val pipeline = new Pipeline().setStages(Array(
  features_asm,
  gen_clf
))

val clf_model = pipeline.fit(data)
See also

GenericClassifierModel for the trained model

Linear Supertypes
CheckLicense, AnnotatorApproach[GenericClassifierModel], CanBeLazy, DefaultParamsWritable, MLWritable, HasOutputAnnotatorType, HasOutputAnnotationCol, HasInputAnnotationCols, Estimator[GenericClassifierModel], PipelineStage, Logging, Params, Serializable, Serializable, Identifiable, AnyRef, Any
Known Subclasses
Ordering
  1. Grouped
  2. Alphabetic
  3. By Inheritance
Inherited
  1. GenericClassifierApproach
  2. CheckLicense
  3. AnnotatorApproach
  4. CanBeLazy
  5. DefaultParamsWritable
  6. MLWritable
  7. HasOutputAnnotatorType
  8. HasOutputAnnotationCol
  9. HasInputAnnotationCols
  10. Estimator
  11. PipelineStage
  12. Logging
  13. Params
  14. Serializable
  15. Serializable
  16. Identifiable
  17. AnyRef
  18. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

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

    uid

    a unique identifier for the instantiated AnnotatorModel

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. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  5. def _fit(dataset: Dataset[_], recursiveStages: Option[PipelineModel]): GenericClassifierModel
    Attributes
    protected
    Definition Classes
    AnnotatorApproach
  6. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  7. val batchSize: IntParam

    Batch size

  8. def beforeTraining(spark: SparkSession): Unit
    Definition Classes
    GenericClassifierApproach → AnnotatorApproach
  9. final def checkSchema(schema: StructType, inputAnnotatorType: String): Boolean
    Attributes
    protected
    Definition Classes
    HasInputAnnotationCols
  10. def checkValidEnvironment(spark: Option[SparkContext]): Unit
    Definition Classes
    CheckLicense
  11. def checkValidScope(scope: String): Unit
    Definition Classes
    CheckLicense
  12. def checkValidScopeAndEnvironment(scope: String, spark: Option[SparkContext], checkLp: Boolean): Unit
    Definition Classes
    CheckLicense
  13. final def clear(param: Param[_]): GenericClassifierApproach.this.type
    Definition Classes
    Params
  14. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  15. final def copy(extra: ParamMap): Estimator[GenericClassifierModel]
    Definition Classes
    AnnotatorApproach → Estimator → PipelineStage → Params
  16. def copyValues[T <: Params](to: T, extra: ParamMap): T
    Attributes
    protected
    Definition Classes
    Params
  17. final def defaultCopy[T <: Params](extra: ParamMap): T
    Attributes
    protected
    Definition Classes
    Params
  18. val description: String

    Trains TensorFlow model for multi-class text classification

    Trains TensorFlow model for multi-class text classification

    Definition Classes
    GenericClassifierApproach → AnnotatorApproach
  19. val dropout: FloatParam

    Dropout coefficient

  20. val epochsN: IntParam

    Maximum number of epochs to train

  21. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  22. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  23. def explainParam(param: Param[_]): String
    Definition Classes
    Params
  24. def explainParams(): String
    Definition Classes
    Params
  25. final def extractParamMap(): ParamMap
    Definition Classes
    Params
  26. final def extractParamMap(extra: ParamMap): ParamMap
    Definition Classes
    Params
  27. val featureScaling: Param[String]

    Feature scaling method.

    Feature scaling method. Possible values are 'zscore', 'minmax' or empty (no scaling)

  28. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  29. final def fit(dataset: Dataset[_]): GenericClassifierModel
    Definition Classes
    AnnotatorApproach → Estimator
  30. def fit(dataset: Dataset[_], paramMaps: Array[ParamMap]): Seq[GenericClassifierModel]
    Definition Classes
    Estimator
    Annotations
    @Since( "2.0.0" )
  31. def fit(dataset: Dataset[_], paramMap: ParamMap): GenericClassifierModel
    Definition Classes
    Estimator
    Annotations
    @Since( "2.0.0" )
  32. def fit(dataset: Dataset[_], firstParamPair: ParamPair[_], otherParamPairs: ParamPair[_]*): GenericClassifierModel
    Definition Classes
    Estimator
    Annotations
    @Since( "2.0.0" ) @varargs()
  33. val fixImbalance: BooleanParam

    Fix the imbalance in the training set by replicating examples of under represented categories

  34. final def get[T](param: Param[T]): Option[T]
    Definition Classes
    Params
  35. def getBatchSize: Int

    Batch size

  36. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  37. final def getDefault[T](param: Param[T]): Option[T]
    Definition Classes
    Params
  38. def getDropout: Float

    Dropout coefficient

  39. def getFeatureScaling: String

    Get feature scaling method

  40. def getFixImbalance: Boolean

    Fix imbalance in training set

  41. def getInputCols: Array[String]
    Definition Classes
    HasInputAnnotationCols
  42. def getLabelColumn: String

    Column with label per each document

  43. def getLazyAnnotator: Boolean
    Definition Classes
    CanBeLazy
  44. def getLearningRate: Float

    Learning Rate

  45. def getMaxEpochs: Int

    Maximum number of epochs to train

  46. def getModelFile: String

    Model file name

  47. final def getOrDefault[T](param: Param[T]): T
    Definition Classes
    Params
  48. final def getOutputCol: String
    Definition Classes
    HasOutputAnnotationCol
  49. def getOutputLogsPath: String

    Get output logs path

  50. def getParam(paramName: String): Param[Any]
    Definition Classes
    Params
  51. def getValidationSplit: Float

    Choose the proportion of training dataset to be validated against the model on each Epoch.

    Choose the proportion of training dataset to be validated against the model on each Epoch. The value should be between 0.0 and 1.0 and by default it is 0.0 and off.

  52. final def hasDefault[T](param: Param[T]): Boolean
    Definition Classes
    Params
  53. def hasParam(paramName: String): Boolean
    Definition Classes
    Params
  54. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  55. def initializeLogIfNecessary(isInterpreter: Boolean, silent: Boolean): Boolean
    Attributes
    protected
    Definition Classes
    Logging
  56. def initializeLogIfNecessary(isInterpreter: Boolean): Unit
    Attributes
    protected
    Definition Classes
    Logging
  57. val inputAnnotatorTypes: Array[AnnotatorType]

    Input annotator type : FEATURE_VECTOR

    Input annotator type : FEATURE_VECTOR

    Definition Classes
    GenericClassifierApproach → HasInputAnnotationCols
  58. final val inputCols: StringArrayParam
    Attributes
    protected
    Definition Classes
    HasInputAnnotationCols
  59. final def isDefined(param: Param[_]): Boolean
    Definition Classes
    Params
  60. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  61. def isLp(): Boolean
    Definition Classes
    CheckLicense
  62. final def isSet(param: Param[_]): Boolean
    Definition Classes
    Params
  63. def isTraceEnabled(): Boolean
    Attributes
    protected
    Definition Classes
    Logging
  64. val labelColumn: Param[String]

    Column with label per each document

  65. val lazyAnnotator: BooleanParam
    Definition Classes
    CanBeLazy
  66. val learningRate: FloatParam

    Learning Rate

  67. def log: Logger
    Attributes
    protected
    Definition Classes
    Logging
  68. def logDebug(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  69. def logDebug(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  70. def logError(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  71. def logError(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  72. def logInfo(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  73. def logInfo(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  74. def logName: String
    Attributes
    protected
    Definition Classes
    Logging
  75. def logTrace(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  76. def logTrace(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  77. def logWarning(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  78. def logWarning(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  79. val modelFile: Param[String]

    Location of file of the model used for classification

  80. def msgHelper(schema: StructType): String
    Attributes
    protected
    Definition Classes
    HasInputAnnotationCols
  81. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  82. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  83. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  84. def onTrained(model: GenericClassifierModel, spark: SparkSession): Unit
    Definition Classes
    AnnotatorApproach
  85. val optionalInputAnnotatorTypes: Array[String]
    Definition Classes
    HasInputAnnotationCols
  86. val outputAnnotatorType: String

    Output annotator type : CATEGORY

    Output annotator type : CATEGORY

    Definition Classes
    GenericClassifierApproach → HasOutputAnnotatorType
  87. final val outputCol: Param[String]
    Attributes
    protected
    Definition Classes
    HasOutputAnnotationCol
  88. val outputLogsPath: Param[String]

    Path to folder to output logs.

    Path to folder to output logs. If no path is specified, no logs are generated

  89. lazy val params: Array[Param[_]]
    Definition Classes
    Params
  90. def save(path: String): Unit
    Definition Classes
    MLWritable
    Annotations
    @Since( "1.6.0" ) @throws( ... )
  91. final def set(paramPair: ParamPair[_]): GenericClassifierApproach.this.type
    Attributes
    protected
    Definition Classes
    Params
  92. final def set(param: String, value: Any): GenericClassifierApproach.this.type
    Attributes
    protected
    Definition Classes
    Params
  93. final def set[T](param: Param[T], value: T): GenericClassifierApproach.this.type
    Definition Classes
    Params
  94. def setBatchSize(batch: Int): GenericClassifierApproach.this.type

    Batch size

  95. final def setDefault(paramPairs: ParamPair[_]*): GenericClassifierApproach.this.type
    Attributes
    protected
    Definition Classes
    Params
  96. final def setDefault[T](param: Param[T], value: T): GenericClassifierApproach.this.type
    Attributes
    protected
    Definition Classes
    Params
  97. def setDropout(dropout: Float): GenericClassifierApproach.this.type

    Dropout coefficient

  98. def setEpochsNumber(epochs: Int): GenericClassifierApproach.this.type

    Maximum number of epochs to train

  99. def setFeatureScaling(featureScaling: String): GenericClassifierApproach.this.type

    Set the feature scaling method.

    Set the feature scaling method. Possible values are 'zscore', 'minmax' or empty (no scaling)

  100. def setFixImbalance(fix: Boolean): GenericClassifierApproach.this.type

    Fix imbalance of training set

  101. final def setInputCols(value: String*): GenericClassifierApproach.this.type
    Definition Classes
    HasInputAnnotationCols
  102. final def setInputCols(value: Array[String]): GenericClassifierApproach.this.type
    Definition Classes
    HasInputAnnotationCols
  103. def setLabelColumn(column: String): GenericClassifierApproach.this.type

    Column with label per each document

  104. def setLazyAnnotator(value: Boolean): GenericClassifierApproach.this.type
    Definition Classes
    CanBeLazy
  105. def setModelFile(modelFile: String): GenericClassifierApproach.this.type

    Set the model file name

  106. final def setOutputCol(value: String): GenericClassifierApproach.this.type
    Definition Classes
    HasOutputAnnotationCol
  107. def setOutputLogsPath(outputLogsPath: String): GenericClassifierApproach.this.type

    Set the output log path

  108. def setValidationSplit(validationSplit: Float): GenericClassifierApproach.this.type

    Choose the proportion of training dataset to be validated against the model on each Epoch.

    Choose the proportion of training dataset to be validated against the model on each Epoch. The value should be between 0.0 and 1.0 and by default it is 0.0 and off.

  109. def setlearningRate(lr: Float): GenericClassifierApproach.this.type

    Learning Rate

  110. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  111. def toString(): String
    Definition Classes
    Identifiable → AnyRef → Any
  112. def train(dataset: Dataset[_], recursivePipeline: Option[PipelineModel]): GenericClassifierModel
    Definition Classes
    GenericClassifierApproach → AnnotatorApproach
  113. final def transformSchema(schema: StructType): StructType
    Definition Classes
    AnnotatorApproach → PipelineStage
  114. def transformSchema(schema: StructType, logging: Boolean): StructType
    Attributes
    protected
    Definition Classes
    PipelineStage
    Annotations
    @DeveloperApi()
  115. val uid: String
    Definition Classes
    GenericClassifierApproach → Identifiable
  116. def validate(schema: StructType): Boolean
    Attributes
    protected
    Definition Classes
    AnnotatorApproach
  117. val validationSplit: FloatParam

    Choose the proportion of training dataset to be validated against the model on each Epoch.

    Choose the proportion of training dataset to be validated against the model on each Epoch. The value should be between 0.0 and 1.0 and by default it is 0.0 and off.

  118. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  119. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  120. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  121. def write: MLWriter
    Definition Classes
    DefaultParamsWritable → MLWritable

Inherited from CheckLicense

Inherited from AnnotatorApproach[GenericClassifierModel]

Inherited from CanBeLazy

Inherited from DefaultParamsWritable

Inherited from MLWritable

Inherited from HasOutputAnnotatorType

Inherited from HasOutputAnnotationCol

Inherited from HasInputAnnotationCols

Inherited from Estimator[GenericClassifierModel]

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

Annotator types

Required input and expected output annotator types

Members

Parameter setters

Parameter getters