今回作るもの
パーソナライズド・レコメンダー・システムにおける好みをもとにした公平性のオンライン検証 の記事で作成したアイキャッチ画像(下の画像)を作っていきます!

ライブラリ
今回、texthero( https://texthero.org/ )を用いることで簡単にWordCloudを使うことができるので、このライブラリを使っていきます!
インポート
import pandas as pd
import texthero as hero
import datetime
タイトル・アブストラクト入力
タイトル(title) : 画像を保存する際に用います!(試す分にはなくても大丈夫です)
アブストラクト(abstract) : WordCloudで分析する内容としてabstractを入力します!
記入部分
#論文のタイトル
title = "Learning Implicit Surface Light Fields"
#論文のアブストラクト
abstract = "Implicit representations of 3D objects have recently achieved impressive results on learning-based 3D reconstruction tasks. While existing works use simple texture models to represent object appearance, photo-realistic image synthesis requires reasoning about the complex interplay of light, geometry and surface properties. In this work,(以下略)"
WordCloud作成(コード)
textheroだと、簡単に作ることができるので、下のコードだけで実行できます!!
注) Series型でないといけないので、string型などで代入している場合は注意してください!
WordCloud作成
s = pd.Series(abstract)
clean_text = hero.clean(s, pipeline=[
hero.preprocessing.fillna,
hero.preprocessing.lowercase,
hero.preprocessing.remove_digits,
hero.preprocessing.remove_punctuation,
hero.preprocessing.remove_diacritics,
hero.preprocessing.remove_stopwords
])
hero_img = hero.visualization.wordcloud(clean_text, colormap='viridis', background_color='white',return_figure=True)
画像を保存する際に、日付を加えたいので作成時刻をdt_now_formatに保存します
日付設定
dt_now = datetime.datetime.now()
dt_now_format = dt_now.strftime('%Y%m%d')
画像をimgディレクトリの中に、titleと日付を加えた上で保存したいので、下のように書いていますが、ファイル名は保存したい名前を入力してください!
画像保存
hero_img.savefig("img_blog/{}_{}.png".format(dt_now_format,title))
ここまでを実行することで、下の画像を作ることができました!!


コメント