Packages

class NerConverter extends AnnotatorModel[NerConverter] with HasSimpleAnnotate[NerConverter]

Converts a IOB or IOB2 representation of NER to a user-friendly one, by associating the tokens of recognized entities and their label. Results in CHUNK Annotation type.

NER chunks can then be filtered by setting a whitelist with setWhiteList. Chunks with no associated entity (tagged "O") are filtered.

See also Inside–outside–beginning (tagging) for more information.

Example

This is a continuation of the example of the NerDLModel. See that class on how to extract the entities.

The output of the NerDLModel follows the Annotator schema and can be converted like so:

result.selectExpr("explode(ner)").show(false)
+----------------------------------------------------+
|col                                                 |
+----------------------------------------------------+
|[named_entity, 0, 2, B-ORG, [word -> U.N], []]      |
|[named_entity, 3, 3, O, [word -> .], []]            |
|[named_entity, 5, 12, O, [word -> official], []]    |
|[named_entity, 14, 18, B-PER, [word -> Ekeus], []]  |
|[named_entity, 20, 24, O, [word -> heads], []]      |
|[named_entity, 26, 28, O, [word -> for], []]        |
|[named_entity, 30, 36, B-LOC, [word -> Baghdad], []]|
|[named_entity, 37, 37, O, [word -> .], []]          |
+----------------------------------------------------+

After the converter is used:

val converter = new NerConverter()
  .setInputCols("sentence", "token", "ner")
  .setOutputCol("entities")
  .setPreservePosition(false)

converter.transform(result).selectExpr("explode(entities)").show(false)
+------------------------------------------------------------------------+
|col                                                                     |
+------------------------------------------------------------------------+
|[chunk, 0, 2, U.N, [entity -> ORG, sentence -> 0, chunk -> 0], []]      |
|[chunk, 14, 18, Ekeus, [entity -> PER, sentence -> 0, chunk -> 1], []]  |
|[chunk, 30, 36, Baghdad, [entity -> LOC, sentence -> 0, chunk -> 2], []]|
+------------------------------------------------------------------------+
Linear Supertypes
HasSimpleAnnotate[NerConverter], AnnotatorModel[NerConverter], CanBeLazy, RawAnnotator[NerConverter], HasOutputAnnotationCol, HasInputAnnotationCols, HasOutputAnnotatorType, ParamsAndFeaturesWritable, HasFeatures, DefaultParamsWritable, MLWritable, Model[NerConverter], Transformer, PipelineStage, Logging, Params, Serializable, Serializable, Identifiable, AnyRef, Any
Ordering
  1. Grouped
  2. Alphabetic
  3. By Inheritance
Inherited
  1. NerConverter
  2. HasSimpleAnnotate
  3. AnnotatorModel
  4. CanBeLazy
  5. RawAnnotator
  6. HasOutputAnnotationCol
  7. HasInputAnnotationCols
  8. HasOutputAnnotatorType
  9. ParamsAndFeaturesWritable
  10. HasFeatures
  11. DefaultParamsWritable
  12. MLWritable
  13. Model
  14. Transformer
  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

Parameters

A list of (hyper-)parameter keys this annotator can take. Users can set and get the parameter values through setters and getters, respectively.

  1. val nerHasNoSchema: BooleanParam

    set this to true if your NER tags coming from a model that does not have a IOB/IOB2 schema

  2. val preservePosition: BooleanParam

    Whether to preserve the original position of the tokens in the original document or use the modified tokens (Default: true)

  3. val whiteList: StringArrayParam

    If defined, list of entities to process.

    If defined, list of entities to process. The rest will be ignored. Do not include IOB prefix on labels

Annotator types

Required input and expected output annotator types

  1. val inputAnnotatorTypes: Array[String]

    Input Annotator Type : DOCUMENT, TOKEN, NAMED_ENTITY

    Input Annotator Type : DOCUMENT, TOKEN, NAMED_ENTITY

    Definition Classes
    NerConverterHasInputAnnotationCols
  2. val outputAnnotatorType: AnnotatorType

    Output Annotator Type : CHUNK

    Output Annotator Type : CHUNK

    Definition Classes
    NerConverterHasOutputAnnotatorType

Members

  1. type AnnotatorType = String
    Definition Classes
    HasOutputAnnotatorType
  1. def annotate(annotations: Seq[Annotation]): 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

    annotations

    Annotations that correspond to inputAnnotationCols generated by previous annotators if any

    returns

    any number of annotations processed for every input annotation. Not necessary one to one relationship

    Definition Classes
    NerConverterHasSimpleAnnotate
  2. final def clear(param: Param[_]): NerConverter.this.type
    Definition Classes
    Params
  3. def copy(extra: ParamMap): NerConverter

    requirement for annotators copies

    requirement for annotators copies

    Definition Classes
    RawAnnotator → Model → Transformer → PipelineStage → Params
  4. def dfAnnotate: UserDefinedFunction

    Wraps annotate to happen inside SparkSQL user defined functions in order to act with org.apache.spark.sql.Column

    Wraps annotate to happen inside SparkSQL user defined functions in order to act with org.apache.spark.sql.Column

    returns

    udf function to be applied to inputCols using this annotator's annotate function as part of ML transformation

    Definition Classes
    HasSimpleAnnotate
  5. def explainParam(param: Param[_]): String
    Definition Classes
    Params
  6. def explainParams(): String
    Definition Classes
    Params
  7. final def extractParamMap(): ParamMap
    Definition Classes
    Params
  8. final def extractParamMap(extra: ParamMap): ParamMap
    Definition Classes
    Params
  9. val features: ArrayBuffer[Feature[_, _, _]]
    Definition Classes
    HasFeatures
  10. final def get[T](param: Param[T]): Option[T]
    Definition Classes
    Params
  11. final def getDefault[T](param: Param[T]): Option[T]
    Definition Classes
    Params
  12. def getInputCols: Array[String]

    returns

    input annotations columns currently used

    Definition Classes
    HasInputAnnotationCols
  13. def getLazyAnnotator: Boolean
    Definition Classes
    CanBeLazy
  14. final def getOrDefault[T](param: Param[T]): T
    Definition Classes
    Params
  15. final def getOutputCol: String

    Gets annotation column name going to generate

    Gets annotation column name going to generate

    Definition Classes
    HasOutputAnnotationCol
  16. def getParam(paramName: String): Param[Any]
    Definition Classes
    Params
  17. final def hasDefault[T](param: Param[T]): Boolean
    Definition Classes
    Params
  18. def hasParam(paramName: String): Boolean
    Definition Classes
    Params
  19. def hasParent: Boolean
    Definition Classes
    Model
  20. final def isDefined(param: Param[_]): Boolean
    Definition Classes
    Params
  21. final def isSet(param: Param[_]): Boolean
    Definition Classes
    Params
  22. val lazyAnnotator: BooleanParam
    Definition Classes
    CanBeLazy
  23. val optionalInputAnnotatorTypes: Array[String]
    Definition Classes
    HasInputAnnotationCols
  24. lazy val params: Array[Param[_]]
    Definition Classes
    Params
  25. var parent: Estimator[NerConverter]
    Definition Classes
    Model
  26. def save(path: String): Unit
    Definition Classes
    MLWritable
    Annotations
    @Since( "1.6.0" ) @throws( ... )
  27. final def set[T](param: Param[T], value: T): NerConverter.this.type
    Definition Classes
    Params
  28. final def setInputCols(value: String*): NerConverter.this.type
    Definition Classes
    HasInputAnnotationCols
  29. def setInputCols(value: Array[String]): NerConverter.this.type

    Overrides required annotators column if different than default

    Overrides required annotators column if different than default

    Definition Classes
    HasInputAnnotationCols
  30. def setLazyAnnotator(value: Boolean): NerConverter.this.type
    Definition Classes
    CanBeLazy
  31. final def setOutputCol(value: String): NerConverter.this.type

    Overrides annotation column name when transforming

    Overrides annotation column name when transforming

    Definition Classes
    HasOutputAnnotationCol
  32. def setParent(parent: Estimator[NerConverter]): NerConverter
    Definition Classes
    Model
  33. def toString(): String
    Definition Classes
    Identifiable → AnyRef → Any
  34. 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
  35. def transform(dataset: Dataset[_], paramMap: ParamMap): DataFrame
    Definition Classes
    Transformer
    Annotations
    @Since( "2.0.0" )
  36. def transform(dataset: Dataset[_], firstParamPair: ParamPair[_], otherParamPairs: ParamPair[_]*): DataFrame
    Definition Classes
    Transformer
    Annotations
    @Since( "2.0.0" ) @varargs()
  37. 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
  38. val uid: String
    Definition Classes
    NerConverter → Identifiable
  39. def write: MLWriter
    Definition Classes
    ParamsAndFeaturesWritable → DefaultParamsWritable → MLWritable

Parameter setters

  1. def setNerHasNoSchema(value: Boolean): NerConverter.this.type

  2. def setPreservePosition(value: Boolean): NerConverter.this.type

    Whether to preserve the original position of the tokens in the original document or use the modified tokens (Default: true)

  3. def setWhiteList(list: String*): NerConverter.this.type

    If defined, list of entities to process.

    If defined, list of entities to process. The rest will be ignored. Do not include IOB prefix on labels