[PYTHON] I want to automatically generate a modern metal band name

Introduction

Have you ever had the experience of "I can't decide on the name of our original band ..."? I think it's an experience that everyone has had trouble with once. I am currently suffering from the band leader's homework, "I am thinking about two plans for each person by the next practice."

Looking at the band names of recent artists, I feel that very unique and complicated names are increasing. It is a very important event to think about the band name when forming our own original band. In the music industry these days, where band names are diversifying due to the increase in the number of bands, many people may have a hard time deciding on a "good band name" with originality.

So, this time, in order to solve the above problems, I started the work of this article with the approach of automatically generating using simple natural language processing (although I did not use natural language processing technology much after all). ).

The script created this time and the list of collected metal band names are here.

What I made

Overview (elevator pitch)

―― [Determine the name of your band] I want to -For [Bandman who recently formed an original band] --The tool called [Band Name Generator] is --[python script]. --This allows you to [automatically generate the original band name from the specified conditions], -Unlike [thinking while saying things by yourself] -[A function to automatically generate multiple band names that look like it based on the information of existing bands] is provided.

Generated band name

I automatically generated it several times and picked up the ones that I personally liked.

Bring Funeral Against You
Devil Brings Sacred
Burden Minus Trooper Hollow
Brat Murphy Thrice Hearts
Brides Macabre Tigers Hotel
Project Farewell My Eyes
Glass Cloud Nothings Black
Necropsy Rites Of Today

Trends in modern metal band names and approaches to them

The names of modern metal bands these days have become very complicated. The following is an example.

As a result of my own analysis, I felt that there was a tendency as follows.

--3-4 English word sequence --Abuse of two words in the kitchen --A name that seems to have a deep meaning (~~ but not really ~~) --Words other than English, such as coined words and Latin

Also, when I listened to the stories of the band members, I got the information that the following points should be kept in mind when deciding the band name.

--Catchy remains when abbreviated --Often abbreviated by taking the first letter of each word-> BMTH (Bring Me The Horizon), KsE (Killswitch Engage), A7X (Avenged Sevenfold), etc. -(Of course) give originality ――It is not good to be buried in other information when searching with a search engine. ――It is out of the question if you already have the same band name. ――If you make your own coined words, it is easy (but difficult) to satisfy the above two points.

Among the analyzed trends, except for coined words, I thought that it would be possible to collect words used as band names and automatically generate them by some processing. In this article, we tried automatic generation using the following three approaches.

  1. Specify one word you want to use and the number of words you want to generate, and randomly extract the remaining number of words from the word list.
  2. Specify an acronym and randomly extract words along the acronym from the word list.
  3. Specify the number of words you want to generate and generate using Markov chains

Supplement: About Markov chains

Roughly speaking, the Markov chain is "the state of time t + 1 depends only on the state of the current time t (the state of the timeti (i <0)in the past). It is a stochastic process with the idea (Markov property) of "independent".

The "state" in sentence generation corresponds to letters, words, and phrases. (Word in this band name generation)

For example

If you use the four band names as a sample, After "The", "Rolling" appears with a probability of 0.75 (= 3/4), and after "Rolling", there is an equal probability of 0.33 (= 1/3) for "Stones", "Korokoros", and "GoroGoros". "Appears. After "Led", "Zeppelin" always appears with a probability of 1.00 (= 1/1), You can decide the next state (= next word) like this. By increasing the number of samples, you can create a model with more variations.

For a detailed explanation of Markov chains and implementation by python, [this article](https://qiita.com/k-jimon/items/f02f ae75e853a9c02127 for each mode implemented) is explained in an easy-to-understand manner.

Implementation

Implementation environment

OS: Ubuntu 18.04.2 LTS
Python: 3.6

Band name collection

We collected from the band name list of each Wikipedia genre and created a txt file in the format of one band per line. This has also been uploaded to the github repository!

Genres collected this time


- Christian hardcore
- deathcore
- djent
- mathcore
- metalcore
- hardcore punk
- heavy metal

In the end, we were able to collect 1,730 bands.

code

generate.py


import numpy as np
import random
import re
from collections import defaultdict
import pprint

def make_by_word(seed_word, num_word, init_dict):
    """Generate using the specified word"""
    result_words = [seed_word]
    seed_word = seed_word.lower()
    for i in range(num_word-1):
        chosen_word = random.choice(tokenized_text)
        result_words.append(chosen_word)

    bandname = result_words
    if "the" in bandname or "The" in bandname:
        for i, res in enumerate(result_words):
            if res.lower() == "the":
                bandname[0], bandname[i] = bandname[i], bandname[0]
    else:
        random.shuffle(bandname)

    print(" ".join(bandname))

def make_by_initial_name(seed, init_dict):
    """Generated based on the specified initials"""
    seed = seed.lower()
    result_words = []
    for initial in seed:
        #print(initial)
        #print(init_dict[initial])
        choices = init_dict[initial]
        chosen_word = random.choice(choices)
        result_words.append(chosen_word.capitalize())

    print(" ".join(result_words))

def walk_graph(seed, graph, distance=5, start_node=None):
    """Generated using Markov chain by specifying the number of words"""
    if distance <= 0:
        return []
    #print(seed)
    # If not given, pick a start node at random.
    if not start_node:
        start_node = random.choice(list(graph.keys()))


    weights = np.array(
        list(markov_graph[start_node].values()),
        dtype=np.float64)
    # Normalize word counts to sum to 1.
    weights /= weights.sum()

    # Pick a destination using weighted distribution.
    choices = list(markov_graph[start_node].keys())
    #print(choices)

    chosen_word = np.random.choice(choices, None, p=weights)

    result_words = [chosen_word] + walk_graph(seed,
        graph, distance=distance-1,
        start_node=chosen_word)

    return result_words


if __name__ == '__main__':
    # preprocess
    ## Read text from file and tokenize.
    path = './band_list/band_list.txt'

    with open(path) as f:
      text = f.read()
    #print(text)
    tokenized_text = [
        word
        for word in re.split('\W+', text)
        if word != ''
    ]

    init_dict = defaultdict(list)
    for word in set(tokenized_text):
      word_ = word.lower()
      init_dict[word_[0]].append(word_)

    ## Create graph.
    markov_graph = defaultdict(lambda: defaultdict(int))

    last_word = tokenized_text[0].lower()
    for word in tokenized_text[1:]:
        word = word.lower()
        markov_graph[last_word][word] += 1
        last_word = word


    # main process
    print("""\
    mode:
    1: generate the words you want to use and the num of words you set(e.g. bring 4)
    2: set the acronym you want to use(e.g. BMTH)
    3: set hte word count and generate a Markov chain model(e.g. 4)""")
    mode = int(input("mode? >> "))

    if mode == 1:
        seed = input("seed? >> ")
        num_word = int(input("word num? >> "))
        print("--------------------------")
        for i in range(10):
            make_by_word(seed, num_word, init_dict)

    elif mode == 2:
        seed = input("initial? >> ")
        print("--------------------------")
        for i in range(10):
            make_by_initial_name(seed, init_dict)

    else:
        seed = int(input("word num? >> "))
        print("--------------------------")
        for i in range(10):
            #print(' '.join(walk_graph(
            #      markov_graph, distance=len(seed))), '\n')
            count = 0
            res = walk_graph(seed, markov_graph, distance=seed)
            print(" ".join(res))

As a pretreatment ・ Read the band name list and ・ Store the band name in the dictionary ・ Create a Markov graph After performing, the band name generation, which is the main function, is performed.

This time, I implemented it with the three approaches mentioned above.

  1. Specify one word you want to use and the number of words you want to generate, and randomly extract the remaining number of words from the word list (make_by_word ())
  2. Specify an initial letter and randomly extract words along the initial letter from the word list (make_by_initial_name ())
  3. Specify the number of words you want to generate and generate using Markov chains (walk_graph ())

Actually generate the band name

Do the following:

python generate.py

The following is output, so select the mode.

mode:
1: generate the words you want to use and the num of words you set(e.g. bring 4)
2: set the acronym you want to use(e.g. BMTH)
3: set hte word count and generate a Markov chain model(e.g. 4)
mode? >>

The outline of each mode is as follows.

1:Band name generation is performed by specifying the word you want to use and the number of words you want to generate.(Example: bring 4)
2:Specify the first letter of the band name you want to generate and generate the band name.(Example: BMTH)
3:Specify the number of words you want to generate and generate the band name using the Markov chain model.

By setting the value to be asked for each mode, 10 band names are automatically generated.

Mode 1: Specify the word you want to use and the number of words

Use this mode if you have a word that you want to use. You can specify a word that does not exist. (The band name generated below the underlined part of the standard output.)

mode:
1: generate the words you want to use and the num of words you set(e.g. bring 4)
2: set the acronym you want to use(e.g. BMTH)
3: set hte word count and generate a Markov chain model(e.g. 4)
mode? >> 1
seed? >> Bring
word num? >> 4
--------------------------
Bring Funeral Against You
Bring Deftones Airlines Kids
Hesitation Dire Bring Psyopus
Lions Barren Bring Dismemberment
Rorschach Bring Hand Bloodshed
Bring Pereo Hound This
Take Remains Bring Skycamefalling
Bring Sick Bunchofuckingoofs Annisokay
Rock Bring Fall Drivers
Devil Bring s Sacred

Mode 2: Specify the first letter of the band name you want to generate

These days band names are often abbreviated by initials, so this is the mode we implemented. (The band name generated below the underlined part of the standard output.)

mode:
1: generate the words you want to use and the num of words you set(e.g. bring 4)
2: set the acronym you want to use(e.g. BMTH)
3: set hte word count and generate a Markov chain model(e.g. 4)
mode? >> 2
initial? >> BMTH
--------------------------
Bullet Minutemen Thee Hoax
Burst Meat Treason Hand
Burden Minus Trooper Hollow
Blitzkrieg Mantis Treatment Horse
Botch Me Troy Hat
Beasts Mad Tattoo Hacktivist
Break Moxy They Headpins
Brat Murphy Thrice Hearts
Blue Mountain They Houses
Brides Macabre Tigers Hotel

You can decide from the top down because of the coolness when abbreviated.

Mode 3: Generate with Markov chain model by specifying only the number of words you want to generate

Generate using a Markov chain model by specifying only the number of words. (The band name generated below the underlined part of the standard output.)

mode:
1: generate the words you want to use and the num of words you set(e.g. bring 4)
2: set the acronym you want to use(e.g. BMTH)
3: set hte word count and generate a Markov chain model(e.g. 4)
mode? >> 3
word num? >> 4
--------------------------
venomous concept messiah prophet
wept rapeman pagan altar
hat band opprobrium p
x cries hannah head
lvl maroon alexisonfire mallory
for mine anti cimex
ambassadors of slumber kerber
project farewell my eyes
glass cloud nothings black
necropsy rites of today

Since there is no specification other than the number of words, you can use it when you have not decided which word you want to use. Thanks to the use of Markov chains, the word sequence should be the most like that of the three modes this time.

in conclusion

This time, I made a tool that automatically generates a band name like that based on the words used in the existing band name. I'll try it a few times and suggest what I like for the band name. Demand may be very low, but if you run into similar challenges, take advantage of it.

(Later talk)
The automatically generated band name has been rejected, but we were able to brush up the ideas that the other members had come up with and decide safely!

reference

-[Python] Generate sentences with N-th floor Markov chain

Recommended Posts

I want to automatically generate a modern metal band name
I want to generate a UUID quickly (memorandum) ~ Python ~
I tried to automatically generate a password with Python3
I want to send a business start email automatically
I want to print in a comprehension
I want to build a Python environment
I want to make matplotlib a dark theme
I want to INSERT a DataFrame into MSSQL
I want to create a window in Python
I want to make a game with Python
I don't want to take a coding test
I want to create a plug-in type implementation
I tried to generate a random character string
I want to easily find a delicious restaurant
I want to write to a file with Python
I want to upload a Django app to heroku
I tried to automatically generate a port management table from Config of L2SW
I want to see the file name from DataLoader
I want to embed a variable in a Python string
I want to easily implement a timeout in python
I want to iterate a Python generator many times
I want DQN Puniki to hit a home run
100 image processing knocks !! (021-030) I want to take a break ...
I want to give a group_id to a pandas data frame
I want to transition with a button in flask
I want to climb a mountain with reinforcement learning
I want to write in Python! (2) Let's write a test
I want to find a popular package on PyPi
I want to randomly sample a file in Python
I want to easily build a model-based development environment
I want to work with a robot in python.
I want to split a character string with hiragana
I want to install a package of Php Redis
[Python3] I want to generate harassment names from Japanese!
[Python] I want to make a nested list a tuple
I want to manually create a legend with matplotlib
I want to run a quantum computer with Python
I want to do Wake On LAN fully automatically
I want to bind a local variable with lambda
I tried to automatically generate a character string to be input to Mr. Adjustment with Python
I want a mox generator
I tried to automatically generate OGP of a blog made with Hugo with tcardgen made by Go
I tried to automatically create a report with Markov chain
I want to make a blog editor with django admin
I want to start a jupyter environment with one command
I want to start a lot of processes from python
I want to make a click macro with pyautogui (desire)
NikuGan ~ I want to see a lot of delicious meat! !!
I made a command to generate a table comment in Django
I want to solve Sudoku (Sudoku)
I want to automatically attend online classes with Python + Selenium!
I want to make a click macro with pyautogui (outlook)
I want a mox generator (2)
I want to use a virtual environment with jupyter notebook!
I want to install a package from requirements.txt with poetry
I want to send a message from Python to LINE Bot
[Django] I want to log in automatically after new registration
I made a tool to automatically generate a simple ER diagram from the CREATE TABLE statement
[Introduction to Pytorch] I want to generate sentences in news articles
[Visualization] I want to draw a beautiful graph with Plotly
I want to make input () a nice complement in python