Packages

class NerDisambiguator extends AnnotatorApproach[NerDisambiguatorModel] with KvKnowledgeExtractor 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, KvKnowledgeExtractor, 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. KvKnowledgeExtractor
  5. AnnotatorApproach
  6. CanBeLazy
  7. DefaultParamsWritable
  8. MLWritable
  9. HasOutputAnnotatorType
  10. HasOutputAnnotationCol
  11. HasInputAnnotationCols
  12. Estimator
  13. PipelineStage
  14. Logging
  15. Params
  16. Serializable
  17. Serializable
  18. Identifiable
  19. AnyRef
  20. 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
    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. def extractKnowledgeFromKv(id2record: (DataId) ⇒ Option[Record], chunk2id: (Chunk) ⇒ Option[List[DataId]]): Knowledge
    Definition Classes
    KvKnowledgeExtractor
  25. final def extractParamMap(): ParamMap
    Definition Classes
    Params
  26. final def extractParamMap(extra: ParamMap): ParamMap
    Definition Classes
    Params
  27. val features: ArrayBuffer[Feature[_, _, _]]
    Definition Classes
    HasFeatures
  28. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  29. final def fit(dataset: Dataset[_]): NerDisambiguatorModel
    Definition Classes
    AnnotatorApproach → Estimator
  30. def fit(dataset: Dataset[_], paramMaps: Array[ParamMap]): Seq[NerDisambiguatorModel]
    Definition Classes
    Estimator
    Annotations
    @Since( "2.0.0" )
  31. def fit(dataset: Dataset[_], paramMap: ParamMap): NerDisambiguatorModel
    Definition Classes
    Estimator
    Annotations
    @Since( "2.0.0" )
  32. def fit(dataset: Dataset[_], firstParamPair: ParamPair[_], otherParamPairs: ParamPair[_]*): NerDisambiguatorModel
    Definition Classes
    Estimator
    Annotations
    @Since( "2.0.0" ) @varargs()
  33. def get[T](feature: StructFeature[T]): Option[T]
    Attributes
    protected
    Definition Classes
    HasFeatures
  34. def get[K, V](feature: MapFeature[K, V]): Option[Map[K, V]]
    Attributes
    protected
    Definition Classes
    HasFeatures
  35. def get[T](feature: SetFeature[T]): Option[Set[T]]
    Attributes
    protected
    Definition Classes
    HasFeatures
  36. def get[T](feature: ArrayFeature[T]): Option[Array[T]]
    Attributes
    protected
    Definition Classes
    HasFeatures
  37. final def get[T](param: Param[T]): Option[T]
    Definition Classes
    Params
  38. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  39. final def getDefault[T](param: Param[T]): Option[T]
    Definition Classes
    Params
  40. 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
  41. def getInputCols: Array[String]
    Definition Classes
    HasInputAnnotationCols
  42. def getLazyAnnotator: Boolean
    Definition Classes
    CanBeLazy
  43. 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
  44. 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
  45. 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
  46. 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
  47. final def getOrDefault[T](param: Param[T]): T
    Definition Classes
    Params
  48. final def getOutputCol: String
    Definition Classes
    HasOutputAnnotationCol
  49. def getParam(paramName: String): Param[Any]
    Definition Classes
    Params
  50. 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
  51. 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
  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[String]

    Input annotator types: CHUNK, SENTENCE_EMBEDDINGS

    Input annotator types: CHUNK, SENTENCE_EMBEDDINGS

    Definition Classes
    NerDisambiguator → 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. final def isSet(param: Param[_]): Boolean
    Definition Classes
    Params
  62. def isTraceEnabled(): Boolean
    Attributes
    protected
    Definition Classes
    Logging
  63. val knowledgeBase: Param[String]

    Knowledge base path

  64. val knowledgeBaseStructure: StructFeature[Knowledge]
    Definition Classes
    DisambiguatorModelParams
  65. val lazyAnnotator: BooleanParam
    Definition Classes
    CanBeLazy
  66. 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
  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. def msgHelper(schema: StructType): String
    Attributes
    protected
    Definition Classes
    HasInputAnnotationCols
  80. 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
  81. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  82. 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
  83. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  84. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  85. 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
  86. def onTrained(model: NerDisambiguatorModel, spark: SparkSession): Unit
    Definition Classes
    AnnotatorApproach
  87. val outputAnnotatorType: AnnotatorType

    Output annotator types: DISAMBIGUATION

    Output annotator types: DISAMBIGUATION

    Definition Classes
    NerDisambiguator → HasOutputAnnotatorType
  88. final val outputCol: Param[String]
    Attributes
    protected
    Definition Classes
    HasOutputAnnotationCol
  89. lazy val params: Array[Param[_]]
    Definition Classes
    Params
  90. 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
  91. lazy val rocksDbReader: RocksDbReader
  92. val s3KnowledgeBaseName: Param[String]

    Knowledge base name in s3

  93. def save(path: String): Unit
    Definition Classes
    MLWritable
    Annotations
    @Since( "1.6.0" ) @throws( ... )
  94. def set[T](feature: StructFeature[T], value: T): NerDisambiguator.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  95. def set[K, V](feature: MapFeature[K, V], value: Map[K, V]): NerDisambiguator.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  96. def set[T](feature: SetFeature[T], value: Set[T]): NerDisambiguator.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  97. def set[T](feature: ArrayFeature[T], value: Array[T]): NerDisambiguator.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  98. final def set(paramPair: ParamPair[_]): NerDisambiguator.this.type
    Attributes
    protected
    Definition Classes
    Params
  99. final def set(param: String, value: Any): NerDisambiguator.this.type
    Attributes
    protected
    Definition Classes
    Params
  100. final def set[T](param: Param[T], value: T): NerDisambiguator.this.type
    Definition Classes
    Params
  101. def setDefault[T](feature: StructFeature[T], value: () ⇒ T): NerDisambiguator.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  102. def setDefault[K, V](feature: MapFeature[K, V], value: () ⇒ Map[K, V]): NerDisambiguator.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  103. def setDefault[T](feature: SetFeature[T], value: () ⇒ Set[T]): NerDisambiguator.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  104. def setDefault[T](feature: ArrayFeature[T], value: () ⇒ Array[T]): NerDisambiguator.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  105. final def setDefault(paramPairs: ParamPair[_]*): NerDisambiguator.this.type
    Attributes
    protected
    Definition Classes
    Params
  106. final def setDefault[T](param: Param[T], value: T): NerDisambiguator.this.type
    Attributes
    protected
    Definition Classes
    Params
  107. 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
  108. final def setInputCols(value: String*): NerDisambiguator.this.type
    Definition Classes
    HasInputAnnotationCols
  109. final def setInputCols(value: Array[String]): NerDisambiguator.this.type
    Definition Classes
    HasInputAnnotationCols
  110. def setKnowledgeBase(path: String): NerDisambiguator.this.type

    Knowledge base path

  111. def setKnowledgeBaseStructure(kb: Knowledge): NerDisambiguator.this.type
    Definition Classes
    DisambiguatorModelParams
  112. def setLazyAnnotator(value: Boolean): NerDisambiguator.this.type
    Definition Classes
    CanBeLazy
  113. 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
  114. 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
  115. 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
  116. 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
  117. final def setOutputCol(value: String): NerDisambiguator.this.type
    Definition Classes
    HasOutputAnnotationCol
  118. 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
  119. def setS3KnowledgeBaseName(path: String): NerDisambiguator.this.type

    Knowledge base name in s3

  120. 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
  121. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  122. def toString(): String
    Definition Classes
    Identifiable → AnyRef → Any
  123. 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
  124. def train(dataset: Dataset[_], recursivePipeline: Option[PipelineModel]): NerDisambiguatorModel
    Definition Classes
    NerDisambiguator → AnnotatorApproach
  125. final def transformSchema(schema: StructType): StructType
    Definition Classes
    AnnotatorApproach → PipelineStage
  126. def transformSchema(schema: StructType, logging: Boolean): StructType
    Attributes
    protected
    Definition Classes
    PipelineStage
    Annotations
    @DeveloperApi()
  127. val uid: String
    Definition Classes
    NerDisambiguator → Identifiable
  128. def validate(schema: StructType): Boolean
    Attributes
    protected
    Definition Classes
    AnnotatorApproach
  129. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  130. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  131. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  132. def write: MLWriter
    Definition Classes
    DefaultParamsWritable → MLWritable

Inherited from DisambiguatorModelParams

Inherited from HasFeatures

Inherited from KvKnowledgeExtractor

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