声明类型推断验证状态待复核
35个SKU每月合规审查人力有限不知道应该先审查哪些——ML风险评分输出每个SKU的违规概率将人工审查效率提升3-5倍,主动发现新违规模式避损年化30-120万元
Skill-Compliance-ML-Risk-Scoring
35个SKU每月合规审查人力有限不知道应该先审查哪些——ML风险评分输出每个SKU的违规概率将人工审查效率提升3-5倍,主动发现新违规模式避损年化30-120万元
¥30-120 万(以避损为主)
待企业数据验证 · 缺失:样本、基线、时间窗、币种、计算方法、证据来源
35个SKU每月合规审查人力有限不知道应该先审查哪些——ML风险评分输出每个SKU的违规概率将人工审查效率提升3-5倍,主动发现新违规模式避损年化30-120万元
规则引擎 vs ML 评分的区别:
规则引擎(现有合规工具):
"包含'clinically proven'→违规"
问题:新违规模式出现前无法检测,无法量化风险大小
ML 风险评分:
历史违规案例 → 特征提取 → 梯度提升分类器 → 违规概率
优势:
① 发现规则未覆盖的新模式
② 输出概率(0.05 低风险 vs 0.87 高风险)
③ 自动适应平台政策变化(重训即可)特征工程(三层):
L1 内容特征(Listing文本):
- 违禁词数量(FDA/FTC词典命中数)
- 情感强度(超级夸张词:best/amazing)
- 量化声明密度(数字+百分比数量)
- 比较词密度(better than/compared to)
L2 历史行为特征(卖家账号):
- 历史违规次数(近90天)
- 账号年龄(越新越高风险)
- 产品数量/违规比
- 品类(母婴/健康类高风险)
L3 环境特征(时间/平台):
- 平台近期政策更新(是否有新规)
- 季节(大促前合规审查加强)
- 市场(德国/美国合规要求差异)梯度提升模型(XGBoost):
P(\text{violation}) = \sigma(\text{XGBoost}(\text{features}))输出 0-1 风险概率,按阈值分级:
业务问题:35个SKU每月需要合规审查,但人力有限,每次只能仔细审查8-10个。不知道应该先审查哪些,导致风险最高的SKU被遗漏。
数据要求: - 历史违规记录(被下架/警告的 SKU 及其 Listing 文本) - 当前所有 SKU 的 Listing 草稿 - 账号历史合规行为
预期产出: - 所有 SKU 的违规概率评分(0-1) - 风险排行榜:前 10 个高风险 SKU 优先处理 - 具体高风险特征解释(SHAP 值)
代码块数量:3
"""
Compliance ML Risk Scoring
机器学习合规风险评分模型
"""
import re
import numpy as np
from dataclasses import dataclass
@dataclass
class ListingData:
sku_id: str
title: str
bullets: str
description: str
category: str
account_age_days: int = 365
account_violation_count: int = 0
# 合规风险词典
HIGH_RISK_WORDS = [
'clinically proven', 'fda approved', 'medical grade', 'cure', 'treat',
'guaranteed', 'scientifically proven', '#1', 'best ever',
'clinically tested', 'doctor recommended', 'hospital grade',
]
MODERATE_RISK_WORDS = [
'proven', 'certified', 'clinical', 'medical', 'professional grade',
'recommended by', 'laboratory tested', 'dermatologist',
]
SUPERLATIVE_WORDS = [
'best', 'perfect', 'amazing', 'incredible', 'unbeatable',
'superior', 'ultimate', 'revolutionary', 'breakthrough',
]
COMPARATIVE_WORDS = [
'better than', 'superior to', 'compared to', 'unlike other',
'outperforms', 'more effective than',
]
HIGH_RISK_CATEGORIES = ['health', 'baby', 'infant', 'medical', 'beauty', 'nutrition']
def extract_compliance_features(listing: ListingData) -> np.ndarray:
"""提取合规风险特征向量"""
full_text = f"{listing.title} {listing.bullets} {listing.description}".lower()
word_count = max(len(full_text.split()), 1)
# L1: 内容特征
high_risk_hits = sum(1 for w in HIGH_RISK_WORDS if w in full_text)
moderate_risk_hits = sum(1 for w in MODERATE_RISK_WORDS if w in full_text)
superlative_density = sum(1 for w in SUPERLATIVE_WORDS if w in full_text) / word_count * 100
comparative_hits = sum(1 for w in COMPARATIVE_WORDS if w in full_text)
# 数字声明密度(含%的)
num_claims = len(re.findall(r'\d+\s*%|\d+x\s+', full_text))
# 文本长度(过短可能信息不充分)
text_length_score = min(1.0, len(full_text) / 500)
# L2: 账号历史特征
account_age_norm = min(1.0, listing.account_age_days / 730) # 2年内标准化
violation_rate = listing.account_violation_count / max(1, listing.account_age_days / 30)
# L3: 品类风险
cat_lower = listing.category.lower()
is_high_risk_cat = any(c in cat_lower for c in HIGH_RISK_CATEGORIES)
features = np.array([
high_risk_hits, # 高危词命中数
moderate_risk_hits, # 中危词命中数
superlative_density, # 夸张词密度
comparative_hits, # 比较声明数
num_claims, # 数字声明数
text_length_score, # 文本完整度
account_age_norm, # 账号年龄(越新越高风险,这里取反)
violation_rate * 10, # 违规率
float(is_high_risk_cat), # 高危品类
])
return features
def rule_based_risk_score(features: np.ndarray) -> float:
"""
规则加权风险评分(生产中用 XGBoost 替代)
features: [high_risk_hits, moderate_risk_hits, superlative_density,
comparative_hits, num_claims, text_length, account_age,
violation_rate, is_high_risk_cat]
"""
weights = np.array([0.30, 0.15, 0.10, 0.08, 0.08, -0.05, -0.08, 0.15, 0.07])
raw_score = float(np.dot(features, weights))
# Sigmoid 归一化
risk = 1 / (1 + np.exp(-raw_score + 0.5))
return min(0.99, max(0.01, risk))
def classify_risk(score: float) -> tuple[str, str]:
if score < 0.2:
return 'LOW', '🟢'
elif score < 0.5:
return 'MEDIUM', '🟡'
elif score < 0.8:
return 'HIGH', '🟠'
else:
return 'CRITICAL', '🔴'
def batch_compliance_scoring(listings: list[ListingData]) -> list[dict]:
"""批量合规风险评分,按风险从高到低排序"""
results = []
for listing in listings:
features = extract_compliance_features(listing)
score = rule_based_risk_score(features)
risk_level, icon = classify_risk(score)
top_risks = []
feat_names = ['高危词', '中危词', '夸张词密度', '比较声明', '数字声明', '文本完整度', '账号年龄', '违规率', '高危品类']
for i, (name, val, w) in enumerate(zip(feat_names, features, [0.30,0.15,0.10,0.08,0.08,-0.05,-0.08,0.15,0.07])):
if val * w > 0.05:
top_risks.append(f"{name}:{val:.1f}")
results.append({
'sku_id': listing.sku_id,
'risk_score': round(score, 3),
'risk_level': risk_level,
'icon': icon,
'top_risk_factors': ', '.join(top_risks[:3]),
})
return sorted(results, key=lambda x: -x['risk_score'])
def run_compliance_scoring_demo():
print('=' * 62)
print('Compliance ML Risk Scoring — 合规 ML 风险评分')
print('=' * 62)
listings = [
ListingData('SKU-001', 'Hospital Grade Breast Pump - FDA Approved, Clinically Proven',
'Scientifically proven to increase milk supply. #1 best rated.',
'Medical grade, better than all competitors.', 'Baby Health',
account_age_days=180, account_violation_count=2),
ListingData('SKU-002', 'Ultra-Quiet Double Electric Breast Pump',
'BPA-free silicone. Hospital-strength suction technology. USB rechargeable.',
'Designed for nursing mothers. Compatible with standard bottles.',
'Baby', account_age_days=730, account_violation_count=0),
ListingData('SKU-003', 'Baby Car Seat - Professional Grade, Certified Safe',
'Doctor recommended. Amazing safety features. Unbeatable protection.',
'Superior to competitors. Guaranteed safe.', 'Baby Safety',
account_age_days=365, account_violation_count=1),
ListingData('SKU-004', 'Bamboo Baby Bibs - Soft and Absorbent',
'Made from organic bamboo. Machine washable. Set of 5.',
'Great for babies 0-12 months. Easy to clean.',
'Baby Clothing', account_age_days=900, account_violation_count=0),
]
results = batch_compliance_scoring(listings)
print(f'\n📊 合规风险排行榜(从高到低):')
print(f' {"SKU":<12} {"风险分":>8} {"级别":>10} {"主要风险因素"}')
print(' ' + '-' * 62)
for r in results:
print(f' {r["sku_id"]:<12} {r["risk_score"]:>8.3f} {r["icon"]} {r["risk_level"]:<8} {r["top_risk_factors"]}')
print('\n💡 处理建议:')
for r in results:
if r['risk_level'] in ('CRITICAL', 'HIGH'):
print(f' {r["icon"]} {r["sku_id"]}: 上架前必须修改 (风险分={r["risk_score"]:.3f})')
elif r['risk_level'] == 'MEDIUM':
print(f' {r["icon"]} {r["sku_id"]}: 建议优化后上架')
print('\n[✓] Compliance ML Risk Scoring 测试通过')
if __name__ == '__main__':
run_compliance_scoring_demo()论文链接用于核验方法来源,不自动证明本页商业结果。