com.johnsnowlabs.nlp.embeddings
internal types to show Rows as a relevant StructType Should be deleted once Spark releases UserDefinedTypes to @developerAPI
internal types to show Rows as a relevant StructType Should be deleted once Spark releases UserDefinedTypes to @developerAPI
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 that correspond to inputAnnotationCols generated by previous annotators if any
any number of annotations processed for every input annotation. Not necessary one to one relationship
Batch size (Default: 32
).
Batch size (Default: 32
). Large values allows faster processing but requires more memory.
Whether to ignore case in index lookups (Default depends on model)
Whether to ignore case in index lookups (Default depends on model)
ConfigProto from tensorflow, serialized into byte array.
ConfigProto from tensorflow, serialized into byte array. Get with config_proto.SerializeToString()
requirement for annotators copies
requirement for annotators copies
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
udf function to be applied to inputCols using this annotator's annotate function as part of ML transformation
Number of embedding dimensions (Default depends on model)
Number of embedding dimensions (Default depends on model)
Override for additional custom schema checks
Override for additional custom schema checks
input annotations columns currently used
Gets XLNet tensorflow Model
Gets annotation column name going to generate
Gets annotation column name going to generate
Input Annotator Type : TOKEN, DOCUMENT
Input Annotator Type : TOKEN, DOCUMENT
columns that contain annotations necessary to run this annotator AnnotatorType is used both as input and output columns if not specified
columns that contain annotations necessary to run this annotator AnnotatorType is used both as input and output columns if not specified
Max sentence length to process (Default: 128
)
Output Annotator Type : WORD_EMBEDDINGS
Output Annotator Type : WORD_EMBEDDINGS
Set dimension of Embeddings Since output shape depends on the model selected, see https://github.com/zihangdai/xlnetfor further reference
Set dimension of Embeddings Since output shape depends on the model selected, see https://github.com/zihangdai/xlnetfor further reference
Overrides required annotators column if different than default
Overrides required annotators column if different than default
Sets XLNet tensorflow Model
Overrides annotation column name when transforming
Overrides annotation column name when transforming
Unique identifier for storage (Default: this.uid
)
Unique identifier for storage (Default: this.uid
)
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[Row]
requirement for pipeline transformation validation.
requirement for pipeline transformation validation. It is called on fit()
required internal uid for saving annotator
required internal uid for saving annotator
takes a Dataset and checks to see if all the required annotation types are present.
takes a Dataset and checks to see if all the required annotation types are present.
to be validated
True if all the required types are present, else false
A list of (hyper-)parameter keys this annotator can take. Users can set and get the parameter values through setters and getters, respectively.
Required input and expected output annotator types
XlnetEmbeddings (XLNet): Generalized Autoregressive Pretraining for Language Understanding
XLNet is a new unsupervised language representation learning method based on a novel generalized permutation language modeling objective. Additionally, XLNet employs Transformer-XL as the backbone model, exhibiting excellent performance for language tasks involving long context. Overall, XLNet achieves state-of-the-art (SOTA) results on various downstream language tasks including question answering, natural language inference, sentiment analysis, and document ranking.
These word embeddings represent the outputs generated by the XLNet models.
Note that this is a very computationally expensive module compared to word embedding modules that only perform embedding lookups. The use of an accelerator is recommended.
"xlnet_large_cased"
= XLNet-Large | 24-layer, 1024-hidden, 16-heads"xlnet_base_cased"
= XLNet-Base | 12-layer, 768-hidden, 12-heads. This model is trained on full data (different from the one in the paper).Pretrained models can be loaded with
pretrained
of the companion object:The default model is
"xlnet_base_cased"
, if no name is provided.For extended examples of usage, see the Spark NLP Workshop and the XlnetEmbeddingsTestSpec.
Sources :
XLNet: Generalized Autoregressive Pretraining for Language Understanding
https://github.com/zihangdai/xlnet
Paper abstract:
With the capability of modeling bidirectional contexts, denoising autoencoding based pretraining like BERT achieves better performance than pretraining approaches based on autoregressive language modeling. However, relying on corrupting the input with masks, BERT neglects dependency between the masked positions and suffers from a pretrain-finetune discrepancy. In light of these pros and cons, we propose XLNet, a generalized autoregressive pretraining method that (1) enables learning bidirectional contexts by maximizing the expected likelihood over all permutations of the factorization order and (2) overcomes the limitations of BERT thanks to its autoregressive formulation. Furthermore, XLNet integrates ideas from Transformer-XL, the state-of-the-art autoregressive model, into pretraining. Empirically, under comparable experiment settings, XLNet outperforms BERT on 20 tasks, often by a large margin, including question answering, natural language inference, sentiment analysis, and document ranking.
Example
Annotators Main Page for a list of transformer based embeddings