XLNet Embeddings (Large)

Description

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. The details are described in the paper “​XLNet: Generalized Autoregressive Pretraining for Language Understanding

Download Copy S3 URI

How to use

...
embeddings = XlnetEmbeddings.pretrained("xlnet_large_cased", "en") \
.setInputCols("sentence", "token") \
.setOutputCol("embeddings")
nlp_pipeline = Pipeline(stages=[document_assembler, sentence_detector, tokenizer, embeddings])
pipeline_model = nlp_pipeline.fit(spark.createDataFrame([[""]]).toDF("text"))
result = pipeline_model.transform(spark.createDataFrame([['I love NLP']], ["text"]))
...
val embeddings = XlnetEmbeddings.pretrained("xlnet_large_cased", "en")
.setInputCols("sentence", "token")
.setOutputCol("embeddings")
val pipeline = new Pipeline().setStages(Array(document_assembler, sentence_detector, tokenizer, embeddings))
val data = Seq("I love NLP").toDF("text")
val result = pipeline.fit(data).transform(data)
import nlu

text = ["I love NLP"]
embeddings_df = nlu.load('en.embed.xlnet_large_cased').predict(text, output_level='token')
embeddings_df

Results

	token	en_embed_xlnet_large_cased_embeddings
	
	I	[0.9742076396942139, -0.6181889772415161, 0.45...
	love	[-0.7322277426719666, -1.7254987955093384, -0....
	NLP	[1.6873085498809814, -0.8617655038833618, 0.46...

Model Information

Model Name: xlnet_large_cased
Type: embeddings
Compatibility: Spark NLP 2.5.0+
License: Open Source
Edition: Official
Input Labels: [sentence, token]
Output Labels: [word_embeddings]
Language: [en]
Dimension: 1024
Case sensitive: true

Data Source

The model is imported from https://github.com/zihangdai/xlnet