
為電商微調產品推薦模型:完整演示
通用推薦引擎錯過語義產品關係。以下是如何在你的目錄和購買歷史上微調模型,構建增加平均訂單價值的推薦引擎。
協同過濾推薦「其他客戶也購買了 X」。它適用於熱門產品,但在長尾上失敗——而且它完全沒有語義理解。購買露營爐的客戶可能應該看到引火材料和防水火柴。協同過濾只有在足夠多的其他客戶精確地一起購買了這些物品時才知道這一點。
微調的語言模型語義地理解產品關係。你可以在你的目錄、購買歷史和客戶互動上訓練它,構建了解你的產品實際用途的推薦引擎。
你在構建什麼
一個接受產品(或購物車)作為輸入並返回排名推薦的模型。範例:
輸入:
Customer is viewing: Jetboil Flash Camping Stove
Cart contains: Sleeping bag, tent stakes
Recommend 5 complementary products from our catalog.
輸出:
1. MSR Fuel Canister 110g — Required fuel for Jetboil Flash operation
2. UCO Stormproof Matches — Backup ignition, waterproof
3. Sea to Summit Alpha Light Spork — Lightweight utensil for camp cooking
4. Nalgene Wide Mouth Bottle 32oz — Water container for cooking
5. Bear Canister — Required food storage for backcountry camping
這不是協同過濾。模型知道露營爐需要燃料、防水火柴是備用點火器,以及烹飪器具在上下文中是相關的。它從對你目錄的語義理解中產生這些。
資料需求
最小可行資料集: 500 個(產品/購物車,推薦)配對
推薦資料集大小: 2,000-5,000 個範例
你需要的資料:
- 帶描述的產品目錄(SKU、名稱、描述、類別、屬性)
- 購買歷史(訂單 ID,每個訂單的產品 ID)
- 已轉化的現有推薦(如果你有推薦資料)
如何從購買歷史構建訓練範例:
- 取包含 3 個以上商品的訂單
- 使用購買的商品作為「購物車」輸入
- 使用剩餘商品作為「正確推薦」輸出
- 過濾掉推薦商品不是明顯類別匹配的訂單(去除噪音)
第 1 步:準備你的資料集
將你的產品目錄匯出為 JSON:
{
"sku": "JB-FLASH-BLK",
"name": "Jetboil Flash Camping Stove",
"description": "Fast, lightweight backpacking stove. Boils 1L water in 100 seconds. Requires Jetboil fuel canister.",
"category": "Camping Stoves",
"attributes": {
"weight": "13.1 oz",
"compatible_fuel": "Jetboil fuel canisters",
"use_case": "backpacking, ultralight camping"
}
}
匯出購買歷史並構建推薦配對為 JSONL:
{"messages": [{"role": "user", "content": "Customer viewing: Jetboil Flash Camping Stove. Recommend 3 complementary products."}, {"role": "assistant", "content": "1. Jetboil JetPower Fuel 100g — Required fuel for Jetboil Flash\n2. UCO Stormproof Match Kit — Backup ignition\n3. Sea to Summit Alpha Light Spork Set — Lightweight eating utensil for camp cooking"}]}
{"messages": [{"role": "user", "content": "Cart: 2-person backpacking tent, sleeping bag. Recommend 3 complementary products."}, {"role": "assistant", "content": "1. Sleeping bag liner — Adds warmth and extends temperature range\n2. Tent footprint — Protects tent floor from abrasion\n3. Headlamp — Essential for camp use at night"}]}
系統訊息應描述模型的角色和你的目錄範圍:
{"messages": [{"role": "system", "content": "You are a product recommendation assistant for [Brand], an outdoor gear retailer. Recommend products from our catalog that are genuinely complementary — based on functional need, common use together, or upgrade path. Be specific about why each product complements the item(s) in the cart."}, ...]}
第 2 步:使用 Ertas 訓練
- 在 Ertas 中上傳你的 JSONL 資料集
- 驗證資料集(Ertas 將標記格式錯誤)
- 選擇基礎模型(Mistral 7B 或 Llama 3 8B 對推薦任務效果很好)
- 啟動訓練任務
有 2,000 個範例的資料集,訓練通常需要 30-60 分鐘。除非你有特定原因進行調整,否則使用預設 LoRA 設置運行。
第 3 步:評估
你的評估集應該在訓練前保留——使用 10-15% 的資料集進行評估。
關鍵指標:
- 模型是否推薦目錄中的真實產品(幻覺率)?
- 推薦是否在語義上相關?
- 推薦是否具體到有用?
評估提示: 通過模型運行評估集中的 50-100 個產品。手動評分每個推薦集:3 分 = 全部相關,2 分 = 大多數相關,1 分 = 大多數不相關。目標平均分:2.5 分以上。
常見問題:
- 模型推薦目錄中不存在的產品 → 添加更多帶有具體 SKU 引用的範例
- 推薦過於通用 → 添加更多帶有功能說明的具體範例
- 模型重複相同的產品 → 添加更多目錄多樣性的範例
第 4 步:整合到你的 Shopify / 電商平台
從 Ertas 將訓練後的模型匯出為 GGUF,使用 Ollama 部署。
Shopify 整合(通過自訂應用程式或 Shopify Functions):
// 在你的產品頁面組件中
async function getRecommendations(product, cart) {
const response = await fetch('http://your-ollama-server:11434/api/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
model: 'your-recommendation-model',
messages: [
{
role: 'user',
content: `Customer viewing: ${product.title}. Cart: ${cart.map(i => i.title).join(', ')}. Recommend 4 complementary products.`
}
],
stream: false
})
});
const data = await response.json();
return parseRecommendations(data.message.content);
}
解析模型輸出以擷取產品名稱,然後通過 Shopify Product API 將它們與你的目錄匹配。
測量改進
追蹤前後對比:
- 推薦點擊率(推薦小工具上的 CTR)
- 從推薦加入購物車(次要加入率)
- 平均訂單價值(最終指標)
訓練良好的推薦模型 vs 通用協同過濾的典型改進:
- CTR:+15-30%
- 次要加入率:+20-40%
- 平均訂單價值(AOV):+3-8%
對每月收入 $50,000 的商店,5% 的 AOV 改進是每月 $2,500——每年 $30,000。模型在幾週內就能收回其訓練成本。
Ship AI that runs on your users' devices.
Ertas early bird pricing starts at $14.50/mo — locked in for life. Plans for builders and agencies.
延伸閱讀
- E-Commerce AI Agency Opportunity — 完整的電商垂直市場概覽
- E-Commerce Customer Service AI — 支援票自動化
- Shopify AI Without API Costs — 在 Shopify 中替換 OpenAI 呼叫
- Fine-Tune Once, Charge Monthly — 產品化服務模型
Ship AI that runs on your users' devices.
Early bird pricing starts at $14.50/mo — locked in for life. Plans for builders and agencies.
Keep reading

E-Commerce Customer Service AI: Build a Fine-Tuned Support Model
Replace expensive GPT-4 support calls with a fine-tuned model trained on your ticket history. Here's the full build: data prep, training, deployment, and accuracy targets.

E-Commerce Product Catalog AI Classification: Fine-Tuned Category Models
Manually categorizing thousands of SKUs is expensive and inconsistent. A fine-tuned classifier trained on your taxonomy reduces categorization time by 80% and improves consistency across your catalog.

Fine-Tune a Listing Description AI for Real Estate: Step-by-Step
Real estate agents spend 30-45 minutes writing each listing. A fine-tuned model trained on the brokerage's own listings generates on-brand descriptions in 2 minutes. Here's how to build it.