Cookpadのレシピ検索 — 学習to-rank実装

クックパッドは日本最大級のレシピ投稿サービスとして、一日に数百万件のレシピ検索を処理しています。「今夜の献立」を考える利用者が最も満足するレシピを上位に並べるためには、単純なキーワード一致だけでは不十分です。本記事ではクックパッドの検索順位付けの全体像を整理します。
Cookpad, as one of Japan's largest-class recipe posting services, processes several million recipe searches per day. To rank the recipes that most satisfy users thinking about "tonight's menu" at the top, simple keyword matching alone is insufficient. This article organizes the overall picture of Cookpad's search ranking.
特徴量の設計
順位付けモデルに入力される特徴量は多岐にわたります。食材の一致度、レシピの人気(つくれぽ数や保存数)、季節との相性、利用者の過去閲覧履歴、作者の信頼度、投稿からの経過時間など、数十から数百に及ぶ特徴量を組み合わせます。
The features fed into the ranking model are diverse — ingredient match degree, recipe popularity (number of tsukurepo "cooked reports" and saves), seasonal compatibility, the user's past browsing history, author trust level, time elapsed since posting, and more. Dozens to hundreds of features are combined.
形態素解析と日本語特有の難しさ
日本語の検索クエリは英語のように空白で単語が区切られていません。「豚肉キャベツ簡単」というクエリを処理するためには、形態素解析器(mecabやkuromoji)で単語に分解する必要があります。クックパッドは料理ドメインに特化した辞書を整備し、食材名や料理用語を正しく切り出せるようにしています。
Japanese search queries are not separated by spaces between words like English. To process the query "pork cabbage easy," it must be decomposed into words by a morphological analyzer (mecab or kuromoji). Cookpad maintains a dictionary specialized for the cooking domain so that ingredient names and cooking terms can be correctly extracted.
表記揺れと同義語の吸収
「人参」「ニンジン」「にんじん」、「豚バラ」「豚ばら肉」など同じ食材でも表記の揺れが豊富にあります。索引時にこれらを正規化し、クエリ側でも同義語展開を行うことで、ユーザーがどの書き方をしても同じレシピがヒットするようになります。
The same ingredient has abundant notation variations — "人参 / ニンジン / にんじん" for carrot, "豚バラ / 豚ばら肉" for pork belly. By normalizing these at indexing time and performing synonym expansion on the query side, the same recipes will hit regardless of how the user writes them.
学習to-rankモデル
特徴量を人手で重み付けするのではなく、利用者のクリックやつくれぽ投稿を正解データとして学習するモデルが使われます。LambdaMARTやXGBoostといった勾配ブースティング木モデルが代表的で、各特徴量の重要度を自動的に学習します。「人気が高ければよい」という単純な線形関係ではなく、食材一致との組み合わせで非線形に評価できる点が強みです。
Rather than weighting features manually, models that learn from user clicks and tsukurepo postings as ground truth are used. Gradient boosting tree models like LambdaMART and XGBoost are representative, automatically learning the importance of each feature. The strength is that they can evaluate non-linearly through combinations with ingredient match, rather than as a simple linear relationship like "high popularity is good."
季節と地域変動
日本の食文化は季節と強く結びついており、夏は冷やし中華や素麺、冬は鍋や煮込みが人気です。クックパッドは食材の旬や気温と連動した特徴量を加え、同じ「簡単レシピ」というクエリでも時期によって結果が変わるように設計しています。地域差(関西と関東の味付けなど)も考慮に入れます。
Japanese food culture is strongly tied to seasons — chilled Chinese noodles and somen are popular in summer, hot pots and stews in winter. Cookpad adds features linked to ingredient peak seasons and temperature, designed so that even the same "easy recipe" query yields different results by time period. Regional differences (such as Kansai vs Kanto seasoning) are also taken into consideration.
A/Bテスト基盤
新しいモデルや特徴量を本番に投入する前に、必ずA/Bテストで既存モデルとの差を計測します。評価指標はクリック率だけでなく、「つくれぽが投稿されたか」「保存されたか」など料理が実際に作られたことを示す後段の行動を重視します。クリックされても作られなければ本当の満足とは言えないからです。
Before deploying a new model or feature to production, the difference from the existing model is always measured via A/B test. Evaluation metrics emphasize not only click rate but also downstream actions that show the dish was actually cooked — "was a tsukurepo posted?" "was it saved?" — because clicking without cooking cannot be called true satisfaction.
個人化と嗜好履歴
同じ「カレー」というクエリでも、肉食の利用者にはチキンカレー、野菜中心の利用者にはベジタブルカレーが上位に来るように、個人の過去行動を考慮した個人化が行われます。ただし、強すぎる個人化は「いつも同じレシピしか出ない」フィルターバブルを生むため、一定の割合で新しいレシピを混ぜ込む工夫が必要です。
Even with the same query "curry," personalization considering an individual's past behavior is performed so that meat-eating users see chicken curry on top, and vegetable-centric users see vegetable curry on top. However, overly strong personalization creates a filter bubble where "only the same recipes ever appear," so a device for mixing in new recipes at a certain ratio is needed.
低レイテンシでの応答
数百万レシピから数十を即座に返すためには、二段階検索が基本です。第一段階は転置インデックスで候補を数百に絞り、第二段階で重い学習to-rankモデルを適用して最終の順位付けを行います。全件にモデルを掛けると応答時間が爆発するため、現実的な計算コストで精度を出す工夫が施されています。
To instantly return dozens of results from millions of recipes, two-stage search is the basic approach. The first stage narrows candidates down to hundreds via an inverted index, and the second stage applies a heavy learning-to-rank model for final ranking. Applying the model to all items would explode response time, so devices for producing accuracy at realistic computational cost are applied.
おわりに
クックパッドの検索は「食材が一致している」「人気が高い」という基本に加え、日本語特有の表記揺れ、季節・地域変動、個人嗜好を組み合わせて「今夜作りたいレシピ」を届ける仕組みです。機械学習と料理ドメイン知識の両方が揃って初めて満足する体験が実現します。
Cookpad's search is a mechanism that, in addition to the basics of "ingredient matches" and "high popularity," combines Japanese-specific notation variations, seasonal and regional variation, and individual preferences to deliver "the recipe I want to cook tonight." Only when both machine learning and cooking domain knowledge come together is a satisfying experience realized.