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 annotation column name going to generate
Gets annotation column name going to generate
Function used to set the embedding output layer of the ELMO model
Input annotator types : DOCUMENT, TOKEN
Input annotator types : DOCUMENT, TOKEN
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
Output annotator type : WORD_EMBEDDINGS
Output annotator type : WORD_EMBEDDINGS
Set ELMo pooling layer to: "word_emb"
, "lstm_outputs1"
, "lstm_outputs2"
, or "elmo"
(Default: "word_emb"
).
Set ELMo pooling layer to: "word_emb"
, "lstm_outputs1"
, "lstm_outputs2"
, or "elmo"
(Default: "word_emb"
).
Possible values are:
"word_emb"
: the character-based word representations with shape [batch_size, max_length, 512]."lstm_outputs1"
: the first LSTM hidden state with shape [batch_size, max_length, 1024]."lstm_outputs2"
: the second LSTM hidden state with shape [batch_size, max_length, 1024]."elmo"
: the weighted sum of the 3 layers, where the weights are trainable. This tensor has shape [batch_size, max_length, 1024]
Large values allows faster processing but requires more memory.
ConfigProto from tensorflow, serialized into byte array.
ConfigProto from tensorflow, serialized into byte array. Get with config_proto.SerializeToString()
Set Dimension of pooling layer.
Set Dimension of pooling layer. This is meta for the annotation and will not affect the actual embedding calculation.
Overrides required annotators column if different than default
Overrides required annotators column if different than default
Overrides annotation column name when transforming
Overrides annotation column name when transforming
Function used to set the embedding output layer of the ELMO model
Function used to set the embedding output layer of the ELMO model
Layer specification
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 uid for storing annotator to disk
required uid for storing annotator to disk
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
Word embeddings from ELMo (Embeddings from Language Models), a language model trained on the 1 Billion Word Benchmark.
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.
Pretrained models can be loaded with
pretrained
of the companion object:The default model is
"elmo"
, if no name is provided.For available pretrained models please see the Models Hub.
The pooling layer can be set with
setPoolingLayer
to the following values:"word_emb"
: the character-based word representations with shape[batch_size, max_length, 512]
."lstm_outputs1"
: the first LSTM hidden state with shape[batch_size, max_length, 1024]
."lstm_outputs2"
: the second LSTM hidden state with shape[batch_size, max_length, 1024]
."elmo"
: the weighted sum of the 3 layers, where the weights are trainable. This tensor has shape[batch_size, max_length, 1024]
.For extended examples of usage, see the Spark NLP Workshop and the ElmoEmbeddingsTestSpec.
Sources:
https://tfhub.dev/google/elmo/3
Deep contextualized word representations
Paper abstract:
We introduce a new type of deep contextualized word representation that models both (1) complex characteristics of word use (e.g., syntax and semantics), and (2) how these uses vary across linguistic contexts (i.e., to model polysemy). Our word vectors are learned functions of the internal states of a deep bidirectional language model (biLM), which is pre-trained on a large text corpus. We show that these representations can be easily added to existing models and significantly improve the state of the art across six challenging NLP problems, including question answering, textual entailment and sentiment analysis. We also present an analysis showing that exposing the deep internals of the pre-trained network is crucial, allowing downstream models to mix different types of semi-supervision signals.
Example
Annotators Main Page for a list of other transformer based embeddings