Sentiment Analysis of Italian texts

Description

This model was imported from Hugging Face and it’s been fine-tuned for Italian language, leveraging Bert embeddings and BertForSequenceClassification for text classification purposes.

Predicted Entities

negative, positive, neutral

Download Copy S3 URI

How to use

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

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

sequenceClassifier = BertForSequenceClassification \
      .pretrained('bert_sequence_classifier_sentiment', 'it') \
      .setInputCols(['token', 'document']) \
      .setOutputCol('class')

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

example = spark.createDataFrame([['Ho mal di testa e mi sento male.']]).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 = BertForSequenceClassification.pretrained("bert_sequence_classifier_sentiment", "it")
      .setInputCols("document", "token")
      .setOutputCol("class")

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

val example = Seq.empty["Ho mal di testa e mi sento male."].toDS.toDF("text")

val result = pipeline.fit(example).transform(example)
import nlu
nlu.load("it.classify.sentiment").predict("""Ho mal di testa e mi sento male.""")

Results

['negative']

Model Information

Model Name: bert_sequence_classifier_sentiment
Compatibility: Spark NLP 3.3.4+
License: Open Source
Edition: Official
Input Labels: [document, token]
Output Labels: [class]
Language: it
Size: 415.5 MB
Case sensitive: true
Max sentense length: 512

Data Source

https://huggingface.co/neuraly/bert-base-italian-cased-sentiment

Benchmarking

label      score
accuracy   0.82