ALBERT Sequence Classification Base - AG News (albert_base_sequence_classifier_ag_news)

Description

ALBERT Model with sequence classification/regression head on top (a linear layer on top of the pooled output) e.g. for multi-class document classification tasks.

albert_base_sequence_classifier_ag_news is a fine-tuned ALBERT model that is ready to be used for Sequence Classification tasks such as sentiment analysis or multi-class text classification and it achieves state-of-the-art performance.

We used TFAlbertForSequenceClassification to train this model and used AlbertForSequenceClassification annotator in Spark NLP 🚀 for prediction at scale!

Predicted Entities

Business, Sci/Tech, Sports, World

Download Copy S3 URI

How to use

document_assembler = DocumentAssembler() \
.setInputCol('text') \
.setOutputCol('document')

tokenizer = Tokenizer() \
.setInputCols(['document']) \
.setOutputCol('token')

sequenceClassifier = AlbertForSequenceClassification \
.pretrained('albert_base_sequence_classifier_ag_news', 'en') \
.setInputCols(['token', 'document']) \
.setOutputCol('class') \
.setCaseSensitive(False) \
.setMaxSentenceLength(512)

pipeline = Pipeline(stages=[
document_assembler, 
tokenizer,
sequenceClassifier    
])

example = spark.createDataFrame([['Disney Comics was a comic book publishing company operated by The Walt Disney Company which ran from 1990 to 1993.']]).toDF("text")
result = pipeline.fit(example).transform(example)
val document_assembler = DocumentAssembler() 
.setInputCol("text") 
.setOutputCol("document")

val tokenizer = Tokenizer() 
.setInputCols("document") 
.setOutputCol("token")

val tokenClassifier = AlbertForSequenceClassification.pretrained("albert_base_sequence_classifier_ag_news", "en")
.setInputCols("document", "token")
.setOutputCol("class")
.setCaseSensitive(false)
.setMaxSentenceLength(512)

val pipeline = new Pipeline().setStages(Array(document_assembler, tokenizer, sequenceClassifier))

val example = Seq("Disney Comics was a comic book publishing company operated by The Walt Disney Company which ran from 1990 to 1993.").toDS.toDF("text")

val result = pipeline.fit(example).transform(example)

import nlu
nlu.load("en.classify.albert.ag_news").predict("""Disney Comics was a comic book publishing company operated by The Walt Disney Company which ran from 1990 to 1993.""")

Model Information

Model Name: albert_base_sequence_classifier_ag_news
Compatibility: Spark NLP 3.4.0+
License: Open Source
Edition: Official
Input Labels: [token, document]
Output Labels: [ner]
Language: en
Size: 44.9 MB
Case sensitive: false
Max sentense length: 512

Data Source

https://huggingface.co/datasets/ag_news

Benchmarking

{
	"eval_loss": 0.18820451200008392,
	"eval_accuracy": 0.9472368421052632,
	"eval_f1": 0.9472368421052632,
	"eval_precision": 0.9472368421052632,
	"eval_recall": 0.9472368421052632,
	"eval_runtime": 52.2405,
	"eval_samples_per_second": 145.481,
	"eval_steps_per_second": 4.556,
	"epoch": 3.0
}