AI で商品レビューを評価する

Maud Nalpas
Maud Nalpas
Kenji Baheux
Kenji Baheux
Alexandra Klepper
Alexandra Klepper

公開日: 2024 年 5 月 16 日

オンライン ショッピングでは、商品のレビュー数や商品数が多すぎて、圧倒されることがあります。このノイズをすべて分類して、特定のニーズを実際に満たす製品を見つけるにはどうすればよいでしょうか?

たとえば、仕事用のバックパックを探しているとします。バックパックは、機能、美しさ、実用性のバランスが取れている必要があります。クチコミの数が多すぎて、完璧なバッグを見つけたかどうかを判断するのはほぼ不可能です。AI を活用してノイズをふるい分け、最適な商品を見つけられたらどうでしょうか?

すべてのレビューの概要と、最も一般的なメリットとデメリットのリストがあると便利です。

星による評価と長所と短所のリストを含むユーザー レビューの例。

これを構築するために、サーバーサイドの生成 AI を使用します。推論はサーバーで行われます。

このドキュメントでは、Google AI JavaScript SDK を使用して多くのレビューからデータを要約する Node.js での Gemini API のチュートリアルに沿って操作できます。この作業では生成 AI の部分に焦点を当てます。結果の保存方法やジョブキューの作成方法については説明しません。

実際には、任意の LLM API を任意の SDK で使用できます。ただし、選択したモデルに合わせて、提案されたプロンプトを調整する必要がある場合があります。

前提条件

  1. Gemini API のキーを作成し、環境ファイルで定義します。

  2. Google AI JavaScript SDK をインストールします(npm などを使用)。 npm install @google/generative-ai

レビュー要約アプリケーションを構築する

  1. 生成 AI オブジェクトを初期化します。
  2. レビューの要約を生成する関数を作成します。
    1. 生成 AI モデルを選択します。このユースケースでは、Gemini Pro を使用します。ユースケースに固有のモデルを使用します(たとえば、gemini-pro-vision はマルチモーダル入力用です)。
    2. プロンプトを追加します。
    3. generateContent を呼び出して、プロンプトを引数として渡します。
    4. レスポンスを生成して返します。
const { GoogleGenerativeAI } = require("@google/generative-ai");

// Access the API key env
const genAI = new GoogleGenerativeAI(process.env.API_KEY_GEMINI);

async function generateReviewSummary(reviews) {
  // Use gemini-pro model for text-only input
  const model = genAI.getGenerativeModel({ model: "gemini-pro" });
  // Shortened for legibility. See "Write an effective prompt" for
  // writing an actual production-ready prompt.
  const prompt = `Summarize the following product reviews:\n\n${reviews}`;
  const result = await model.generateContent(prompt);
  const response = await result.response;
  const summary = response.text();
  return summary;
}

効果的なプロンプトを作成する

生成 AI を効果的に活用するには、詳細なプロンプトを作成することが重要です。この例では、一貫した出力を得るためにワンショット プロンプト手法を使用しています。

ワンショット プロンプトは、Gemini がモデル化する出力例で表されます。

const prompt =
`I will give you user reviews for a product. Generate a short summary of the
reviews, with focus on the common positive and negative aspects across all of
the reviews. Use the exact same output format as in the example (list of
positive highlights, list of negative aspects, summary). In the summary,
address the potential buyer with second person ("you", "be aware").

Input (list of reviews):
// ... example

Output (summary of reviews):
// ... example

**Positive highlights**
// ... example
**Negative aspects**
// ... example
**Summary**
// ... example

Input (list of reviews):
${reviews}

Output (summary of all input reviews):`;

このプロンプトの出力例を次に示します。これには、すべてのレビューの概要と、一般的な長所と短所のリストが含まれています。

## Summary of Reviews:

**Positive highlights:**

* **Style:** Several reviewers appreciate the backpack's color and design.
* **Organization:** Some users love the compartments and find them useful for
  organization.
* **Travel & School:** The backpack seems suitable for both travel and school
  use, being lightweight and able to hold necessary items.

**Negative aspects:**

* **Durability:** Concerns regarding the zipper breaking and water bottle holder
  ripping raise questions about the backpack's overall durability.
* **Size:** A few reviewers found the backpack smaller than expected.
* **Material:** One user felt the material was cheap and expressed concern about
  its longevity.

**Summary:**

This backpack seems to be stylish and appreciated for its organization and
suitability for travel and school. However, you should be aware of potential
durability issues with the zippers and water bottle holder. Some users also
found the backpack smaller than anticipated and expressed concerns about the
material's quality.

トークンの上限

レビューが多すぎると、モデルのトークン上限に達する可能性があります。トークンは必ずしも単語と一致するとは限りません。トークンは単語の一部または複数の単語をまとめたものにすることができます。たとえば、Gemini Pro のトークン上限は 30,720 です。つまり、プロンプトには、英語の 30 語のレビューを平均 600 件まで含めることができます。ただし、プロンプトの残りの指示は除きます。

countTokens() を使用してトークン数を確認し、プロンプトが許容されるサイズを超えている場合は入力を減らします。

const MAX_INPUT_TOKENS = 30720
const { totalTokens } = await model.countTokens(prompt);
if (totalTokens > MAX_INPUT_TOKENS) {
    // Shorten the prompt.
}

企業向けの開発

Google Cloud ユーザーである場合や、エンタープライズ サポートが必要な場合は、Vertex AI を使用して Gemini Pro や Anthropic の Claude モデルなどのモデルにアクセスできます。Model Garden を使用して、特定のユースケースに最適なモデルを特定することをおすすめします。

次のステップ

Google が構築したアプリケーションは、質の高いレビューに大きく依存して、最も効果的な要約を提供します。質の高いレビューを集めるには、このシリーズの次の記事であるオンデバイス ウェブ AI を活用してユーザーが有益な商品レビューを書けるようにするをご覧ください。

このアプローチについて、皆様のご意見をお聞かせください。最も興味深いユースケースをお知らせください。フィードバックを共有して早期プレビュー プログラムに参加すると、ローカル プロトタイプでこのテクノロジーをテストできます。

皆様のご協力により、AI をすべての人にとって強力かつ実用的なツールにすることができます。

次へ: ユーザーが有益な商品レビューを書くのを手伝う