We give an example of how to use Expert.ai and Python to investigate favorite music albums.

Sponsored Post.

By Laura Gorrieri, expert.ai

Please find the notebook version of this thread here.

Let’s build a small application to investigate one of my favourite artists. They are called “The Penguin Café Orchestra” and if you don’t know them you are going to find out what they are about.

Our dataset: a list of their album’s reviews that I took from Piero Scaruffi’s website and saved in a dedicated folder.

Our goal: to understand more about an artist using album reviews.

Our practical goal: to see how expert.ai’s NL API works and what it can do.

What is The Penguin Café Orchestra about?

First let’s see what comes out from the reviews just analysing the words used in them. We’ll firstly concatenate all the reviews in one variable, in order to have a whole artist’s review. Then we are going to take a look at the most frequent words in them, hoping that it will reveal more on the Penguin Café Orchestra.

## Code for iterating on the artist's folder and concatenate albums' reviews in one single artist's review
import os

artist_review = ''
albums = os.listdir(artist_path)

for album in albums:
album_path = os.path.join(artist_path, album)
      with open(album_path, 'r', encoding = 'utf8') as file:
           review = file.read()
           artist_review += review

Using a shallow-linguistics approach we can investigate the artist review, which contains all the available reviews. To do so we use matplotlib and word cloud to produce a word cloud that will tell us more about the most frequent words in the text.

# Import packages

import matplotlib.pyplot as plt
%matplotlib inline

# Define a function to plot word cloud
def plot_cloud(wordcloud):
    # Set figure size
    plt.figure(figsize=(30, 10))
    # Display image
    # No axis details

# Import package
from wordcloud import WordCloud, STOPWORDS

# Generate word cloud
wordcloud = WordCloud(width = 3000, height = 2000, random_state=1, background_color="white", collocations=False, stopwords = STOPWORDS).generate(artist_review)

# Plot

Fig.1: A word cloud in which the most used words appear in a bigger font and the less used one in a smaller font.

How does their music make you feel?

Thanks to the word cloud, we know more about The Penguin Café…

Continue reading: https://www.kdnuggets.com/2021/08/expert-nlp-insights-music.html

Source: www.kdnuggets.com