<jupyter_start><jupyter_text>Sentiment Analysis: Data Gathering 1 (Vader)The original sentiments of domain dataset are unclean, especially for the neutral sentiment. Instead of manually going through and correcting sentiments by hand certain techniques are employed to assist this process. This notebook implements the first data annotation pipeline for the sentiment analysis task,  which utilizes NLTK's VADER sentiment classifier in order to quickly get a different baseline sentiment to compare with the original. This process has been performed iteratively by manually inspecting the results and modiying VADER's internal library, which contains pre-defined weights towards certain sentiments. Data used here are texts that have been cleaned from stopwords (see ma_eda_all.ipynb)since certain words / phrases affect the results negatively, e.g. "kind regards", "good day", etc.Data used is also the normalized version in order to better target certain words and update the weights within VADER's vocabulary since some words, e.g. "worn", "hole", etc., are considered more negative in this domain as opposed to what VADER would classify it normally. Notes* Data: feedback_39k* Texts have been removed from certain stopwords that might skew the results of VADER* Using normalized words to better target words* Tuned by updating vocabulary of VADER Goal* Add additional column for VADER sentiments pos/neu/neg Results* Passable results to help with manual tasks* Very different sentiment distributions than original sentiments* Not good if too few words<jupyter_code>import nltk
nltk.download('vader_lexicon')
nltk.download('punkt')
import re
import pandas as pd
import seaborn as sns; sns.set()
from nltk.sentiment.vader import SentimentIntensityAnalyzer

sns.set(style='white', context='notebook', palette='deep')
from google.colab import drive
drive.mount('/content/drive')
PROJECT_PATH = '/content/drive/MyDrive/Colab/data/ma_data/'
DATA = PROJECT_PATH + 'feedback_all_normalized.csv'
DATA_EXPORT = PROJECT_PATH + 'feedback_all_vader_1.csv'
sia = SentimentIntensityAnalyzer()
print(sia.lexicon)
domain_words = {"bruise": -3.0, "pity": -3.0, "thanks": 0.0, "glue": -2.0, "shortcoming": -3.0, "break": -3.0, "inflamed": -2.0, "reminder": -1.0, "reliable": 3.0, "uncomplicated": 2.0, "fast": 2.0, "kindly": 0.0, "confuse": -2.0, "blister": -3.0, "flaw": -3.0, "stain": -3.0, "complain": -2.0, "dissolve": -3.0, "apalled": -4.0, "discolor": -3.0, "spot": -2.0, "big": -1.5, "small": -1.5, "broken": -3.0, "worn": -3.0, "torn": -3.0, "hole": -3.0, "dirt": -3.0}
sia.lexicon.update(domain_words)
df_raw = pd.read_csv(DATA)
df_raw[6:11]
df = df_raw.copy()
%%time

pos_treshold = 0.8
neg_treshold = -0.25
df['vader'] = df['normalized_with_stopwords'].apply(lambda x: 'POSITIVE' if sia.polarity_scores(str(x))['compound'] >= pos_treshold 
                                           else ('NEGATIVE' if sia.polarity_scores(str(x))['compound'] <= neg_treshold 
                                                 else 'NONE'))

df['vader score'] = df['normalized_with_stopwords'].apply(lambda x: sia.polarity_scores(str(x))['compound'])
df.iloc[idx, 8]
# Original sentiment distribution
df["sentiment"].value_counts(normalize=True)
# Vader initial predictions
df["vader"].value_counts(normalize=True)
# No including stopwords
df["vader"].value_counts(normalize=True)
# With more stopwords v2
df["vader"].value_counts(normalize=True)
# With more stopwords v3
df["vader"].value_counts(normalize=True)
test_sia = "material error on the belt loop leather color flake off"
sia.polarity_scores(test_sia)
df_export = df[["feedback_text_en", "sentiment", "vader", "vader score", "delivery", "feedback_return", "product", "monetary", "one_hot_labels", "feedback_normalized", "normalized_with_stopwords"]]
df_export.to_csv(DATA_EXPORT)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12269300753834156, 'fraction_numerical': 0.018455939693267483, 'mean_word_length': 5.186495176848875, 'pattern_counts': {'":': 28, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '1240', 'license': 'MIT', 'n_tokens_mistral': 1252, 'n_tokens_neox': 1205, 'n_words': 394, 'path': 'notebooks/ma02_data_sa_vader.ipynb', 'repo_name': 'CouchCat/ma-zdash-nlp', 'size': '3847'}