Packages

class NerDisambiguator extends AnnotatorApproach[NerDisambiguatorModel] with DisambiguatorModelParams

Links words of interest, such as names of persons, locations and companies, from an input text document to a corresponding unique entity in a target Knowledge Base (KB). Words of interest are called Named Entities (NEs), mentions, or surface forms. The model needs extracted CHUNKS and SENTENCE_EMBEDDINGS type input from e.g. SentenceEmbeddings and NerConverter.

Example

Extracting Person identities

First define pipeline stages that extract entities and embeddings. Entities are filtered for PER type entities.

val data = Seq("The show also had a contestant named Donald Trump who later defeated Christina Aguilera ...")
  .toDF("text")
val documentAssembler = new DocumentAssembler()
  .setInputCol("text")
  .setOutputCol("document")
val sentenceDetector = new SentenceDetector()
  .setInputCols("document")
  .setOutputCol("sentence")
val tokenizer = new Tokenizer()
  .setInputCols("sentence")
  .setOutputCol("token")
val word_embeddings = WordEmbeddingsModel.pretrained()
  .setInputCols("sentence", "token")
  .setOutputCol("embeddings")
val sentence_embeddings = new SentenceEmbeddings()
  .setInputCols("sentence","embeddings")
  .setOutputCol("sentence_embeddings")
val ner_model = NerDLModel.pretrained()
  .setInputCols("sentence", "token", "embeddings")
  .setOutputCol("ner")
val ner_converter = new NerConverter()
  .setInputCols("sentence", "token", "ner")
  .setOutputCol("ner_chunk")
  .setWhiteList("PER")

Then the extracted entities can be disambiguated.

 val disambiguator = new NerDisambiguator()
  .setS3KnowledgeBaseName("i-per")
  .setInputCols("ner_chunk", "sentence_embeddings")
  .setOutputCol("disambiguation")
  .setNumFirstChars(5)

val nlpPipeline = new Pipeline().setStages(Array(
  documentAssembler,
  sentenceDetector,
  tokenizer,
  word_embeddings,
  sentence_embeddings,
  ner_model,
  ner_converter,
  disambiguator))

val model = nlpPipeline.fit(data)
val result = model.transform(data)

Show results

result.selectExpr("explode(disambiguation)")
  .selectExpr("col.metadata.chunk as chunk", "col.result as result").show(5, false)
+------------------+------------------------------------------------------------------------------------------------------------------------+
|chunk             |result                                                                                                                  |
+------------------+------------------------------------------------------------------------------------------------------------------------+
|Donald Trump      |http://en.wikipedia.org/?curid=4848272, http://en.wikipedia.org/?curid=31698421, http://en.wikipedia.org/?curid=55907961|
|Christina Aguilera|http://en.wikipedia.org/?curid=144171, http://en.wikipedia.org/?curid=6636454                                           |
+------------------+------------------------------------------------------------------------------------------------------------------------+
Linear Supertypes
DisambiguatorModelParams, HasFeatures, AnnotatorApproach[NerDisambiguatorModel], CanBeLazy, DefaultParamsWritable, MLWritable, HasOutputAnnotatorType, HasOutputAnnotationCol, HasInputAnnotationCols, Estimator[NerDisambiguatorModel], PipelineStage, Logging, Params, Serializable, Serializable, Identifiable, AnyRef, Any
Ordering
  1. Grouped
  2. Alphabetic
  3. By Inheritance
Inherited
  1. NerDisambiguator
  2. DisambiguatorModelParams
  3. HasFeatures
  4. AnnotatorApproach
  5. CanBeLazy
  6. DefaultParamsWritable
  7. MLWritable
  8. HasOutputAnnotatorType
  9. HasOutputAnnotationCol
  10. HasInputAnnotationCols
  11. Estimator
  12. PipelineStage
  13. Logging
  14. Params
  15. Serializable
  16. Serializable
  17. Identifiable
  18. AnyRef
  19. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new NerDisambiguator()
  2. new NerDisambiguator(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. 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]): NerDisambiguatorModel
    Attributes
    protected
    Definition Classes
    AnnotatorApproach
  10. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  11. def beforeTraining(spark: SparkSession): Unit
    Definition Classes
    NerDisambiguator → AnnotatorApproach
  12. final def checkSchema(schema: StructType, inputAnnotatorType: String): Boolean
    Attributes
    protected
    Definition Classes
    HasInputAnnotationCols
  13. final def clear(param: Param[_]): NerDisambiguator.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[NerDisambiguatorModel]
    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
    Definition Classes
    NerDisambiguator → AnnotatorApproach
  19. val embeddingTypeParam: Param[String]

    Can be 'bow' for word embeddings or 'sentence' for sentences (Default: sentence)

    Can be 'bow' for word embeddings or 'sentence' for sentences (Default: sentence)

    Definition Classes
    DisambiguatorModelParams
  20. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  21. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  22. def explainParam(param: Param[_]): String
    Definition Classes
    Params
  23. def explainParams(): String
    Definition Classes
    Params
  24. final def extractParamMap(): ParamMap
    Definition Classes
    Params
  25. final def extractParamMap(extra: ParamMap): ParamMap
    Definition Classes
    Params
  26. val features: ArrayBuffer[Feature[_, _, _]]
    Definition Classes
    HasFeatures
  27. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  28. final def fit(dataset: Dataset[_]): NerDisambiguatorModel
    Definition Classes
    AnnotatorApproach → Estimator
  29. def fit(dataset: Dataset[_], paramMaps: Seq[ParamMap]): Seq[NerDisambiguatorModel]
    Definition Classes
    Estimator
    Annotations
    @Since( "2.0.0" )
  30. def fit(dataset: Dataset[_], paramMap: ParamMap): NerDisambiguatorModel
    Definition Classes
    Estimator
    Annotations
    @Since( "2.0.0" )
  31. def fit(dataset: Dataset[_], firstParamPair: ParamPair[_], otherParamPairs: ParamPair[_]*): NerDisambiguatorModel
    Definition Classes
    Estimator
    Annotations
    @Since( "2.0.0" ) @varargs()
  32. def get[T](feature: StructFeature[T]): Option[T]
    Attributes
    protected
    Definition Classes
    HasFeatures
  33. def get[K, V](feature: MapFeature[K, V]): Option[Map[K, V]]
    Attributes
    protected
    Definition Classes
    HasFeatures
  34. def get[T](feature: SetFeature[T]): Option[Set[T]]
    Attributes
    protected
    Definition Classes
    HasFeatures
  35. def get[T](feature: ArrayFeature[T]): Option[Array[T]]
    Attributes
    protected
    Definition Classes
    HasFeatures
  36. final def get[T](param: Param[T]): Option[T]
    Definition Classes
    Params
  37. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  38. final def getDefault[T](param: Param[T]): Option[T]
    Definition Classes
    Params
  39. def getEmbeddingType: String

    Can be 'bow' for word embeddings or 'sentence' for sentences (Default: sentence)

    Can be 'bow' for word embeddings or 'sentence' for sentences (Default: sentence)

    Definition Classes
    DisambiguatorModelParams
  40. def getInputCols: Array[String]
    Definition Classes
    HasInputAnnotationCols
  41. def getLazyAnnotator: Boolean
    Definition Classes
    CanBeLazy
  42. def getLevenshteinDistanceThresholdParam: Double

    Levenshtein distance threshold to narrow results from prefix search (Default: 0.1)

    Levenshtein distance threshold to narrow results from prefix search (Default: 0.1)

    Definition Classes
    DisambiguatorModelParams
  43. def getNarrowWithApproximateMatching: Boolean

    Whether to narrow prefix search results with levenstein distance based matching (Default: true)

    Whether to narrow prefix search results with levenstein distance based matching (Default: true)

    Definition Classes
    DisambiguatorModelParams
  44. def getNearMatchingGapParam: Int

    Puts a limit on a string length (by trimming the candidate chunks) during levenshtein-distance based narrowing, len(candidate) - len(entity chunk) > nearMatchingGap (Default: 4).

    Puts a limit on a string length (by trimming the candidate chunks) during levenshtein-distance based narrowing, len(candidate) - len(entity chunk) > nearMatchingGap (Default: 4).

    Definition Classes
    DisambiguatorModelParams
  45. def getNumFirstChars: Int

    How many characters should be considered for initial prefix search in knowledge base

    How many characters should be considered for initial prefix search in knowledge base

    Definition Classes
    DisambiguatorModelParams
  46. final def getOrDefault[T](param: Param[T]): T
    Definition Classes
    Params
  47. final def getOutputCol: String
    Definition Classes
    HasOutputAnnotationCol
  48. def getParam(paramName: String): Param[Any]
    Definition Classes
    Params
  49. def getPredictionLimit: Int

    Limit on amount of predictions N for topN predictions (Default: 100)

    Limit on amount of predictions N for topN predictions (Default: 100)

    Definition Classes
    DisambiguatorModelParams
  50. def getTokenSearch: Boolean

    Whether to search by token or by chunk in knowledge base (Default: true)

    Whether to search by token or by chunk in knowledge base (Default: true)

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

    Input annotator types: CHUNK, SENTENCE_EMBEDDINGS

    Input annotator types: CHUNK, SENTENCE_EMBEDDINGS

    Definition Classes
    NerDisambiguator → HasInputAnnotationCols
  57. final val inputCols: StringArrayParam
    Attributes
    protected
    Definition Classes
    HasInputAnnotationCols
  58. final def isDefined(param: Param[_]): Boolean
    Definition Classes
    Params
  59. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  60. final def isSet(param: Param[_]): Boolean
    Definition Classes
    Params
  61. def isTraceEnabled(): Boolean
    Attributes
    protected
    Definition Classes
    Logging
  62. val knowledgeBase: Param[String]

    Knowledge base path

  63. val lazyAnnotator: BooleanParam
    Definition Classes
    CanBeLazy
  64. val levenshteinDistanceThresholdParam: DoubleParam

    Levenshtein distance threshold to narrow results from prefix search (Default: 0.1)

    Levenshtein distance threshold to narrow results from prefix search (Default: 0.1)

    Definition Classes
    DisambiguatorModelParams
  65. def log: Logger
    Attributes
    protected
    Definition Classes
    Logging
  66. def logDebug(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  67. def logDebug(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  68. def logError(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  69. def logError(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  70. def logInfo(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  71. def logInfo(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  72. def logName: String
    Attributes
    protected
    Definition Classes
    Logging
  73. def logTrace(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  74. def logTrace(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  75. def logWarning(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  76. def logWarning(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  77. def msgHelper(schema: StructType): String
    Attributes
    protected
    Definition Classes
    HasInputAnnotationCols
  78. val narrowWithApproximateMatching: BooleanParam

    Whether to narrow prefix search results with levenstein distance based matching (Default: true)

    Whether to narrow prefix search results with levenstein distance based matching (Default: true)

    Definition Classes
    DisambiguatorModelParams
  79. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  80. val nearMatchingGapParam: IntParam

    Puts a limit on a string length (by trimming the candidate chunks) during levenshtein-distance based narrowing, len(candidate) - len(entity chunk) > nearMatchingGap (Default: 4).

    Puts a limit on a string length (by trimming the candidate chunks) during levenshtein-distance based narrowing, len(candidate) - len(entity chunk) > nearMatchingGap (Default: 4).

    Definition Classes
    DisambiguatorModelParams
  81. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  82. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  83. val numFirstChars: IntParam

    How many characters should be considered for initial prefix search in knowledge base

    How many characters should be considered for initial prefix search in knowledge base

    Definition Classes
    DisambiguatorModelParams
  84. def onTrained(model: NerDisambiguatorModel, spark: SparkSession): Unit
    Definition Classes
    AnnotatorApproach
  85. val optionalInputAnnotatorTypes: Array[String]
    Definition Classes
    HasInputAnnotationCols
  86. val outputAnnotatorType: AnnotatorType

    Output annotator types: DISAMBIGUATION

    Output annotator types: DISAMBIGUATION

    Definition Classes
    NerDisambiguator → HasOutputAnnotatorType
  87. final val outputCol: Param[String]
    Attributes
    protected
    Definition Classes
    HasOutputAnnotationCol
  88. lazy val params: Array[Param[_]]
    Definition Classes
    Params
  89. val predictionsLimit: IntParam

    Limit on amount of predictions N for topN predictions (Default: 100)

    Limit on amount of predictions N for topN predictions (Default: 100)

    Definition Classes
    DisambiguatorModelParams
  90. def resolveStorageName(database: String): String
  91. val s3KnowledgeBaseName: Param[String]

    Knowledge base name in s3

  92. def save(path: String): Unit
    Definition Classes
    MLWritable
    Annotations
    @Since( "1.6.0" ) @throws( ... )
  93. def set[T](feature: StructFeature[T], value: T): NerDisambiguator.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  94. def set[K, V](feature: MapFeature[K, V], value: Map[K, V]): NerDisambiguator.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  95. def set[T](feature: SetFeature[T], value: Set[T]): NerDisambiguator.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  96. def set[T](feature: ArrayFeature[T], value: Array[T]): NerDisambiguator.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  97. final def set(paramPair: ParamPair[_]): NerDisambiguator.this.type
    Attributes
    protected
    Definition Classes
    Params
  98. final def set(param: String, value: Any): NerDisambiguator.this.type
    Attributes
    protected
    Definition Classes
    Params
  99. final def set[T](param: Param[T], value: T): NerDisambiguator.this.type
    Definition Classes
    Params
  100. def setDefault[T](feature: StructFeature[T], value: () ⇒ T): NerDisambiguator.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  101. def setDefault[K, V](feature: MapFeature[K, V], value: () ⇒ Map[K, V]): NerDisambiguator.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  102. def setDefault[T](feature: SetFeature[T], value: () ⇒ Set[T]): NerDisambiguator.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  103. def setDefault[T](feature: ArrayFeature[T], value: () ⇒ Array[T]): NerDisambiguator.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  104. final def setDefault(paramPairs: ParamPair[_]*): NerDisambiguator.this.type
    Attributes
    protected
    Definition Classes
    Params
  105. final def setDefault[T](param: Param[T], value: T): NerDisambiguator.this.type
    Attributes
    protected
    Definition Classes
    Params
  106. def setEmbeddingType(v: String): NerDisambiguator.this.type

    Can be 'bow' for word embeddings or 'sentence' for sentences (Default: sentence)

    Can be 'bow' for word embeddings or 'sentence' for sentences (Default: sentence)

    Definition Classes
    DisambiguatorModelParams
  107. final def setInputCols(value: String*): NerDisambiguator.this.type
    Definition Classes
    HasInputAnnotationCols
  108. def setInputCols(value: Array[String]): NerDisambiguator.this.type
    Definition Classes
    HasInputAnnotationCols
  109. def setKnowledgeBase(path: String): NerDisambiguator.this.type

    Knowledge base path

  110. def setLazyAnnotator(value: Boolean): NerDisambiguator.this.type
    Definition Classes
    CanBeLazy
  111. def setLevenshteinDistanceThresholdParam(v: Double): NerDisambiguator.this.type

    Levenshtein distance threshold to narrow results from prefix search (Default: 0.1)

    Levenshtein distance threshold to narrow results from prefix search (Default: 0.1)

    Definition Classes
    DisambiguatorModelParams
  112. def setNarrowWithApproximateMatching(v: Boolean): NerDisambiguator.this.type

    Whether to narrow prefix search results with levenstein distance based matching (Default: true)

    Whether to narrow prefix search results with levenstein distance based matching (Default: true)

    Definition Classes
    DisambiguatorModelParams
  113. def setNearMatchingGapParam(v: Int): NerDisambiguator.this.type

    Puts a limit on a string length (by trimming the candidate chunks) during levenshtein-distance based narrowing, len(candidate) - len(entity chunk) > nearMatchingGap (Default: 4).

    Puts a limit on a string length (by trimming the candidate chunks) during levenshtein-distance based narrowing, len(candidate) - len(entity chunk) > nearMatchingGap (Default: 4).

    Definition Classes
    DisambiguatorModelParams
  114. def setNumFirstChars(v: Int): NerDisambiguator.this.type

    How many characters should be considered for initial prefix search in knowledge base

    How many characters should be considered for initial prefix search in knowledge base

    Definition Classes
    DisambiguatorModelParams
  115. final def setOutputCol(value: String): NerDisambiguator.this.type
    Definition Classes
    HasOutputAnnotationCol
  116. def setPredictionLimit(v: Int): NerDisambiguator.this.type

    Limit on amount of predictions N for topN predictions (Default: 100)

    Limit on amount of predictions N for topN predictions (Default: 100)

    Definition Classes
    DisambiguatorModelParams
  117. def setS3KnowledgeBaseName(path: String): NerDisambiguator.this.type

    Knowledge base name in s3

  118. def setTokenSearch(v: Boolean): NerDisambiguator.this.type

    Whether to search by token or by chunk in knowledge base (Default: true)

    Whether to search by token or by chunk in knowledge base (Default: true)

    Definition Classes
    DisambiguatorModelParams
  119. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  120. def toString(): String
    Definition Classes
    Identifiable → AnyRef → Any
  121. val tokenSearch: BooleanParam

    Whether to search by token or by chunk in knowledge base (Default: true)

    Whether to search by token or by chunk in knowledge base (Default: true)

    Definition Classes
    DisambiguatorModelParams
  122. def train(dataset: Dataset[_], recursivePipeline: Option[PipelineModel]): NerDisambiguatorModel
    Definition Classes
    NerDisambiguator → AnnotatorApproach
  123. final def transformSchema(schema: StructType): StructType
    Definition Classes
    AnnotatorApproach → PipelineStage
  124. def transformSchema(schema: StructType, logging: Boolean): StructType
    Attributes
    protected
    Definition Classes
    PipelineStage
    Annotations
    @DeveloperApi()
  125. val uid: String
    Definition Classes
    NerDisambiguator → Identifiable
  126. def validate(schema: StructType): Boolean
    Attributes
    protected
    Definition Classes
    AnnotatorApproach
  127. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  128. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  129. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  130. def write: MLWriter
    Definition Classes
    DefaultParamsWritable → MLWritable

Inherited from DisambiguatorModelParams

Inherited from HasFeatures

Inherited from AnnotatorApproach[NerDisambiguatorModel]

Inherited from CanBeLazy

Inherited from DefaultParamsWritable

Inherited from MLWritable

Inherited from HasOutputAnnotatorType

Inherited from HasOutputAnnotationCol

Inherited from HasInputAnnotationCols

Inherited from Estimator[NerDisambiguatorModel]

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