← 返回首页 📖 📖 Wiki知识库
📐 学习维度 本篇是 📖 📖 Wiki知识库 🏠 首页 🛤️ 学习路径 📚 全部文章

AI大模型备案合规深度实战 - 七、内容安全与意识形态审核

本文是 AI大模型备案合规深度实战 的分章阅读版。

七、内容安全与意识形态审核

7.1 内容审核三道防线


[Line 1] 输入审核: 用户输入过滤
[Line 2] 生成审核: LLM 生成时实时过滤
[Line 3] 输出审核: 返回前最终审核

7.2 输入审核


@Service
public class InputSafetyFilter {
    @Autowired private List<SafetyDetector> detectors;
    
    public SafetyVerdict check(String userInput) {
        for (SafetyDetector d : detectors) {
            SafetyVerdict v = d.check(userInput);
            if (v.isBlocked()) return v;
        }
        return SafetyVerdict.safe();
    }
}

@Component
public class KeywordDetector implements SafetyDetector {
    private static final Set<String> BLACKLIST = Set.of(
        // 颠覆国家政权类
        // 民族歧视类
        // 暴力恐怖类
        // 淫秽色情类
        // ... 网信办敏感词库
    );
    
    public SafetyVerdict check(String text) {
        for (String word : BLACKLIST) {
            if (text.contains(word)) {
                return SafetyVerdict.block("keyword:" + word, 
                    Category.ILLEGAL_CONTENT);
            }
        }
        return SafetyVerdict.safe();
    }
}

@Component
public class PoliticalDetector implements SafetyDetector {
    public SafetyVerdict check(String text) {
        // 1. 领导人姓名 + 负面词组合
        // 2. 历史事件敏感表述
        // 3. 国家主权问题(台独/藏独/疆独)
        // 用 NLP 模型检测
        return politicalClassifier.check(text);
    }
}

@Component
public class LLMSafetyClassifier implements SafetyDetector {
    @Autowired private LLMClient safetyLLM;
    
    public SafetyVerdict check(String text) {
        String prompt = """
            判断用户输入是否包含:
            1. 违法内容(暴力/色情/恐怖)
            2. 政治敏感
            3. 个人信息侵犯
            4. 知识产权侵犯
            
            输出 JSON: {"safe": true/false, "category": "...", "reason": "..."}
            
            用户输入: {{text}}
            """;
        String result = safetyLLM.chat(prompt, Map.of("text", text));
        SafetyResponse r = parseJson(result, SafetyResponse.class);
        return r.isSafe() ? SafetyVerdict.safe() 
                         : SafetyVerdict.block(r.getCategory());
    }
}

7.3 输出审核


@Service
public class OutputSafetyFilter {
    @Autowired private InputSafetyFilter safetyFilter;
    @Autowired private HallucinationDetector hallucinationDetector;
    
    public String sanitize(String output, String userInput) {
        // 1. 关键词过滤
        SafetyVerdict v = safetyFilter.check(output);
        if (v.isBlocked()) {
            auditService.logViolation(userInput, output, v);
            return SAFE_FALLBACK;
        }
        
        // 2. 幻觉检测
        if (hallucinationDetector.isHallucinated(output, userInput)) {
            return "抱歉,我无法确定答案。";
        }
        
        // 3. 添加 AI 生成标识(深度合成规定)
        return "[本回答由 AI 生成]\n" + output;
    }
    
    private static final String SAFE_FALLBACK = 
        "抱歉,我无法回答这个问题。请尝试其他问题。";
}

7.4 内容审核平台选型

平台厂商价格特点
网易易盾网易¥0.01-0.05/次综合性强
阿里绿网阿里¥0.005-0.03/次中文最强
百度内容审核百度¥0.01/次模型好
腾讯天御腾讯¥0.01/次生态好
数美第三方¥0.008/次性价比
自建-服务器成本完全可控

7.5 意识形态特殊要求


@Component
public class IdeologyGuard {
    // 中国历史敏感事件
    private static final List<String> SENSITIVE_EVENTS = List.of(
        "1989",
        "六四",
        "天安门事件",
        // ... 其他
    );
    
    // 领导人敏感词
    private static final List<String> LEADER_NAMES = List.of(
        // 历届领导人
    );
    
    // 国家主权
    private static final List<String> SOVEREIGNTY = List.of(
        "台湾独立", "西藏独立", "新疆独立", "香港独立",
        "Two Chinas", "One China One Taiwan"
    );
    
    public SafetyVerdict check(String text) {
        for (String event : SENSITIVE_EVENTS) {
            if (text.contains(event)) {
                return SafetyVerdict.block("sensitive_event", 
                    Category.POLITICAL);
            }
        }
        // ...
        return SafetyVerdict.safe();
    }
}


相关页面