SlideShare a Scribd company logo
1 of 23
Download to read offline
歌詞の可視化クイズ!
(自然言語処理技術)
2019年12月20日
鹿児島.mk#5 LTのためのLT大会
鹿児島大学3年 セリナ 1
自己紹介 セリナ(23) @serina_ponpi
 鹿児島大学工学部情報生体システム工学科
学部3年
 福岡工業大学短期大学部情報メディア学科
CG映像サウンドコース 卒業後2年次編入
 趣味:スマホゲーム(PUBG/音ゲー)
踊ってみた観賞
アイドル(嵐/Perfume/ZOC/すとぷり)
 先週研究室配属が決定
画像に関する人工知能技術を研究予定
2
今回の背景
 「自然言語処理」講義を受講中
- N-gram,形態素解析,構造解析,意味解析,チャットボット作成
 形態素解析の課題を調べていたら面白そうなQiitaの記事を発見!
「米津玄師の歌詞をWordCloudで可視化してみた。」
https://qiita.com/Senple/items/1ad08b1a7ac9560bef62
 アーティストごとに歌詞を可視化してクイズにしよう!
3
全体の流れ
歌詞の収集(スクレイピング)
歌詞を単語にわける(形態素解析)
可視化(WordCloud)
4
歌詞の収集(スクレイピング)
 スクレイピング
Webサイトから自分が必要とする情報を抽出すること。
特に近年では、機械学習などで大量のデータを取得する必要があり、
プログラムを使って自動化することが多くなっている。
 Beautiful Soup
HTMLファイルやXMLファイルからデータを抽出するためのPythonライブラリ
5
歌詞の収集(スクレイピング)
6
 def main():
 with open(‘Yonedu_kashi.txt', 'a') as f:
 # アーティストページ(米津玄師)のアドレス
 url = 'https://www.uta-net.com/artist/6636/'
 # 曲ページの先頭アドレス
 base_url = 'https://www.uta-net.com'
 # ページの取得
 html = load(url)
 # 曲ごとのurlを格納
 musics_url = []
 # 歌詞を格納
 kashis = ''
アーティストページのURLを指定
 """ 曲のurlを取得 """
 # td要素の取り出し
 for td in pickup_tag(html, 'td'):
 # a要素の取り出し
 for a in pickup_tag(td, 'a'):
 # href属性にsongを含むか
 if 'song' in a.get('href'):
 # urlを配列に追加
 musics_url.append(base_url + a.get('href'))
7
歌詞の収集(スクレイピング)
各曲のURLを取得し
配列に追加
 """ 歌詞の取得 """
 for i, page in enumerate(musics_url):
 print('{}曲目:{}'.format(i + 1, page))
 html = load(page)
 for div in pickup_tag(html, 'div'):
 # id検索がうまく行えなかった為、一度strにキャスト
 div = str(div)
 # 歌詞が格納されているdiv要素か
 if r'itemprop="text"' in div:
 # 不要なデータを取り除く
 kashi = parse(div)
 print(kashi, end = '¥n¥n')
 # 歌詞を1つにまとめる
 kashis += kashi + '¥n'
8
歌詞の収集(スクレイピング)
歌詞を配列に追加
9
歌詞の収集(スクレイピング)
 歌詞のテキストファイルが出力される
歌詞を単語にわける(形態素解析)
 形態素解析
文章を意味のある単語ごとに切り分ける。
・英語→スペースでわければいい
My / name / is / Serina.
・日本語→形態素解析エンジンMeCabを使用
私 / の / 名前 / は / せりな / です。
10
 import MeCab
 #スクレイピングした歌詞のデータを取得
 bindata = open("Nogizaka_kashi.txt", 'rb').read()
 kashi = bindata.decode('cp932')
 # 曲ごとに区切る
 lines = kashi.split('¥n')
 mecab = MeCab.Tagger('-Ochasen')
 mecab.parse('')
 output = []
 #意味をなさないような単語を除外する。
 stoplist=['「', '」', 'じゅう', 'そこら', 'れる', 'くい','ん','よう','の','てる','なっ','こと','いる','ない',
 'そう','する', 'まま', 'よう', 'なる', 'こと', 'もう', 'いい', 'ある', 'ゆく', 'れる','それ']
11
歌詞を単語にわける(形態素解析)
特徴にならなそうな
単語を除外
先ほどの
テキストファイルを読み込む
 for i in range(0,len(lines)):
 node = mecab.parseToNode(lines[i])
 # 品詞に分解して、助詞や接続詞などは除外している。
 while node:
 word_type = node.feature.split(",")[0]
 if word_type in ["名詞","形容詞","副詞","動詞"]:
 if not node.surface in stoplist and not node.surface.isdigit():
 output.append(node.surface.upper())
 node = node.next
 print(output)
12
歌詞を単語にわける(形態素解析)
品詞に分解
For文で曲数分回す
13
 単語ごとに分かれた配列が出力される
歌詞を単語にわける(形態素解析)
可視化(WordCloud)
 ワードクラウド
頻出語を頻度に比例する大きさで
雲のように並べたもの
14
 from wordcloud import WordCloud
 #形態素解析された単語のリストをWordCloud用に処理している。
 text = ' '.join(output)
 #日本語はWindowsのフォントのパスを貼り付ける
 fpath = "C:/Windows/Fonts/YuGothM.ttc"
 wordcloud = WordCloud(background_color="white",
 font_path = fpath, width=800,height=600).generate(text)
 #WordCloudの画像は同じディレクトリ内に保存されます。
 wordcloud.to_file("./wordcloud_Fanmon.png")
15
可視化(WordCloud)
WordCloudライブラリで
画像化
クイズ!
16
どれがAKB48?乃木坂46?欅坂46?
クイズ!
17
乃木坂46 AKB48 欅坂46
18
19
ゆず、嵐、Perfume、西野カナ、Mt.Children、Funky Monkey babys
20
嵐 ゆず
Perfume 西野カナ
Funky Monkey Babys
Mt.Children
嵐(ソロ曲含む343曲)
21
Perfume(107曲)
22
さいごに
 形態素解析わりと簡単にできるし可視化すると面白い!
 リアル世界に投影など演出にしても面白そう!
人間の表現×技術でわくわくすることしたい!
 もっと詳しく聞きたい方、
「このアーティスト/曲やってほしい!」等ぜひ声かけてください!
23

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

20191220歌詞の可視化クイズ(鹿児島.mk#5)