<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>ML | Democratizing Data</title><link>https://b94feae1.chezo-uno.pages.dev/categories/ml/</link><atom:link href="https://b94feae1.chezo-uno.pages.dev/categories/ml/index.xml" rel="self" type="application/rss+xml"/><description>ML</description><generator>Hugo Blox Builder (https://hugoblox.com)</generator><language>en-us</language><copyright>© Aki Ariga 2017-2025</copyright><lastBuildDate>Tue, 25 Jan 2022 19:37:52 -0800</lastBuildDate><image><url>https://b94feae1.chezo-uno.pages.dev/media/icon_hu_9ca82a90e0d162db.png</url><title>ML</title><link>https://b94feae1.chezo-uno.pages.dev/categories/ml/</link></image><item><title>3 configs add recommend articles into your Hugo blog by GitHub Actions</title><link>https://b94feae1.chezo-uno.pages.dev/blog/2022-01-25_hugo-content-based-recommendation/</link><pubDate>Tue, 25 Jan 2022 19:37:52 -0800</pubDate><guid>https://b94feae1.chezo-uno.pages.dev/blog/2022-01-25_hugo-content-based-recommendation/</guid><description>&lt;p>Hugo has a feature to show keyword based related articles.&lt;/p>
&lt;div class="iframely-embed">&lt;div class="iframely-responsive" style="height: 140px; padding-bottom: 0;">&lt;a href="https://gohugo.io/content-management/related/" data-iframely-url="//iframely.net/q1grvUY?card=small">&lt;/a>&lt;/div>&lt;/div>&lt;script async src="//iframely.net/embed.js" charset="utf-8">&lt;/script>
&lt;p>Yeah, keyword based articles might be useful, for people who can manage keyword, category, etc, constantly.
I&amp;rsquo;d love to add content based recommendation that doesn&amp;rsquo;t require to write explicit keywords by myself. Then, I found an open source named &amp;ldquo;Prelims&amp;rdquo; which is developed by &lt;a href="https://twitter.com/takuti" target="_blank" rel="noopener">takuti&lt;/a>.&lt;/p>
&lt;div class="iframely-embed">&lt;div class="iframely-responsive" style="height: 140px; padding-bottom: 0;">&lt;a href="https://github.com/takuti/prelims" data-iframely-url="//iframely.net/omDBVa8?card=small">&lt;/a>&lt;/div>&lt;/div>&lt;script async src="//iframely.net/embed.js" charset="utf-8">&lt;/script>
&lt;p>Prelims is a post-processing tool for Front matter of Hugo/Jekyll, that is a metadata of an article.
The recommendation method which is implemented for now is classical, create a TF-IDF based word vector and find similar articles by consign similarity.&lt;/p>
&lt;p>The reason why I love Prelims is it&amp;rsquo;s simple and flexible. Post-processing of front matter doesn&amp;rsquo;t break your articles nor blog system at all. You can remove extra meta data Prelims generated whenever you want.&lt;/p>
&lt;p>Isn&amp;rsquo;t it practical, right?&lt;/p>
&lt;p>One downside of Prelims is it requires to implement Python code for tokenizing or vectorizing TF-IDF. I don&amp;rsquo;t want to bring my laptop for blog writing and wanna use Netlify CMS and iPad without having Python environment.&lt;/p>
&lt;p>So, I built a CLI tool for Prelims, named &lt;a href="https://github.com/chezou/prelims-cli" target="_blank" rel="noopener">prelims-cli&lt;/a>, which enables to add recommended articles just writing 1 configuration YAML file. It also runs with GitHub Actions.&lt;/p>
&lt;div class="iframely-embed">&lt;div class="iframely-responsive" style="height: 140px; padding-bottom: 0;">&lt;a href="https://github.com/chezou/prelims-cli" data-iframely-url="//iframely.net/m9C9uKt?card=small">&lt;/a>&lt;/div>&lt;/div>&lt;script async src="//iframely.net/embed.js" charset="utf-8">&lt;/script>
&lt;p>The three things you need to prepare are:&lt;/p>
&lt;ol>
&lt;li>Configuration YAML file for prelims-cli. e.g., &lt;code>scripts/config/myconfig.yaml&lt;/code>&lt;/li>
&lt;li>Hugo HTML partial layout, e.g., &lt;code>layouts/partials/page_related.html&lt;/code>&lt;/li>
&lt;li>GitHub Actions workflow for prelims-cli&lt;/li>
&lt;/ol>
&lt;p>Here is the example gist what you need to write.&lt;/p>
&lt;script src="https://gist.github.com/chezou/a9cb0ab2a086b3ce9ce9bf1abbc5b347.js">&lt;/script>
&lt;p>where &lt;code>content/blog&lt;/code> is the directory for English articles and &lt;code>content/post&lt;/code> is the directory for Japanese articles.&lt;/p>
&lt;p>Putting three files enables you to show recommended articles into your Hugo blog, like the screenshot in the top of this article.&lt;/p>
&lt;p>Internally, for Japanese tokenization, it uses SudachiPy. Since &lt;code>keywords&lt;/code> prelims generates are a-bit noisy and didn&amp;rsquo;t wanted to cleanup, so I stopped using it.&lt;/p>
&lt;p>The good things I feel are, I can use my blog articles for my hobby recommendation project, and I don&amp;rsquo;t need to manage tags and categories seriously.&lt;/p>
&lt;p>You can enjoy your recommendation without having Python environment, so you can write your articles on iPad with Netlify CMS!&lt;/p></description></item><item><title>3ファイル追加してGitHub ActionsでHugoにレコメンド記事を表示する</title><link>https://b94feae1.chezo-uno.pages.dev/post/2022-01-25-hugo-content-based-recommendation/</link><pubDate>Tue, 25 Jan 2022 18:41:33 -0800</pubDate><guid>https://b94feae1.chezo-uno.pages.dev/post/2022-01-25-hugo-content-based-recommendation/</guid><description>&lt;p>こんにちは、早いものでもう40の大台が迫ってくる誕生日を迎えました。前日にブースターショットを打ったので、一日中ほとんど寝込んでいました。必要な人のために、&lt;a href="https://www.amazon.jp/hz/wishlist/ls/FH3MHL6LTE02?ref_=wl_share" target="_blank" rel="noopener">例のリスト&lt;/a>を置いておきます。&lt;/p>
&lt;p>さて、Hugoにはキーワードベースの関連記事の表示をする機能があります。&lt;/p>
&lt;div class="iframely-embed">&lt;div class="iframely-responsive" style="height: 140px; padding-bottom: 0;">&lt;a href="https://gohugo.io/content-management/related/" data-iframely-url="//iframely.net/q1grvUY?card=small">&lt;/a>&lt;/div>&lt;/div>&lt;script async src="//iframely.net/embed.js" charset="utf-8">&lt;/script>
&lt;p>しかし、キーワードベースの関連記事も悪くはないのですが、折角なので自分で関連記事のレコメンドをしてみたくないですか？
そう思っていたら、 &lt;a href="https://twitter.com/takuti" target="_blank" rel="noopener">takuti&lt;/a> さんの Prelims というオープンソースを見つけました。&lt;/p>
&lt;div class="iframely-embed">&lt;div class="iframely-responsive" style="height: 140px; padding-bottom: 0;">&lt;a href="https://github.com/takuti/prelims" data-iframely-url="//iframely.net/omDBVa8?card=small">&lt;/a>&lt;/div>&lt;/div>&lt;script async src="//iframely.net/embed.js" charset="utf-8">&lt;/script>
&lt;p>Prelimsは、Hugo（やJekyll）のFront matterと呼ばれるメタデータの部分にキーワードやレコメンド記事を足してくれるものになります。&lt;/p>
&lt;p>レコメンドの方式自体は、今実装されているのは古典的なTF-IDFを用いたコンテンツベースの類似文書を出してくる方式ですが、Front matterを後から処理してレコメンド記事を追加するというシンプルだけどスマートな方法に感銘を受けました。&lt;/p>
&lt;p>ただし、Prelimsはflexibilityを重視しているため、例えば日本語のtokenizerやstop wordsなどは自分で設定をする必要があります。&lt;/p>
&lt;p>このあたり、ちょっと慣れていないと難しいかなとも思ったので、&lt;a href="https://github.com/chezou/prelims-cli" target="_blank" rel="noopener">prelims-cli&lt;/a>というCLIツールを作り、config用のYAMLファイルを用意すればGitHub Actionsでrecommendできるようにしました。&lt;/p>
&lt;div class="iframely-embed">&lt;div class="iframely-responsive" style="height: 140px; padding-bottom: 0;">&lt;a href="https://github.com/chezou/prelims-cli" data-iframely-url="//iframely.net/m9C9uKt?card=small">&lt;/a>&lt;/div>&lt;/div>&lt;script async src="//iframely.net/embed.js" charset="utf-8">&lt;/script>
&lt;p>用意するものは以下の3つです。&lt;/p>
&lt;ol>
&lt;li>prelims-cli用の scripts/config/myconfig.yaml&lt;/li>
&lt;li>関連ページを表示する layouts/partials/page_related.html&lt;/li>
&lt;li>prelims-cliを実行する GitHub Actions&lt;/li>
&lt;/ol>
&lt;p>実際の例をgistに貼りました。&lt;/p>
&lt;script src="https://gist.github.com/chezou/a9cb0ab2a086b3ce9ce9bf1abbc5b347.js">&lt;/script>
&lt;p>myconfig.yaml については、 &lt;code>content/blog&lt;/code> が英語の &lt;code>content/post&lt;/code> が日本語の記事をおいている想定です。
この3つのファイルを追加すればHugoであれば関連記事が、冒頭の画像のように出てくるはずです。&lt;/p>
&lt;p>内部的には日本語のtokenizerはSuachiPyのfull辞書を使い、最も長いCモードで形態素単位を設定しています。
ただし、prelimsが生成する &lt;code>keywords&lt;/code> は少しノイジーだなと思ったので、自分のサイトでは &lt;code>recommendations&lt;/code> のみを利用しています。&lt;/p>
&lt;p>僕はものぐさなので、タグやカテゴリを豆にメンテナンスできないのですが、レコメンドのおかげで過去の関連記事のリンクも出せるので便利だと感じています。
また、自分の記事は自分の持ち物なので、それに対してレコメンドしてML的なsandboxとして遊ぶのは楽しいなと感じています。&lt;/p>
&lt;p>この環境を使うことで、Netlify CMSでの執筆等Python環境を用意することができないところでも執筆して、レコメンド記事を作成することができます。
もしよければ、 prelims を使ったレコメンドを試してみてください。&lt;/p></description></item></channel></rss>