liveBook · Manning

FinBERT-PT-BR

As explained in Starting Data Analytics with Generative AI and Python

FinBERT-PT-BR is a Portuguese sentiment-classification model trained on financial news.

FinBERT-PT-BR is a Portuguese sentiment-classification model trained on financial news. It can help filter positive customer reviews when better-matched Portuguese models are unavailable, but its financial training domain makes the result provisional. section 6.2.5

Treat the model as a screening aid rather than an unquestioned decision-maker:

  • Check predictions against sampled raw reviews, especially sarcasm, cultural expressions, and regional Portuguese. section 6.2.5
  • Use human review and error monitoring to identify shortcomings before relying on filtered results. section 6.2.5
  • Consider computational requirements, model bias, and privacy when processing customer reviews. section 6.2.5
Listing 6.2 Extracting positive reviews with the help of a suboptimal model
import pandas as pd
from transformers import pipeline

# Assuming df is your DataFrame and it has a column named 
'review_comment_message'
# Load the sentiment analysis pipeline with the FinBERT-PT-BR model
classifier = pipeline("sentiment-analysis", 
model="lucas-leme/FinBERT-PT-BR")
def get_sentiment(review):
    try:
        result = classifier(review)[0]
        return result['label'], result['score']
    except Exception as e:
        print(f"Error processing review: {e}")
        return None, None
# Apply the sentiment analysis to each review
df['sentiment'], df['score'] = 
zip(*df['review_comment_message'].map(get_sentiment))
# Filter the DataFrame to only include positive reviews
positive_reviews_df = df[df['sentiment'] == 'LABEL_1']   
# Assuming 'LABEL_1' is positive; adjust label as necessary based on model
output
# Now positive_reviews_df contains only the positive reviews

A pandas and Transformers workflow applies the classifier to review_comment_message, stores labels and scores, and filters an assumed positive LABEL_1. section 6.2.5

How Starting Data Analytics with Generative AI and Python covers it

How deep it goes
Provides an executable classification workflow and limitations, but stops short of proving suitability for customer-review sentiment.
Examples
Uses a review_comment_message column, sentiment labels, confidence scores, and a filtered positive_reviews_df dataframe.
What it assumes
Assumes Portuguese review data in a pandas dataframe and basic Python familiarity with model pipelines.
What you can do after
Apply it via Transformers to label reviews, inspect scores, and extract records assigned a positive label.
How it connects
Connects sentiment analysis with customer reviews, human-in-the-loop review, error monitoring, and transformer-based models.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Starting Data Analytics with Generative AI and Python. The section links point to the parts of the book it draws on.