Identify violence in music with Artificial Intelligence. Do we hear or listen to music?
Latam online. First Edition. 2020 Have you stopped to think, what do your children listen to? Have you ever thought about how music influences our society and vice versa? Currently we are surrounded by a large amount of music…
A learning project shared by the community. The article documents its team, methods and results; it does not establish that the prototype is ready for real-world use.

This archive includes automatic translations. Audio, video and text inside images remain in their original language.
Latam online. First Edition. 2020
Have you stopped to think, what do your children listen to?
Have you ever thought about how music influences our society and vice versa?
Currently we are surrounded by a large amount of music that, although it has certain filters and criteria for its publication, sometimes reaches the ears of a certain population that is affected by the message that is transmitted. Nowadays it is no longer necessary to have a record label to promote a song, since access to social networks allows anyone with a cell phone and internet access to record and publish their song, reaching thousands of people in the world, including minors, like your children.
For a song to be heard, there are several distribution channels such as television, radio and social networks, and if there is no adequate filter, all types of songs with different content may be reaching the ears of minors.
Our proposal is based on identifying songs in which, in their lyrics, there is violent content. According to the article ““Violence against women in music: A methodological approach”[1], where violence against women in music is discussed, indicates that:
“In the most negative cases, stereotypes are projected that place men and women in different social positions, even going so far as to justify and promote violence against women.”
That is why this project aims to contribute to the fulfillment of one of the seventeen Sustainable Development Goals, proposed by the United Nations and accepted by several countries in Latin America, specifically objective five regarding gender equality. To identify and raise awareness among the population about the message that music transmits and, in this way, empower the population that has access to digital music platforms, about the messages in the songs they listen to.
At the beginning of this project, we brainstormed and thought about creating an app that, when listening to or entering a song, indicates whether it contains various types of violence in its lyrics, through the use of Natural Language Processing (NLP), for which the following labeling was proposed:
Types of violence according to the article “Violence against women in music: A methodological approach”, some icons were obtained from the article “What do we talk about when we talk about violence against women”, from .infojusnoticias.gov.ar
Suitable for minors
It does not contain any type of violence, the message and context of the song should be reviewed by an adult.
Data extraction
To do this, a sample of 500 songs began to be analyzed, which were selected from Latin music popularity lists, since the project is proposed for the Spanish-speaking population of Latin America, so the workflow was as follows:
It was found in the rankings of Billboard and Scanner Sound, the list of songs most played with a web scraper, with what was obtained artist and title.
Using the musixmatch developer tools, the API obtained the musical genre of each song and whether they have 'explicit' language, however it only provided us with 40% of the lyrics.
The lyrics of the songs were obtained from Google, which is fed by two providers: Musixmatch and LyricFind, with which, finally, the following fields were obtained:
- Artist
- Gender
- Title
- Whether it is explicit or not (inappropriate language)
Then, the song lyrics were extracted using APIs offered by the most popular music sites (Musixmatch and Billboard) through their developer tools.
Once the lyrics of the songs were obtained, manual labeling was carried out, which was carried out according to the types of violence previously explained. The development team of this project labeled the training categories, resulting in the following data source, its representation can be seen below:

Example of a data set obtained in a first labeling
It is important to note that, because the labeling of each category is subject to the criteria of each team member, the data set could have a bias. It is worth mentioning that this stage of the project is a proof of concept that will help us validate the feasibility of carrying out automatic labeling according to the stated objective. Furthermore, upon observing that the number of positives in each category was not enough for the algorithm to learn well, it was decided to add an additional category, called 'class', which indicates whether it has violent content. This change within scope will be addressed later.
EDA
Then the Expiatory Data Analysis (EDA) was carried out. To prepare the data using the 'pandas' library for Python, as well as matplotlib, seaborn and plotly for this first analysis that would allow us to make decisions prior to pre-processing the data and have an overview of how the classes were distributed in our 'data set'. and obtain a corpus that would serve as a basis to begin the analysis using NLP.

Some interesting insights were obtained from the generated data set through a first Expiatory Data Analysis (EDA):
Analysis/distribution of types of violence

Bar graph showing the number of incidents in each class of the data set
In this bar graph we can observe the distribution of the types of violence contained in the selected music, in this case, the greatest predominance are musical genres of reggaeton, regional Mexican and pop in Spanish because the most listened to songs of the moment were obtained, however, this information will not be used for the algorithm since it could create an important bias, as can be seen in the histogram according to the genres. It is worth mentioning that this analysis was done before normalizing the data to have an overview of how the data is distributed.

Bar graph showing how the types of violence are distributed by musical genre.
A heat map was made to discover how the types of violence are related within the songs that were considered.

After analyzing the types of violence, we consider that separating the number of songs into the seven selected categories would not be enough to make a good classification since we have relatively few positives in each category. Based on this observation, for a first phase, the separation will be carried out only into 2 categories: “violent” and “non-violent”. Something very important to highlight is that even if a song does not contain violence, it does not mean that it is suitable for infants, because it could touch on topics not suitable for certain ages.
Analysis with word maps with and without the violence label
In a second approach, during the preprocessing of the data, word maps were obtained, like a second EDA, in order to identify the most frequent words in violent and non-violent content and recognize some “stopwords” that we must consider or, if applicable, words that should be lemmatized.
The preprocessing of the data, in this case, was carried out as follows:
Normalization of song data/lyrics (accents, capital letters, punctuation marks and elimination of words like 'oh', 'yeah', 'ma', etc.)
Word tokenization
Stopword removal
Lemmatization (in a next stage it is considered to see if 'stemming' could help obtain better results)
Vectorization of the songs (Bag of Words is used in this stage of the project).
After the preprocessing was done, word maps were used again to observe which words could be more recurrent in a song with violence and without violence. However, when obtaining the word maps, it was observed that in both cases words such as: have, want, do and have predominate. Therefore, they were included in the list of 'stopwords' and an analysis was performed again with a word cloud.

map of “non-violence” words before removing very common stop words

map “with violence” words before removing very common stop words

map of “non-violence” words after removing very common stop words

map of “with violence” words after removing very common stop words
As can be seen, both classifications still have some words in common such as “say” and “know.” However, different words can be seen on the map of the songs 'with violence', such as "forget", "die", "lose", "leave", etc.
Once the 'corpora' was prepared and the Bag of Words vectorization was applied, we worked with the "violent" or "non-violent" label, which will represent whether the song has any type of violence in its content.
Training and model selection
It was tested with different algorithms, after applying the 'bag of words' representation and using the lemmatization technique with the nltk tools, for the models the sklearn libraries such as Naive Bayes, Random Forest, Decision Tree, SVM and SGD were used.
For each model, a classification report was presented to visualize its accuracy, but the f1-score was also considered to evaluate them together with a heat map of the confusion matrix.

Results obtained from the classifiers, confusion matrix and metrics obtained with the sklearn and seaborn libraries
In order to better compare the performance of the models, ROC curves were also used. Which shows us in a more visual way the behavior of the models with each other.

ROC curves of the models obtained with the sklearn and matplotlib libraries
ROC curves of the models
As seen in the ROC curve graph, the models that had the best performance were 'Random Forest' and 'Naïve Bayes', which have very similar results. However, if we look at the confusion matrices and the 'F1 Score' we can conclude that with the data we have, 'Naïve Bayes' is the model that has the best performance at this stage of the project. Since for us it is better to have a violent label even if it does not have one, than for a song with violence to be wrongly classified and reach minors. That is, in technical terms it is better for us to have a type I error (false positives) than a type II error (False negatives).
Project scalability
Based on the data generated, the learning was done considering only 2 categories 'with violence' and 'without violence', because the number of songs used would not be enough for the algorithm to differentiate between 6 different classes. It is even thought that in the future, with a greater amount of learning data, the classification can be made into 3 or 4 categories, depending on the number of positives that we can obtain.
If good results are obtained, an API could be created for use in mobile applications or as a plug-in, in order to facilitate the recognition of a song and know if said song has violent content or not.
Knowing in advance whether or not a song has violent content will help empower users and reflect on the impact that what is heard in popular culture has on our lives and the culture of the population.
A particular case of an application could be as a tool for detecting 'media violence', in a law recently approved in Mexico: the 'Olimpia' law, in which this term was integrated, which as can be read in the newspaper Excélsior[2], is defined as:
Any act that through any means of communication:
-Promote sexist stereotypes.
-Advocate violence against women and girls.
-Produces or allows the production and dissemination of sexist hate speech.
-Promotes gender discrimination or inequality between women and men.
-Cause harm to women and girls of a psychological, sexual, physical, economic, patrimonial or femicidal nature.

Example of API with the logo of the development team
Glossary:
NLP: Natural Language Processing is the branch of Artificial Intelligence that studies the interaction of human language with computers.
Corpus (pl. corpora): A linguistic corpus is a large and structured set of real examples of language use. These examples can be texts (the most common), or oral samples (generally transcribed). [3]
Lemmatization: Relate an inflected or derived word to its canonical form or lemma. And a motto is nothing more than the form that words have when you look them up in the dictionary. [4]
Stopword: Very common words that are not very informative from a lexical point of view, such as conjunctions (and, or, nor, what), prepositions (a, en, para, por, among others) and very common verbs (ser, ir, and others).[4]
References:
- Gómez Escarda, María., Pérez Redondo, Rubuén J. (2016) ““Violence against women in music: A methodological approach”. King Juan Carlos University, Spain.
- Robles De la Rosa, Leticia (November 2020). They approve 'Olimpia Law' for the entire country; establish a crime in the Federal Penal Code. Excelsior. https://m.excelsior.com.mx/nacional/aprueban-ley-olimpia-para-todo-el-pais-establecen-delito-en-el-codigo-penal-federal/1415366
- Werner, Welte; Meno Blanco, Francisco (1985). Modern Linguistics: Terminology and Bibliography. Madrid: Gredos.
- Urdaneta Fernández, Lino Alberto (May 4, 2019). Reduce the number of words in a text: lemmatization and stemming with Python. Medium. https://medium.com/qu4nt/reducir-el-n%C3%BAmero-de-palabras-de-un-texto-lematizaci%C3%B3n-y-radicalizaci%C3%B3n-stemming-con-python-965bfd0c69fa
Members
- Álvarez Leandro
- Alejandra paintings
- Morales Leobardo
- Ramirez Hector
- Samaniego Luis
Project presentation: DemoDay
Repository
In the following repository you will find the code used to develop this application:https://github.com/SaturdaysAI/Projects/tree/master/LATAM_remote/NLP_Violencia-en-musica–master
More artificial intelligence!
The mission of Saturdays.ai is to make artificial intelligence more accessible (#ai4all) through intensive courses and programs where projects for good are carried out (#ai4good).
Explore our AI master’s programme at https://saturdays.ai/master-ia-online/
If you want to learn more about artificial intelligence join our community at community.saturdays.ai or visit us on our website www.saturdays.ai Join us!
A history of the Saturdays.AI community. Originally published on March 16, 2022.
← More community stories


