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]): Unit
    Definition Classes
    CheckLicense
  10. def checkValidScope(scope: String): Unit
    Definition Classes
    CheckLicense
  11. def checkValidScopeAndEnvironment(scope: String, spark: Option[SparkSession], checkLp: Boolean): Unit
    Definition Classes
    CheckLicense
  12. def checkValidScopesAndEnvironment(scopes: Seq[String], spark: Option[SparkSession], checkLp: Boolean): 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 def extractParamMap(): ParamMap
    Definition Classes
    Params
  24. final def extractParamMap(extra: ParamMap): ParamMap
    Definition Classes
    Params
  25. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  26. final def fit(dataset: Dataset[_]): NameChunkObfuscator
    Definition Classes
    AnnotatorApproach → Estimator
  27. def fit(dataset: Dataset[_], paramMaps: Seq[ParamMap]): Seq[NameChunkObfuscator]
    Definition Classes
    Estimator
    Annotations
    @Since( "2.0.0" )
  28. def fit(dataset: Dataset[_], paramMap: ParamMap): NameChunkObfuscator
    Definition Classes
    Estimator
    Annotations
    @Since( "2.0.0" )
  29. def fit(dataset: Dataset[_], firstParamPair: ParamPair[_], otherParamPairs: ParamPair[_]*): NameChunkObfuscator
    Definition Classes
    Estimator
    Annotations
    @Since( "2.0.0" ) @varargs()
  30. 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
  31. final def get[T](param: Param[T]): Option[T]
    Definition Classes
    Params
  32. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  33. final def getDefault[T](param: Param[T]): Option[T]
    Definition Classes
    Params
  34. def getInputCols: Array[String]
    Definition Classes
    HasInputAnnotationCols
  35. def getLazyAnnotator: Boolean
    Definition Classes
    CanBeLazy
  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. final def hasDefault[T](param: Param[T]): Boolean
    Definition Classes
    Params
  40. def hasParam(paramName: String): Boolean
    Definition Classes
    Params
  41. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  42. def initializeLogIfNecessary(isInterpreter: Boolean, silent: Boolean): Boolean
    Attributes
    protected
    Definition Classes
    Logging
  43. def initializeLogIfNecessary(isInterpreter: Boolean): Unit
    Attributes
    protected
    Definition Classes
    Logging
  44. val inputAnnotatorTypes: Array[String]
    Definition Classes
    NameChunkObfuscatorApproach → HasInputAnnotationCols
  45. final val inputCols: StringArrayParam
    Attributes
    protected
    Definition Classes
    HasInputAnnotationCols
  46. final def isDefined(param: Param[_]): Boolean
    Definition Classes
    Params
  47. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  48. final def isSet(param: Param[_]): Boolean
    Definition Classes
    Params
  49. def isTraceEnabled(): Boolean
    Attributes
    protected
    Definition Classes
    Logging
  50. 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
  51. val lazyAnnotator: BooleanParam
    Definition Classes
    CanBeLazy
  52. def log: Logger
    Attributes
    protected
    Definition Classes
    Logging
  53. def logDebug(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  54. def logDebug(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  55. def logError(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  56. def logError(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  57. def logInfo(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  58. def logInfo(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  59. def logName: String
    Attributes
    protected
    Definition Classes
    Logging
  60. def logTrace(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  61. def logTrace(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  62. def logWarning(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  63. def logWarning(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  64. def msgHelper(schema: StructType): String
    Attributes
    protected
    Definition Classes
    HasInputAnnotationCols
  65. 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
  66. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  67. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  68. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  69. 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
  70. 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
  71. def onTrained(model: NameChunkObfuscator, spark: SparkSession): Unit
    Definition Classes
    AnnotatorApproach
  72. val optionalInputAnnotatorTypes: Array[String]
    Definition Classes
    HasInputAnnotationCols
  73. val outputAnnotatorType: AnnotatorType
    Definition Classes
    NameChunkObfuscatorApproach → HasOutputAnnotatorType
  74. final val outputCol: Param[String]
    Attributes
    protected
    Definition Classes
    HasOutputAnnotationCol
  75. lazy val params: Array[Param[_]]
    Definition Classes
    Params
  76. 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
  77. 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
  78. 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
  79. def save(path: String): Unit
    Definition Classes
    MLWritable
    Annotations
    @Since( "1.6.0" ) @throws( ... )
  80. 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
  81. final def set(paramPair: ParamPair[_]): NameChunkObfuscatorApproach.this.type
    Attributes
    protected
    Definition Classes
    Params
  82. final def set(param: String, value: Any): NameChunkObfuscatorApproach.this.type
    Attributes
    protected
    Definition Classes
    Params
  83. final def set[T](param: Param[T], value: T): NameChunkObfuscatorApproach.this.type
    Definition Classes
    Params
  84. final def setDefault(paramPairs: ParamPair[_]*): NameChunkObfuscatorApproach.this.type
    Attributes
    protected
    Definition Classes
    Params
  85. final def setDefault[T](param: Param[T], value: T): NameChunkObfuscatorApproach.this.type
    Attributes
    protected[org.apache.spark.ml]
    Definition Classes
    Params
  86. 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
  87. final def setInputCols(value: String*): NameChunkObfuscatorApproach.this.type
    Definition Classes
    HasInputAnnotationCols
  88. def setInputCols(value: Array[String]): NameChunkObfuscatorApproach.this.type
    Definition Classes
    HasInputAnnotationCols
  89. 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
  90. def setLazyAnnotator(value: Boolean): NameChunkObfuscatorApproach.this.type
    Definition Classes
    CanBeLazy
  91. 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
  92. 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
  93. 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
  94. final def setOutputCol(value: String): NameChunkObfuscatorApproach.this.type
    Definition Classes
    HasOutputAnnotationCol
  95. 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
  96. 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
  97. 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
  98. 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
  99. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  100. def toString(): String
    Definition Classes
    Identifiable → AnyRef → Any
  101. def train(dataset: Dataset[_], recursivePipeline: Option[PipelineModel]): NameChunkObfuscator
    Definition Classes
    NameChunkObfuscatorApproach → AnnotatorApproach
  102. final def transformSchema(schema: StructType): StructType
    Definition Classes
    AnnotatorApproach → PipelineStage
  103. def transformSchema(schema: StructType, logging: Boolean): StructType
    Attributes
    protected
    Definition Classes
    PipelineStage
    Annotations
    @DeveloperApi()
  104. val uid: String
    Definition Classes
    NameChunkObfuscatorApproach → Identifiable
  105. def validate(schema: StructType): Boolean
    Attributes
    protected
    Definition Classes
    AnnotatorApproach
  106. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  107. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  108. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  109. 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