You don't have access to this class

Keep learning! Join and start boosting your career

Aprovecha el precio especial y haz tu profesión a prueba de IA

Antes: $249

Currency
$209
Suscríbete

Termina en:

0 Días
14 Hrs
36 Min
56 Seg

Desarrollo y Prototipado de la Aplicación Empresarialparte 1

14/16
Resources

Artificial intelligence and natural language processing (NLP) have revolutionized the way we analyze textual data. These technologies allow us to extract valuable information from reviews, comments and other text, providing insights that can be crucial for businesses and organizations. In this content, we will explore how to implement a Free Market review analysis system using pre-trained models and advanced NLP techniques.

How to apply sentiment analysis to Mercado Libre reviews?

Product review analysis is a practical and powerful application of natural language processing. Using a graphical interface, we can allow users to load individual reviews or entire datasets to obtain relevant metrics on sentiment and the entities mentioned.

The interface we will develop has two main functionalities:

  • Individual text analysis: allows entering a specific review and obtaining its sentiment analysis and recognized entities.
  • Full dataset analysis: Processes a CSV file with multiple reviews, generating analysis for each one and creating visualizations as wordcloud.

For example, when entering a review such as "I liked the Levis pants I bought in Belgrano", the system identifies that it is a positive comment (Label 1) with 99% certainty, and recognizes entities such as the brand "Levis" and the location "Belgrano".

What components do we need to develop this application?

To implement this solution, we need to install and use several Python libraries:

# Install dependencies!pip install transformers wordcloud wordcloud pandas pillow.

Then, we import the necessary libraries:

import pandas as pdfrom transformers import pipelinefrom wordcloud import WordCloudfrom PIL import Image # To export the word cloud as an image.

The core of our application consists of two NLP pipelines:

  1. Sentiment analysis: using a pre-trained model with fine-tuning to classify reviews.
  2. Entity Recognition (NER): To identify brands, locations and other relevant elements in text.
# Definition of NLP pipelinessentiment_analysis = pipeline("text-classification",  model="tu_modelo_entrenado")ner = pipeline("ner",  model="modelo_para_entidades_en_español")

How do we process and clean the text for analysis?

Text cleaning is essential to obtain accurate results. Unlike other cases, here we will keep the case structure, as it is crucial for the recognition of entities as tags:

def clean_text(text): # Remove bracketed text # Remove URLs # Remove HTML tags # Remove extra spaces    
 # Important: we do NOT convert to lowercase to preserve entities return cleaned_text.

For entity recognition, we need a function that reconstructs the complete entities from the identified tokens:

def reconstruct_entity(ner_results): # Process NER results to obtain complete entities # Return entities in structured format return processed_entities .

How do we implement individual text and dataset analysis?

Our application has two main functions that correspond to the two interface functionalities:

Individual text analysis

def analyze_text(text): # Clean text cleaned_text = clean_text(text)    
 # Get sentiment analysis sentiment = sentiment_analysis(cleaned_text)    
 # Get recognized entities ner_result = ner(cleaned_text) entities = reconstruct_entity(ner_result)    
 # Return structured results return { "sentiment": sentiment, "entities": entities }

CSV dataset analysis

def analyze_csv(csv_file): # Load CSV with pandas df = pd.read_csv(csv_file)    
 # Verify 'ReviewBody' column exists if 'ReviewBody' not in df.columns: return {"error": "CSV must contain a column named 'ReviewBody'"}    
 results = [] all_entities = []    
 # Process each review for review in df['ReviewBody']: cleaned_review = clean_text(review) sentiment = sentiment_analysis(cleaned_review) ner_result = ner(cleaned_review) entities = reconstruct_entity(ner_result)        
 results.append({ "review": review, "sentiment": sentiment, "entities": entities })        
 all_entities.extend(entities)    
 # Generate wordcloud from entities wordcloud = generate_wordcloud(all_entities)    
 return { "results": results, "wordcloud": wordcloud, "file_size": len(df) }

How do we visualize the results with a wordcloud?

An interesting feature of our application is the generation of a wordcloud that visually displays the most frequent entities in the dataset:

def generate_wordcloud(entities): # Create a dictionary of entity frequencies entity_freq = {} for entity in entities: if entity['text'] in entity_freq: entity_freq[entity['text']] += 1 else: entity_freq[entity['text']] = 1    
 # Generate wordcloud wordcloud = WordCloud(width=800, height=400,  background_color='white').generate_from_frequencies(entity_freq)    
 # Save as image wordcloud_image = wordcloud.to_image() return wordcloud_image

This functionality is especially useful to quickly identify the brands most mentioned in the reviews, such as Nike, Adidas, Levi's or Zara, providing an overview of consumer preferences.

The graphical interface we have developed not only allows these analyses to be performed interactively, but also offers the possibility of generating a practical API to integrate these functionalities into other applications.

Product review analysis is just one of the many possible applications of natural language processing in e-commerce. What other applications can you think of for these technologies? Share your ideas and experiences in the comments.

Contributions 2

Questions 0

Sort by:

Want to see more contributions, questions and answers from the community?

NLP, o Procesamiento del Lenguaje Natural, es una rama de la inteligencia artificial que se centra en la interacción entre las computadoras y el lenguaje humano. Su objetivo es permitir a las máquinas entender, interpretar y generar lenguaje de manera que sea valiosa para los usuarios. Esto incluye tareas como análisis de sentimiento, extracción de información y traducción automática. En el contexto de tu curso, aprenderás a aplicar NLP utilizando Python para desarrollar modelos que puedan procesar y analizar texto de manera efectiva.
cada clase de este curso contiene información muy valiosa Felicitaciones Team Platzi