class SentenceEntityResolverModel extends nlp.annotators.resolution.SentenceEntityResolverModel

The model transforms a dataset with Input Annotation type SENTENCE_EMBEDDINGS, coming from e.g. BertSentenceEmbeddings and returns the normalized entity for a particular trained ontology / curated dataset. (e.g. ICD-10, RxNorm, SNOMED etc.)

To use pretrained models please see the Models Hub for available models.

Example

Resolving CPT

First define pipeline stages to extract entities

val documentAssembler = new DocumentAssembler()
  .setInputCol("text")
  .setOutputCol("document")
val sentenceDetector = SentenceDetectorDLModel.pretrained()
  .setInputCols("document")
  .setOutputCol("sentence")
val tokenizer = new Tokenizer()
  .setInputCols("sentence")
  .setOutputCol("token")
val word_embeddings = WordEmbeddingsModel.pretrained("embeddings_clinical", "en", "clinical/models")
  .setInputCols("sentence", "token")
  .setOutputCol("embeddings")
val clinical_ner = MedicalNerModel.pretrained("jsl_ner_wip_clinical", "en", "clinical/models")
  .setInputCols("sentence", "token", "embeddings")
  .setOutputCol("ner")
val ner_converter = new NerConverter()
  .setInputCols("sentence", "token", "ner")
  .setOutputCol("ner_chunk")
  .setWhiteList("Test","Procedure")
val c2doc = new Chunk2Doc()
  .setInputCols("ner_chunk")
  .setOutputCol("ner_chunk_doc")
val sbert_embedder = BertSentenceEmbeddings
  .pretrained("sbiobert_base_cased_mli","en","clinical/models")
  .setInputCols("ner_chunk_doc")
  .setOutputCol("sbert_embeddings")

Then the resolver is defined on the extracted entities and sentence embeddings

val cpt_resolver = SentenceEntityResolverModel.pretrained("sbiobertresolve_cpt_procedures_augmented","en", "clinical/models")
  .setInputCols("ner_chunk", "sbert_embeddings")
  .setOutputCol("cpt_code")
  .setDistanceFunction("EUCLIDEAN")
val sbert_pipeline_cpt = new Pipeline().setStages(Array(
  documentAssembler,
  sentenceDetector,
  tokenizer,
  word_embeddings,
  clinical_ner,
  ner_converter,
  c2doc,
  sbert_embedder,
  cpt_resolver))

Show results

sbert_outputs
  .select("explode(arrays_zip(ner_chunk.result ,ner_chunk.metadata, cpt_code.result, cpt_code.metadata, ner_chunk.begin, ner_chunk.end)) as cpt_code")
  .selectExpr(
    "cpt_code['0'] as chunk",
    "cpt_code['1'].entity as entity",
    "cpt_code['2'] as code",
    "cpt_code['3'].confidence as confidence",
    "cpt_code['3'].all_k_resolutions as all_k_resolutions",
    "cpt_code['3'].all_k_results as all_k_results"
  ).show(5)
+--------------------+---------+-----+----------+--------------------+--------------------+
|               chunk|   entity| code|confidence|   all_k_resolutions|         all_k_codes|
+--------------------+---------+-----+----------+--------------------+--------------------+
|          heart cath|Procedure|93566|    0.1180|CCA - Cardiac cat...|93566:::62319:::9...|
|selective coronar...|     Test|93460|    0.1000|Coronary angiogra...|93460:::93458:::9...|
|common femoral an...|     Test|35884|    0.1808|Femoral artery by...|35884:::35883:::3...|
|   StarClose closure|Procedure|33305|    0.1197|Heart closure:::H...|33305:::33300:::3...|
|         stress test|     Test|93351|    0.2795|Cardiovascular st...|93351:::94621:::9...|
+--------------------+---------+-----+----------+--------------------+--------------------+
See also

SentenceEntityResolverApproach for training a custom model

Linear Supertypes
nlp.annotators.resolution.SentenceEntityResolverModel, CheckLicense, HasSafeAnnotate[nlp.annotators.resolution.SentenceEntityResolverModel], HandleExceptionParams, HasSimpleAnnotate[nlp.annotators.resolution.SentenceEntityResolverModel], HasEmbeddingsProperties, HasProtectedParams, HasStorageModel, HasStorageOptions, HasStorageReader, HasCaseSensitiveProperties, HasStorageRef, SentenceResolverParams, AnnotatorModel[nlp.annotators.resolution.SentenceEntityResolverModel], CanBeLazy, RawAnnotator[nlp.annotators.resolution.SentenceEntityResolverModel], HasOutputAnnotationCol, HasInputAnnotationCols, HasOutputAnnotatorType, ParamsAndFeaturesWritable, HasFeatures, DefaultParamsWritable, MLWritable, Model[nlp.annotators.resolution.SentenceEntityResolverModel], Transformer, PipelineStage, Logging, Params, Serializable, Serializable, Identifiable, AnyRef, Any
Ordering
  1. Grouped
  2. Alphabetic
  3. By Inheritance
Inherited
  1. SentenceEntityResolverModel
  2. SentenceEntityResolverModel
  3. CheckLicense
  4. HasSafeAnnotate
  5. HandleExceptionParams
  6. HasSimpleAnnotate
  7. HasEmbeddingsProperties
  8. HasProtectedParams
  9. HasStorageModel
  10. HasStorageOptions
  11. HasStorageReader
  12. HasCaseSensitiveProperties
  13. HasStorageRef
  14. SentenceResolverParams
  15. AnnotatorModel
  16. CanBeLazy
  17. RawAnnotator
  18. HasOutputAnnotationCol
  19. HasInputAnnotationCols
  20. HasOutputAnnotatorType
  21. ParamsAndFeaturesWritable
  22. HasFeatures
  23. DefaultParamsWritable
  24. MLWritable
  25. Model
  26. Transformer
  27. PipelineStage
  28. Logging
  29. Params
  30. Serializable
  31. Serializable
  32. Identifiable
  33. AnyRef
  34. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Parameters

  1. val datasetInfo: Param[String]

    Descriptive information about the dataset being used.

    Descriptive information about the dataset being used.

    Definition Classes
    SentenceResolverParams
  2. val doExceptionHandling: BooleanParam

    If true, exceptions are handled.

    If true, exceptions are handled. If exception causing data is passed to the model, a error annotation is emitted which has the exception message. Processing continues with the next one. This comes with a performance penalty.

    Definition Classes
    HandleExceptionParams
  3. val returnResolvedTextEmbeddings: BooleanParam

    Whether to include embeddings for resolved text embeddings.(Default : false)

    Whether to include embeddings for resolved text embeddings.(Default : false)

    Definition Classes
    SentenceEntityResolverModel
  4. val useAuxLabel: BooleanParam

    Whether to use Aux Label or not (Default: false)

    Whether to use Aux Label or not (Default: false)

    Definition Classes
    SentenceEntityResolverModel
  5. val auxLabelCol: Param[String]

    Optional column with one extra label per document.

    Optional column with one extra label per document. This extra label will be outputted later on in an additional column (Default: aux_label)

    Definition Classes
    SentenceEntityResolverModel
    Annotations
    @deprecated
    Deprecated
  6. val returnAllKEmbeddings: BooleanParam

    Whether to return all embeddings of all K candidates of the resolution.

    Whether to return all embeddings of all K candidates of the resolution. Embeddings will be in the metadata. Increase in RAM usage to be expected (Default: false)

    Definition Classes
    SentenceEntityResolverModel
    Annotations
    @deprecated
    Deprecated
  7. val returnCosineDistances: BooleanParam

    Whether to calculate and return cosine distances between a chunk/token and the k closest candidates.

    Whether to calculate and return cosine distances between a chunk/token and the k closest candidates. Can improve accuracy but increases computation (Default: true)

    Definition Classes
    SentenceEntityResolverModel
    Annotations
    @deprecated
    Deprecated
  8. val returnEuclideanDistances: BooleanParam

    Whether to Euclidean distances of the k closest candidates for a chunk/token (Default: true)

    Whether to Euclidean distances of the k closest candidates for a chunk/token (Default: true)

    Definition Classes
    SentenceEntityResolverModel
    Annotations
    @deprecated
    Deprecated

Members

  1. type AnnotatorType = String
    Definition Classes
    HasOutputAnnotatorType
  2. implicit class ProtectedParam[T] extends Param[T]
    Definition Classes
    HasProtectedParams
  1. def annotate(annotations: Seq[Annotation]): Seq[Annotation]

    Resolves the ResolverLabel for the given array of TOKEN and WORD_EMBEDDINGS annotations

    Resolves the ResolverLabel for the given array of TOKEN and WORD_EMBEDDINGS annotations

    annotations

    an array of TOKEN and WORD_EMBEDDINGS Annotation objects coming from ChunkTokenizer and ChunkEmbeddings respectively

    returns

    an array of Annotation objects, with the result of the entity resolution for each chunk and the following metadata all_k_results -> Sorted ResolverLabels in the top alternatives that match the distance threshold all_k_resolutions -> Respective ResolverNormalized strings all_k_distances -> Respective distance values after aggregation all_k_wmd_distances -> Respective WMD distance values all_k_tfidf_distances -> Respective TFIDF Cosinge distance values all_k_jaccard_distances -> Respective Jaccard distance values all_k_sorensen_distances -> Respective SorensenDice distance values all_k_jaro_distances -> Respective JaroWinkler distance values all_k_levenshtein_distances -> Respective Levenshtein distance values all_k_confidences -> Respective normalized probabilities based in inverse distance values target_text -> The actual searched string resolved_text -> The top ResolverNormalized string confidence -> Top probability distance -> Top distance value sentence -> Sentence index chunk -> Chunk Index token -> Token index

    Definition Classes
    SentenceEntityResolverModelSentenceEntityResolverModel → HasSimpleAnnotate
  2. val auxLabelMap: StructFeature[Map[String, String]]

    Collection of Parameters, which are used by method annotate()

    Collection of Parameters, which are used by method annotate()

    Definition Classes
    SentenceEntityResolverModel
  3. val caseSensitive: BooleanParam
    Definition Classes
    HasCaseSensitiveProperties
  4. def checkValidEnvironment(spark: Option[SparkSession], scopes: Seq[String]): Unit
    Definition Classes
    CheckLicense
  5. def checkValidScope(scope: String): Unit
    Definition Classes
    CheckLicense
  6. def checkValidScopeAndEnvironment(scope: String, spark: Option[SparkSession], checkLp: Boolean): Unit
    Definition Classes
    CheckLicense
  7. def checkValidScopesAndEnvironment(scopes: Seq[String], spark: Option[SparkSession], checkLp: Boolean): Unit
    Definition Classes
    CheckLicense
  8. final def clear(param: Param[_]): SentenceEntityResolverModel.this.type
    Definition Classes
    Params
  9. val confidenceFunction: Param[String]
    Definition Classes
    SentenceResolverParams
  10. def continueTraining(newKeys: Array[Array[Float]], newData: Array[TreeData], blackList: Set[String], overwrite: Boolean = true): SerializableKDTree[TreeData]
    Definition Classes
    SentenceEntityResolverModel
  11. def copy(extra: ParamMap): nlp.annotators.resolution.SentenceEntityResolverModel
    Definition Classes
    RawAnnotator → Model → Transformer → PipelineStage → Params
  12. def createDatabaseConnection(database: Name): RocksDBConnection
    Definition Classes
    HasStorageRef
  13. def deserializeStorage(path: String, spark: SparkSession): Unit
    Definition Classes
    HasStorageModel
  14. def dfAnnotate: UserDefinedFunction
    Definition Classes
    HasSimpleAnnotate
  15. val dimension: ProtectedParam[Int]
    Definition Classes
    HasEmbeddingsProperties
  16. val distanceFunction: Param[String]

    what distance function to use for KNN: 'EUCLIDEAN' or 'COSINE'

    what distance function to use for KNN: 'EUCLIDEAN' or 'COSINE'

    Definition Classes
    SentenceResolverParams
  17. val enableInMemoryStorage: BooleanParam
    Definition Classes
    HasStorageOptions
  18. def explainParam(param: Param[_]): String
    Definition Classes
    Params
  19. def explainParams(): String
    Definition Classes
    Params
  20. final def extractParamMap(): ParamMap
    Definition Classes
    Params
  21. final def extractParamMap(extra: ParamMap): ParamMap
    Definition Classes
    Params
  22. val features: ArrayBuffer[Feature[_, _, _]]
    Definition Classes
    HasFeatures
  23. final def get[T](param: Param[T]): Option[T]
    Definition Classes
    Params
  24. def getAuxLabelMap(): Map[String, String]

    Map[String,String] where key=label and value=auxLabel from a dataset.

    Map[String,String] where key=label and value=auxLabel from a dataset.

    Definition Classes
    SentenceEntityResolverModel
  25. def getCaseSensitive: Boolean
    Definition Classes
    HasCaseSensitiveProperties
  26. def getConfidenceFunction: String
    Definition Classes
    SentenceResolverParams
  27. final def getDefault[T](param: Param[T]): Option[T]
    Definition Classes
    Params
  28. def getDimension: Int
    Definition Classes
    HasEmbeddingsProperties
  29. def getDistanceFunction: String
    Definition Classes
    SentenceResolverParams
  30. def getEnableInMemoryStorage: Boolean
    Definition Classes
    HasStorageOptions
  31. def getIncludeStorage: Boolean
    Definition Classes
    HasStorageOptions
  32. def getInputCols: Array[String]
    Definition Classes
    HasInputAnnotationCols
  33. def getLazyAnnotator: Boolean
    Definition Classes
    CanBeLazy
  34. def getMissAsEmpty: Boolean
    Definition Classes
    SentenceResolverParams
  35. def getNeighbours: Int
    Definition Classes
    SentenceResolverParams
  36. final def getOrDefault[T](param: Param[T]): T
    Definition Classes
    Params
  37. final def getOutputCol: String
    Definition Classes
    HasOutputAnnotationCol
  38. def getParam(paramName: String): Param[Any]
    Definition Classes
    Params
  39. def getSearchTree: SerializableKDTree[TreeData]
    Definition Classes
    SentenceEntityResolverModel
  40. def getStorageRef: String
    Definition Classes
    HasStorageRef
  41. def getThreshold: Double
    Definition Classes
    SentenceResolverParams
  42. final def hasDefault[T](param: Param[T]): Boolean
    Definition Classes
    Params
  43. def hasParam(paramName: String): Boolean
    Definition Classes
    Params
  44. def hasParent: Boolean
    Definition Classes
    Model
  45. val includeStorage: BooleanParam
    Definition Classes
    HasStorageOptions
  46. val inputAnnotatorTypes: Array[String]

    Input annotator types: SENTENCE_EMBEDDINGS

    Input annotator types: SENTENCE_EMBEDDINGS

    Definition Classes
    SentenceEntityResolverModel → HasInputAnnotationCols
  47. final def isDefined(param: Param[_]): Boolean
    Definition Classes
    Params
  48. final def isSet(param: Param[_]): Boolean
    Definition Classes
    Params
  49. val lazyAnnotator: BooleanParam
    Definition Classes
    CanBeLazy
  50. val missAsEmpty: BooleanParam

    whether or not to return an empty annotation on unmatched chunks

    whether or not to return an empty annotation on unmatched chunks

    Definition Classes
    SentenceResolverParams
  51. val neighbours: IntParam

    number of neighbours to consider in the KNN query to calculate WMD

    number of neighbours to consider in the KNN query to calculate WMD

    Definition Classes
    SentenceResolverParams
  52. val optionalInputAnnotatorTypes: Array[String]
    Definition Classes
    HasInputAnnotationCols
  53. val outputAnnotatorType: AnnotatorType

    Output annotator types: ENTITY

    Output annotator types: ENTITY

    Definition Classes
    SentenceEntityResolverModel → HasOutputAnnotatorType
  54. lazy val params: Array[Param[_]]
    Definition Classes
    Params
  55. var parent: Estimator[nlp.annotators.resolution.SentenceEntityResolverModel]
    Definition Classes
    Model
  56. def save(path: String): Unit
    Definition Classes
    MLWritable
    Annotations
    @Since( "1.6.0" ) @throws( ... )
  57. def saveStorage(path: String, spark: SparkSession, withinStorage: Boolean): Unit
    Definition Classes
    HasStorageModel
  58. val searchTree: StructFeature_HadoopFix[SerializableKDTree[TreeData]]

    Search Tree.

    Search Tree. Under the hood encapsulates SerializableKDTree. Used to perform the search

    Definition Classes
    SentenceEntityResolverModel
  59. def serializeStorage(path: String, spark: SparkSession): Unit
    Definition Classes
    HasStorageModel
  60. def set[T](param: ProtectedParam[T], value: T): SentenceEntityResolverModel.this.type
    Definition Classes
    HasProtectedParams
  61. final def set[T](param: Param[T], value: T): SentenceEntityResolverModel.this.type
    Definition Classes
    Params
  62. def setAuxLabelMap(m: Map[String, String]): SentenceEntityResolverModel.this.type

    Map[String,String] where key=label and value=auxLabel from a dataset.

    Map[String,String] where key=label and value=auxLabel from a dataset.

    Definition Classes
    SentenceEntityResolverModel
  63. def setCaseSensitive(value: Boolean): SentenceEntityResolverModel.this.type
    Definition Classes
    HasCaseSensitiveProperties
  64. def setConfidenceFunction(v: String): SentenceEntityResolverModel.this.type
    Definition Classes
    SentenceResolverParams
  65. def setDimension(value: Int): SentenceEntityResolverModel.this.type
    Definition Classes
    HasEmbeddingsProperties
  66. def setDistanceFunction(value: String): SentenceEntityResolverModel.this.type
    Definition Classes
    SentenceResolverParams
  67. def setEnableInMemoryStorage(value: Boolean): SentenceEntityResolverModel.this.type
    Definition Classes
    HasStorageOptions
  68. def setIncludeStorage(value: Boolean): SentenceEntityResolverModel.this.type
    Definition Classes
    HasStorageOptions
  69. final def setInputCols(value: String*): SentenceEntityResolverModel.this.type
    Definition Classes
    HasInputAnnotationCols
  70. def setInputCols(value: Array[String]): SentenceEntityResolverModel.this.type
    Definition Classes
    HasInputAnnotationCols
  71. def setLazyAnnotator(value: Boolean): SentenceEntityResolverModel.this.type
    Definition Classes
    CanBeLazy
  72. def setMissAsEmpty(v: Boolean): SentenceEntityResolverModel.this.type
    Definition Classes
    SentenceResolverParams
  73. def setNeighbours(k: Int): SentenceEntityResolverModel.this.type
    Definition Classes
    SentenceResolverParams
  74. final def setOutputCol(value: String): SentenceEntityResolverModel.this.type
    Definition Classes
    HasOutputAnnotationCol
  75. def setParent(parent: Estimator[nlp.annotators.resolution.SentenceEntityResolverModel]): nlp.annotators.resolution.SentenceEntityResolverModel
    Definition Classes
    Model
  76. def setReturnResolvedTextEmbeddings(value: Boolean): SentenceEntityResolverModel.this.type

    Whether to include embeddings for resolved text embeddings.(Default : false)

    Whether to include embeddings for resolved text embeddings.(Default : false)

    Definition Classes
    SentenceEntityResolverModel
  77. def setSearchTree(tree: SerializableKDTree[TreeData]): SentenceEntityResolverModel.this.type
    Definition Classes
    SentenceEntityResolverModel
  78. def setStorageRef(value: String): SentenceEntityResolverModel.this.type
    Definition Classes
    HasStorageRef
  79. def setThreshold(dist: Double): SentenceEntityResolverModel.this.type
    Definition Classes
    SentenceResolverParams
  80. val storageRef: Param[String]
    Definition Classes
    HasStorageRef
  81. val threshold: DoubleParam

    threshold value for the aggregated distance

    threshold value for the aggregated distance

    Definition Classes
    SentenceResolverParams
  82. def toString(): String
    Definition Classes
    Identifiable → AnyRef → Any
  83. final def transform(dataset: Dataset[_]): DataFrame
    Definition Classes
    AnnotatorModel → Transformer
  84. def transform(dataset: Dataset[_], paramMap: ParamMap): DataFrame
    Definition Classes
    Transformer
    Annotations
    @Since( "2.0.0" )
  85. def transform(dataset: Dataset[_], firstParamPair: ParamPair[_], otherParamPairs: ParamPair[_]*): DataFrame
    Definition Classes
    Transformer
    Annotations
    @Since( "2.0.0" ) @varargs()
  86. final def transformSchema(schema: StructType): StructType
    Definition Classes
    RawAnnotator → PipelineStage
  87. val uid: String
    Definition Classes
    SentenceEntityResolverModelSentenceEntityResolverModel → Identifiable
  88. def validateStorageRef(dataset: Dataset[_], inputCols: Array[String], annotatorType: String): Unit
    Definition Classes
    HasStorageRef
  89. def write: MLWriter
    Definition Classes
    ParamsAndFeaturesWritable → DefaultParamsWritable → MLWritable

Parameter setters

  1. def setDatasetInfo(value: String): SentenceEntityResolverModel.this.type

    set descriptive information about the dataset being used

    set descriptive information about the dataset being used

    Definition Classes
    SentenceResolverParams
  2. def setDoExceptionHandling(value: Boolean): SentenceEntityResolverModel.this.type

    If true, exceptions are handled.

    If true, exceptions are handled. If exception causing data is passed to the model, a error annotation is emitted which has the exception message. Processing continues with the next one. This comes with a performance penalty.

    Definition Classes
    HandleExceptionParams
  3. def setUseAuxLabel(b: Boolean): SentenceEntityResolverModel.this.type

    Whether to use Aux Label or not

    Whether to use Aux Label or not

    Definition Classes
    SentenceEntityResolverModel
  4. def setAuxLabelCol(c: String): SentenceEntityResolverModel.this.type

    Optional column with one extra label per document.

    Optional column with one extra label per document. This extra label will be outputted later on in an additional column.

    Definition Classes
    SentenceEntityResolverModel
    Annotations
    @deprecated
    Deprecated
  5. def setReturnAllKEmbeddings(b: Boolean): SentenceEntityResolverModel.this.type

    Whether to return all embeddings of all K candidates of the resolution.

    Whether to return all embeddings of all K candidates of the resolution. Embeddings will be in the metadata. Increase in RAM usage to be expected

    Definition Classes
    SentenceEntityResolverModel
    Annotations
    @deprecated
    Deprecated
  6. def setReturnCosineDistances(value: Boolean): SentenceEntityResolverModel.this.type

    Whether to calculate and return cosine distances between a chunk/token and the k closest candidates.

    Whether to calculate and return cosine distances between a chunk/token and the k closest candidates. Can improve accuracy but increases computation.

    Definition Classes
    SentenceEntityResolverModel
    Annotations
    @deprecated
    Deprecated
  7. def setReturnEuclideanDistances(value: Boolean): SentenceEntityResolverModel.this.type

    Whether to Euclidean distances of the k closest candidates for a chunk/token.

    Whether to Euclidean distances of the k closest candidates for a chunk/token.

    Definition Classes
    SentenceEntityResolverModel
    Annotations
    @deprecated
    Deprecated

Parameter getters

  1. def getDatasetInfo: String

    get descriptive information about the dataset being used

    get descriptive information about the dataset being used

    Definition Classes
    SentenceResolverParams
  2. def getReturnAllKEmbeddings(): Boolean

    Whether to return all embeddings of all K candidates of the resolution.

    Whether to return all embeddings of all K candidates of the resolution. Embeddings will be in the metadata. Increase in RAM usage to be expected

    Definition Classes
    SentenceEntityResolverModel
  3. def getReturnCosineDistances: Boolean

    Whether to calculate and return cosine distances between a chunk/token and the k closest candidates.

    Whether to calculate and return cosine distances between a chunk/token and the k closest candidates. Can improve accuracy but increases computation.

    Definition Classes
    SentenceEntityResolverModel
  4. def getUseAuxLabel(): Boolean

    Whether to use Aux Label or not

    Whether to use Aux Label or not

    Definition Classes
    SentenceEntityResolverModel
  5. def getAuxLabelCol(): String

    Optional column with one extra label per document.

    Optional column with one extra label per document. This extra label will be outputted later on in an additional column.

    Definition Classes
    SentenceEntityResolverModel
    Annotations
    @deprecated
    Deprecated
  6. def getReturnEuclideanDistances: Boolean

    Whether to Euclidean distances of the k closest candidates for a chunk/token.

    Whether to Euclidean distances of the k closest candidates for a chunk/token.

    Definition Classes
    SentenceEntityResolverModel
    Annotations
    @deprecated
    Deprecated