class NerConverter extends AnnotatorModel[NerConverter] with HasSimpleAnnotate[NerConverter]
Converts a IOB or IOB2 representation of NER to a user-friendly one, by associating the tokens
of recognized entities and their label. Results in CHUNK
Annotation type.
NER chunks can then be filtered by setting a whitelist with setWhiteList
. Chunks with no
associated entity (tagged "O") are filtered.
See also Inside–outside–beginning (tagging) for more information.
Example
This is a continuation of the example of the NerDLModel. See that class on how to extract the entities.
The output of the NerDLModel follows the Annotator schema and can be converted like so:
result.selectExpr("explode(ner)").show(false) +----------------------------------------------------+ |col | +----------------------------------------------------+ |[named_entity, 0, 2, B-ORG, [word -> U.N], []] | |[named_entity, 3, 3, O, [word -> .], []] | |[named_entity, 5, 12, O, [word -> official], []] | |[named_entity, 14, 18, B-PER, [word -> Ekeus], []] | |[named_entity, 20, 24, O, [word -> heads], []] | |[named_entity, 26, 28, O, [word -> for], []] | |[named_entity, 30, 36, B-LOC, [word -> Baghdad], []]| |[named_entity, 37, 37, O, [word -> .], []] | +----------------------------------------------------+
After the converter is used:
val converter = new NerConverter() .setInputCols("sentence", "token", "ner") .setOutputCol("entities") .setPreservePosition(false) converter.transform(result).selectExpr("explode(entities)").show(false) +------------------------------------------------------------------------+ |col | +------------------------------------------------------------------------+ |[chunk, 0, 2, U.N, [entity -> ORG, sentence -> 0, chunk -> 0], []] | |[chunk, 14, 18, Ekeus, [entity -> PER, sentence -> 0, chunk -> 1], []] | |[chunk, 30, 36, Baghdad, [entity -> LOC, sentence -> 0, chunk -> 2], []]| +------------------------------------------------------------------------+
- Grouped
- Alphabetic
- By Inheritance
- NerConverter
- HasSimpleAnnotate
- AnnotatorModel
- CanBeLazy
- RawAnnotator
- HasOutputAnnotationCol
- HasInputAnnotationCols
- HasOutputAnnotatorType
- ParamsAndFeaturesWritable
- HasFeatures
- DefaultParamsWritable
- MLWritable
- Model
- Transformer
- PipelineStage
- Logging
- Params
- Serializable
- Serializable
- Identifiable
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Parameters
A list of (hyper-)parameter keys this annotator can take. Users can set and get the parameter values through setters and getters, respectively.
-
val
nerHasNoSchema: BooleanParam
set this to true if your NER tags coming from a model that does not have a IOB/IOB2 schema
-
val
preservePosition: BooleanParam
Whether to preserve the original position of the tokens in the original document or use the modified tokens (Default:
true
) -
val
whiteList: StringArrayParam
If defined, list of entities to process.
If defined, list of entities to process. The rest will be ignored. Do not include IOB prefix on labels
Annotator types
Required input and expected output annotator types
-
val
inputAnnotatorTypes: Array[String]
Input Annotator Type : DOCUMENT, TOKEN, NAMED_ENTITY
Input Annotator Type : DOCUMENT, TOKEN, NAMED_ENTITY
- Definition Classes
- NerConverter → HasInputAnnotationCols
-
val
outputAnnotatorType: AnnotatorType
Output Annotator Type : CHUNK
Output Annotator Type : CHUNK
- Definition Classes
- NerConverter → HasOutputAnnotatorType
Members
-
type
AnnotatorType = String
- Definition Classes
- HasOutputAnnotatorType
-
def
annotate(annotations: Seq[Annotation]): Seq[Annotation]
takes a document and annotations and produces new annotations of this annotator's annotation type
takes a document and annotations and produces new annotations of this annotator's annotation type
- annotations
Annotations that correspond to inputAnnotationCols generated by previous annotators if any
- returns
any number of annotations processed for every input annotation. Not necessary one to one relationship
- Definition Classes
- NerConverter → HasSimpleAnnotate
-
final
def
clear(param: Param[_]): NerConverter.this.type
- Definition Classes
- Params
-
def
copy(extra: ParamMap): NerConverter
requirement for annotators copies
requirement for annotators copies
- Definition Classes
- RawAnnotator → Model → Transformer → PipelineStage → Params
-
def
dfAnnotate: UserDefinedFunction
Wraps annotate to happen inside SparkSQL user defined functions in order to act with org.apache.spark.sql.Column
Wraps annotate to happen inside SparkSQL user defined functions in order to act with org.apache.spark.sql.Column
- returns
udf function to be applied to inputCols using this annotator's annotate function as part of ML transformation
- Definition Classes
- HasSimpleAnnotate
-
def
explainParam(param: Param[_]): String
- Definition Classes
- Params
-
def
explainParams(): String
- Definition Classes
- Params
-
final
def
extractParamMap(): ParamMap
- Definition Classes
- Params
-
final
def
extractParamMap(extra: ParamMap): ParamMap
- Definition Classes
- Params
-
val
features: ArrayBuffer[Feature[_, _, _]]
- Definition Classes
- HasFeatures
-
final
def
get[T](param: Param[T]): Option[T]
- Definition Classes
- Params
-
final
def
getDefault[T](param: Param[T]): Option[T]
- Definition Classes
- Params
-
def
getInputCols: Array[String]
- returns
input annotations columns currently used
- Definition Classes
- HasInputAnnotationCols
-
def
getLazyAnnotator: Boolean
- Definition Classes
- CanBeLazy
-
final
def
getOrDefault[T](param: Param[T]): T
- Definition Classes
- Params
-
final
def
getOutputCol: String
Gets annotation column name going to generate
Gets annotation column name going to generate
- Definition Classes
- HasOutputAnnotationCol
-
def
getParam(paramName: String): Param[Any]
- Definition Classes
- Params
-
final
def
hasDefault[T](param: Param[T]): Boolean
- Definition Classes
- Params
-
def
hasParam(paramName: String): Boolean
- Definition Classes
- Params
-
def
hasParent: Boolean
- Definition Classes
- Model
-
final
def
isDefined(param: Param[_]): Boolean
- Definition Classes
- Params
-
final
def
isSet(param: Param[_]): Boolean
- Definition Classes
- Params
-
val
lazyAnnotator: BooleanParam
- Definition Classes
- CanBeLazy
-
val
optionalInputAnnotatorTypes: Array[String]
- Definition Classes
- HasInputAnnotationCols
-
lazy val
params: Array[Param[_]]
- Definition Classes
- Params
-
var
parent: Estimator[NerConverter]
- Definition Classes
- Model
-
def
save(path: String): Unit
- Definition Classes
- MLWritable
- Annotations
- @Since( "1.6.0" ) @throws( ... )
-
final
def
set[T](param: Param[T], value: T): NerConverter.this.type
- Definition Classes
- Params
-
final
def
setInputCols(value: String*): NerConverter.this.type
- Definition Classes
- HasInputAnnotationCols
-
def
setInputCols(value: Array[String]): NerConverter.this.type
Overrides required annotators column if different than default
Overrides required annotators column if different than default
- Definition Classes
- HasInputAnnotationCols
-
def
setLazyAnnotator(value: Boolean): NerConverter.this.type
- Definition Classes
- CanBeLazy
-
final
def
setOutputCol(value: String): NerConverter.this.type
Overrides annotation column name when transforming
Overrides annotation column name when transforming
- Definition Classes
- HasOutputAnnotationCol
-
def
setParent(parent: Estimator[NerConverter]): NerConverter
- Definition Classes
- Model
-
def
toString(): String
- Definition Classes
- Identifiable → AnyRef → Any
-
final
def
transform(dataset: Dataset[_]): DataFrame
Given requirements are met, this applies ML transformation within a Pipeline or stand-alone Output annotation will be generated as a new column, previous annotations are still available separately metadata is built at schema level to record annotations structural information outside its content
Given requirements are met, this applies ML transformation within a Pipeline or stand-alone Output annotation will be generated as a new column, previous annotations are still available separately metadata is built at schema level to record annotations structural information outside its content
- dataset
Dataset[Row]
- Definition Classes
- AnnotatorModel → Transformer
-
def
transform(dataset: Dataset[_], paramMap: ParamMap): DataFrame
- Definition Classes
- Transformer
- Annotations
- @Since( "2.0.0" )
-
def
transform(dataset: Dataset[_], firstParamPair: ParamPair[_], otherParamPairs: ParamPair[_]*): DataFrame
- Definition Classes
- Transformer
- Annotations
- @Since( "2.0.0" ) @varargs()
-
final
def
transformSchema(schema: StructType): StructType
requirement for pipeline transformation validation.
requirement for pipeline transformation validation. It is called on fit()
- Definition Classes
- RawAnnotator → PipelineStage
-
val
uid: String
- Definition Classes
- NerConverter → Identifiable
-
def
write: MLWriter
- Definition Classes
- ParamsAndFeaturesWritable → DefaultParamsWritable → MLWritable
Parameter setters
- def setNerHasNoSchema(value: Boolean): NerConverter.this.type
-
def
setPreservePosition(value: Boolean): NerConverter.this.type
Whether to preserve the original position of the tokens in the original document or use the modified tokens (Default:
true
) -
def
setWhiteList(list: String*): NerConverter.this.type
If defined, list of entities to process.
If defined, list of entities to process. The rest will be ignored. Do not include IOB prefix on labels