c

com.johnsnowlabs.nlp.annotators.deid

NameChunkObfuscatorApproach

class NameChunkObfuscatorApproach extends AnnotatorApproach[NameChunkObfuscator] with NameChunkObfuscatorParams with DeidApproachParams with CheckLicense

Contains all the methods for training a NameChunkObfuscator model. This module can replace name entities with consistent fakers. Additionally, obfuscation names can be defined with setObfuscateRefFile, where each line is a mapping of name. The format and seperator can be speficied with setRefFileFormat and setRefSep.

George#NAME
Taylor#NAME

The configuration params for that module are in trait NameChunkObfuscatorParams.

See also

NameChunkObfuscator

NameChunkObfuscatorParams

DeidApproachParams See Spark NLP Workshop for more examples of usage.

Example

 val data = Seq("John Davies is a 62 y.o. patient admitted." +
  "He was seen by attending physician Dr. Lorand and was scheduled for emergency assessment.")
  .toDF("text")

val documentAssembler = new DocumentAssembler()
 .setInputCol("text")
 .setOutputCol("sentence")

val tokenizer = new Tokenizer()
.setInputCols("sentence")
.setOutputCol("token")

val word_embeddings = WordEmbeddingsModel.pretrained("embeddings_clinical", "en", "clinical/models")
.setInputCols(Array("sentence", "token"))
.setOutputCol("embeddings")

val clinical_ner = MedicalNerModel.pretrained("ner_deid_generic_augmented", "en", "clinical/models")
.setInputCols(Array("sentence", "token", "embeddings"))
.setOutputCol("ner")

val ner_converter_name = new NerConverterInternal()
.setInputCols(Array("sentence", "token", "ner"))
.setOutputCol("ner_chunk")

NameChunkObfuscatorApproach

val nameChunkObfuscator = new NameChunkObfuscatorApproach()
.setInputCols("ner_chunk")
.setOutputCol("replacement")
.setRefFileFormat("csv")
.setObfuscateRefFile("obfuscator_names.txt")
.setRefSep("#")
.setObfuscateRefSource("both")
.setLanguage("en")

val replacer_name = new Replacer()
.setInputCols("replacement", "sentence")
.setOutputCol("obfuscated_document_name")
.setUseReplacement(true)

Pipeline

 val pipeline = new Pipeline().setStages(Array(
 documentAssembler,
 tokenizer,
 word_embeddings,
 clinical_ner,
 ner_converter_name,
 nameChunkObfuscator,
 replacer_name
 ))

 val result = pipeline.fit(data).transform(data)
 result.select("text").show(false)
 result.selectExpr("explode(document_normalized.result) as normalized_text").show(false)
+-----------------------------------------------------------------------------------------------------------------------------------+
|text                                                                                                                               |
+-----------------------------------------------------------------------------------------------------------------------------------+
|John Davies is a 62 y.o. patient admitted.He was seen by attending physician Dr. Lorand and was scheduled for emergency assessment.|
+-----------------------------------------------------------------------------------------------------------------------------------+

+-------------------------------------------------------------------------------------------------------------------------------------+
|result                                                                                                                               |
+-------------------------------------------------------------------------------------------------------------------------------------+
|[Charlestine is a 62 y.o. patient admitted.He was seen by attending physician Dr. Lowery and was scheduled for emergency assessment.]|
+-------------------------------------------------------------------------------------------------------------------------------------+
Linear Supertypes
CheckLicense, DeidApproachParams, NameChunkObfuscatorParams, AnnotatorApproach[NameChunkObfuscator], CanBeLazy, DefaultParamsWritable, MLWritable, HasOutputAnnotatorType, HasOutputAnnotationCol, HasInputAnnotationCols, Estimator[NameChunkObfuscator], PipelineStage, Logging, Params, Serializable, Serializable, Identifiable, AnyRef, Any
Ordering
  1. Grouped
  2. Alphabetic
  3. By Inheritance
Inherited
  1. NameChunkObfuscatorApproach
  2. CheckLicense
  3. DeidApproachParams
  4. NameChunkObfuscatorParams
  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 NameChunkObfuscatorApproach()
  2. new NameChunkObfuscatorApproach(uid: String)

    uid

    required uid for storing annotator to disk

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]): NameChunkObfuscator
    Attributes
    protected
    Definition Classes
    AnnotatorApproach
  6. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  7. def beforeTraining(spark: SparkSession): Unit
    Definition Classes
    AnnotatorApproach
  8. final def checkSchema(schema: StructType, inputAnnotatorType: String): Boolean
    Attributes
    protected
    Definition Classes
    HasInputAnnotationCols
  9. def checkValidEnvironment(spark: Option[SparkSession], scopes: Seq[String], metadata: Option[Map[String, Value]]): Unit
    Definition Classes
    CheckLicense
  10. def checkValidScope(scope: String): Unit
    Definition Classes
    CheckLicense
  11. def checkValidScopeAndEnvironment(scope: String, spark: Option[SparkSession], checkLp: Boolean, metadata: Option[Map[String, Value]]): Unit
    Definition Classes
    CheckLicense
  12. def checkValidScopesAndEnvironment(scopes: Seq[String], spark: Option[SparkSession], checkLp: Boolean, metadata: Option[Map[String, Value]]): Unit
    Definition Classes
    CheckLicense
  13. final def clear(param: Param[_]): NameChunkObfuscatorApproach.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[NameChunkObfuscator]
    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
    NameChunkObfuscatorApproach → AnnotatorApproach
  19. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  20. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  21. def explainParam(param: Param[_]): String
    Definition Classes
    Params
  22. def explainParams(): String
    Definition Classes
    Params
  23. final val extraInputCols: StringArrayParam
    Attributes
    protected
    Definition Classes
    HasInputAnnotationCols
  24. final def extractParamMap(): ParamMap
    Definition Classes
    Params
  25. final def extractParamMap(extra: ParamMap): ParamMap
    Definition Classes
    Params
  26. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  27. final def fit(dataset: Dataset[_]): NameChunkObfuscator
    Definition Classes
    AnnotatorApproach → Estimator
  28. def fit(dataset: Dataset[_], paramMaps: Seq[ParamMap]): Seq[NameChunkObfuscator]
    Definition Classes
    Estimator
    Annotations
    @Since( "2.0.0" )
  29. def fit(dataset: Dataset[_], paramMap: ParamMap): NameChunkObfuscator
    Definition Classes
    Estimator
    Annotations
    @Since( "2.0.0" )
  30. def fit(dataset: Dataset[_], firstParamPair: ParamPair[_], otherParamPairs: ParamPair[_]*): NameChunkObfuscator
    Definition Classes
    Estimator
    Annotations
    @Since( "2.0.0" ) @varargs()
  31. val genderAwareness: BooleanParam

    Whether to use gender-aware names or not during obfuscation.

    Whether to use gender-aware names or not during obfuscation. This param effects only names. If value is true, it might decrease performance. Default: False

    Definition Classes
    NameChunkObfuscatorParams
  32. final def get[T](param: Param[T]): Option[T]
    Definition Classes
    Params
  33. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  34. final def getDefault[T](param: Param[T]): Option[T]
    Definition Classes
    Params
  35. def getInputCols: Array[String]
    Definition Classes
    HasInputAnnotationCols
  36. def getLazyAnnotator: Boolean
    Definition Classes
    CanBeLazy
  37. final def getOrDefault[T](param: Param[T]): T
    Definition Classes
    Params
  38. final def getOutputCol: String
    Definition Classes
    HasOutputAnnotationCol
  39. def getParam(paramName: String): Param[Any]
    Definition Classes
    Params
  40. def getStaticObfuscationPairsResource: ExternalResource
    Definition Classes
    DeidApproachParams
  41. final def hasDefault[T](param: Param[T]): Boolean
    Definition Classes
    Params
  42. def hasParam(paramName: String): Boolean
    Definition Classes
    Params
  43. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  44. def initializeLogIfNecessary(isInterpreter: Boolean, silent: Boolean): Boolean
    Attributes
    protected
    Definition Classes
    Logging
  45. def initializeLogIfNecessary(isInterpreter: Boolean): Unit
    Attributes
    protected
    Definition Classes
    Logging
  46. val inputAnnotatorTypes: Array[String]
    Definition Classes
    NameChunkObfuscatorApproach → HasInputAnnotationCols
  47. final val inputCols: StringArrayParam
    Attributes
    protected
    Definition Classes
    HasInputAnnotationCols
  48. final def isDefined(param: Param[_]): Boolean
    Definition Classes
    Params
  49. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  50. final def isSet(param: Param[_]): Boolean
    Definition Classes
    Params
  51. def isTraceEnabled(): Boolean
    Attributes
    protected
    Definition Classes
    Logging
  52. val language: Param[String]

    The language used to select some faker names The values are the following: 'en'(English), 'de'(German), 'es'(Spanish), 'fr'(French), 'ar'(Arabic) or 'ro'(Romanian).

    The language used to select some faker names The values are the following: 'en'(English), 'de'(German), 'es'(Spanish), 'fr'(French), 'ar'(Arabic) or 'ro'(Romanian). Default:'en'

    Definition Classes
    NameChunkObfuscatorParams
  53. val lazyAnnotator: BooleanParam
    Definition Classes
    CanBeLazy
  54. def loadThreeInputResource(er: ExternalResource): Array[StaticObfuscationEntity]
    Attributes
    protected
    Definition Classes
    DeidApproachParams
  55. def log: Logger
    Attributes
    protected
    Definition Classes
    Logging
  56. def logDebug(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  57. def logDebug(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  58. def logError(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  59. def logError(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  60. def logInfo(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  61. def logInfo(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  62. def logName: String
    Attributes
    protected
    Definition Classes
    Logging
  63. def logTrace(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  64. def logTrace(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  65. def logWarning(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  66. def logWarning(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  67. def msgHelper(schema: StructType): String
    Attributes
    protected
    Definition Classes
    HasInputAnnotationCols
  68. val nameEntities: StringArrayParam

    The nameEntities used to select entities during obfuscation.

    The nameEntities used to select entities during obfuscation. The supported name entities are NAME, PATIENT, and DOCTOR. Default: NAME

    Definition Classes
    NameChunkObfuscatorParams
  69. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  70. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  71. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  72. val obfuscateRefFile: Param[String]

    File with the terms to be used for Obfuscation

    File with the terms to be used for Obfuscation

    Definition Classes
    DeidApproachParams
  73. val obfuscateRefSource: Param[String]

    The source of obfuscation to obfuscate the names.

    The source of obfuscation to obfuscate the names. The values are the following: "file": Takes the names from the obfuscatorRefFile. "faker": Takes the names from the Faker module. "both": Takes the names from the obfuscatorRefFile and the faker module randomly. Default: "both"

    Definition Classes
    NameChunkObfuscatorParams
  74. def onTrained(model: NameChunkObfuscator, spark: SparkSession): Unit
    Definition Classes
    AnnotatorApproach
  75. val optionalInputAnnotatorTypes: Array[String]
    Definition Classes
    HasInputAnnotationCols
  76. val outputAnnotatorType: AnnotatorType
    Definition Classes
    NameChunkObfuscatorApproach → HasOutputAnnotatorType
  77. final val outputCol: Param[String]
    Attributes
    protected
    Definition Classes
    HasOutputAnnotationCol
  78. lazy val params: Array[Param[_]]
    Definition Classes
    Params
  79. val refFileFormat: Param[String]

    Format of the reference file for Obfuscation the default value for that is "csv"

    Format of the reference file for Obfuscation the default value for that is "csv"

    Definition Classes
    DeidApproachParams
  80. val refSep: Param[String]

    Separator character for the csv reference file for Obfuscation de default value is "#"

    Separator character for the csv reference file for Obfuscation de default value is "#"

    Definition Classes
    DeidApproachParams
  81. val sameLength: BooleanParam

    The sameLength used to select the same length names as original ones during obfuscation.

    The sameLength used to select the same length names as original ones during obfuscation. Example: 'John' --> 'Mike'. Default: true

    Definition Classes
    NameChunkObfuscatorParams
  82. def save(path: String): Unit
    Definition Classes
    MLWritable
    Annotations
    @Since( "1.6.0" ) @throws( ... )
  83. val seed: IntParam

    It is the seed to select the names.With the seed you can reply an execution several times with the same output.

    It is the seed to select the names.With the seed you can reply an execution several times with the same output.

    Definition Classes
    NameChunkObfuscatorParams
  84. final def set(paramPair: ParamPair[_]): NameChunkObfuscatorApproach.this.type
    Attributes
    protected
    Definition Classes
    Params
  85. final def set(param: String, value: Any): NameChunkObfuscatorApproach.this.type
    Attributes
    protected
    Definition Classes
    Params
  86. final def set[T](param: Param[T], value: T): NameChunkObfuscatorApproach.this.type
    Definition Classes
    Params
  87. final def setDefault(paramPairs: ParamPair[_]*): NameChunkObfuscatorApproach.this.type
    Attributes
    protected
    Definition Classes
    Params
  88. final def setDefault[T](param: Param[T], value: T): NameChunkObfuscatorApproach.this.type
    Attributes
    protected[org.apache.spark.ml]
    Definition Classes
    Params
  89. def setExtraInputCols(value: Array[String]): NameChunkObfuscatorApproach.this.type
    Definition Classes
    HasInputAnnotationCols
  90. def setGenderAwareness(value: Boolean): NameChunkObfuscatorApproach.this.type

    Whether to use gender-aware names or not during obfuscation.

    Whether to use gender-aware names or not during obfuscation. This param effects only names. If value is true, it might decrease performance. Default: False

    Definition Classes
    NameChunkObfuscatorParams
  91. final def setInputCols(value: String*): NameChunkObfuscatorApproach.this.type
    Definition Classes
    HasInputAnnotationCols
  92. def setInputCols(value: Array[String]): NameChunkObfuscatorApproach.this.type
    Definition Classes
    HasInputAnnotationCols
  93. def setLanguage(s: String): NameChunkObfuscatorApproach.this.type

    The language used to select some faker names.

    The language used to select some faker names. The values are the following: 'en'(English), 'de'(German), 'es'(Spanish), 'fr'(French), 'ar'(Arabic) or 'ro'(Romanian). Default:'en'

    Definition Classes
    NameChunkObfuscatorParams
  94. def setLazyAnnotator(value: Boolean): NameChunkObfuscatorApproach.this.type
    Definition Classes
    CanBeLazy
  95. def setNameEntities(value: Array[String]): NameChunkObfuscatorApproach.this.type

    The nameEntities used to select entities during obfuscation.

    The nameEntities used to select entities during obfuscation. The supported name entities are NAME, PATIENT, and DOCTOR. Default: NAME

    Definition Classes
    NameChunkObfuscatorParams
  96. def setObfuscateRefFile(f: String): NameChunkObfuscatorApproach.this.type

    File with the terms to be used for Obfuscation

    File with the terms to be used for Obfuscation

    Definition Classes
    DeidApproachParams
  97. def setObfuscateRefSource(s: String): NameChunkObfuscatorApproach.this.type

    The source of obfuscation to obfuscate the names.

    The source of obfuscation to obfuscate the names. The values are the following: "file": Takes the names from the obfuscatorRefFile. "faker": Takes the names from the Faker module. "both": Takes the names from the obfuscatorRefFile and the faker module randomly. Default: "both"

    Definition Classes
    NameChunkObfuscatorParams
  98. final def setOutputCol(value: String): NameChunkObfuscatorApproach.this.type
    Definition Classes
    HasOutputAnnotationCol
  99. def setRefFileFormat(f: String): NameChunkObfuscatorApproach.this.type

    File with the terms to be used for Obfuscation

    File with the terms to be used for Obfuscation

    Definition Classes
    DeidApproachParams
  100. def setRefSep(f: String): NameChunkObfuscatorApproach.this.type

    Separator character for the csv reference file for Obfuscation de default value is "#"

    Separator character for the csv reference file for Obfuscation de default value is "#"

    Definition Classes
    DeidApproachParams
  101. def setSameLength(value: Boolean): NameChunkObfuscatorApproach.this.type

    The sameLength used to select the same length names as original ones during obfuscation.

    The sameLength used to select the same length names as original ones during obfuscation. Example: 'John' --> 'Mike'. Default: true

    Definition Classes
    NameChunkObfuscatorParams
  102. def setSeed(s: Int): NameChunkObfuscatorApproach.this.type

    It is the seed to select the names.With the seed you can reply an execution several times with the same output.

    It is the seed to select the names.With the seed you can reply an execution several times with the same output.

    Definition Classes
    NameChunkObfuscatorParams
  103. def setStaticObfuscationPairsResource(path: String, readAs: Format, options: Map[String, String] = ...): NameChunkObfuscatorApproach.this.type

    Sets the static obfuscation pairs resource using a path and readAs format.

    Sets the static obfuscation pairs resource using a path and readAs format. The resource should contain three columns: original, entity, and fake. The delimiter for the columns can be specified in the options.

    path

    The path to the resource.

    readAs

    The format to read the resource (e.g., TEXT, SPARK).

    options

    Additional options for reading the resource, such as "format" and "delimiter". 'delimiter' and 'format' are required options.

    Definition Classes
    DeidApproachParams
  104. def setStaticObfuscationPairsResource(value: ExternalResource): NameChunkObfuscatorApproach.this.type

    Sets the static obfuscation pairs resource.

    Sets the static obfuscation pairs resource. The resource should contain three columns: original, entity, and fake. The delimiter for the columns can be specified in the options. The options must include a 'delimiter' key.

    Definition Classes
    DeidApproachParams
  105. val staticObfuscationPairsResource: ExternalResourceParam

    Resource containing static obfuscation pairs.

    Resource containing static obfuscation pairs. The resource should contain three columns: original, entity, and fake. The delimiter for the columns can be specified in the options.

    Definition Classes
    DeidApproachParams
  106. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  107. def toString(): String
    Definition Classes
    Identifiable → AnyRef → Any
  108. def train(dataset: Dataset[_], recursivePipeline: Option[PipelineModel]): NameChunkObfuscator
    Definition Classes
    NameChunkObfuscatorApproach → AnnotatorApproach
  109. final def transformSchema(schema: StructType): StructType
    Definition Classes
    AnnotatorApproach → PipelineStage
  110. def transformSchema(schema: StructType, logging: Boolean): StructType
    Attributes
    protected
    Definition Classes
    PipelineStage
    Annotations
    @DeveloperApi()
  111. val uid: String
    Definition Classes
    NameChunkObfuscatorApproach → Identifiable
  112. def validate(schema: StructType): Boolean
    Attributes
    protected
    Definition Classes
    AnnotatorApproach
  113. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  114. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  115. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  116. def write: MLWriter
    Definition Classes
    DefaultParamsWritable → MLWritable

Inherited from CheckLicense

Inherited from DeidApproachParams

Inherited from NameChunkObfuscatorParams

Inherited from AnnotatorApproach[NameChunkObfuscator]

Inherited from CanBeLazy

Inherited from DefaultParamsWritable

Inherited from MLWritable

Inherited from HasOutputAnnotatorType

Inherited from HasOutputAnnotationCol

Inherited from HasInputAnnotationCols

Inherited from Estimator[NameChunkObfuscator]

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

Members

Parameter setters