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

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

オンラインでショッピングする場合、商品レビューのボリュームや在庫のある商品の数を見て、戸惑うことがあります。あらゆるノイズの中から特定のニーズを実際に満たすプロダクトを 見つけるにはどうすればよいか?

たとえば、仕事用のバックパックを購入するとします。バックパックは、機能、美しさ、実用性のバランスを考慮する必要があります。レビューの多さから、完璧なバッグを見つけることはほぼ不可能です。AI を使用してノイズをふるいにかけ 最適な商品を見つけられるとしたら?

すべてのレビューの概要と、一般的な長所と短所の一覧が役立つはずです。

肯定的なハイライトと否定的なハイライトを含むユーザー レビューの例。
星評価と長所と短所のリストが記載されたユーザー レビューの例

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

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

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

前提条件

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

  2. npm などを使用して、Google AI JavaScript SDK をインストールします。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.

トークンの上限

多くのレビューがモデルのトークンの上限に達する可能性があります。トークンは、必ずしも 1 つの単語と等しいわけではありません。1 つの単語を構成することも、複数の単語を構成することもできます。たとえば、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 を使用すると、特定のユースケースに最適なモデルを特定できます。

次のステップ

私たちが構築したアプリケーションは、最も効果的な要約を提供するために品質レビューに大きく依存しています。このような品質レビューを収集するには、このシリーズの次の記事デバイス上のウェブ AI を使用してユーザーが有用な商品レビューを作成するのをサポートするをご覧ください。

このアプローチについて、ご意見をお聞かせください。最も関心のあるユースケースを教えてくださいフィードバックを送信して早期プレビュー プログラムに参加すると、このテクノロジーをローカル プロトタイプでテストできます。

皆様のご協力は、AI を強力でありながら実用的なツールにするために役立てられます。

次へ: 有益な商品レビューの投稿をサポートする