百度内容审查做敏感词库筛选

最近在做项目的敏感词库筛选更新。笔者最终的目标是通过百度API将现有的敏感词库筛选更新成。

一、准备工作

读者需在百度智能云登陆账号,然后开通百度内容审核功能,然后根据API Key和Secret Key可以获得调用接口所需的access_token。

二、代码调用API进行筛选

获得API后就是写代码进行筛选了,笔者Python代码如下:

import requests
import json

#获取审核结果
def get_result(data_str):
    params = {'text': data_str}
    request_url = 'https://aip.baidubce.com/rest/2.0/solution/v1/text_censor/v2/user_defined?access_token=【此处写你自己的token】'

    result = requests.post(request_url, headers={'Content-Type': 'application/x-www-form-urlencoded'}, data=params).text
    predict_res = json.loads(result)
    print(predict_res)
    return predict_res['conclusion']

#读取待测文本
def get_txt():
    with open('./待筛选文本/po/drug.txt', 'r', encoding='utf-8') as f:
        with open('./筛选结果/drug_检测失效.txt', 'a', encoding='utf-8') as f_err:
            with open('./筛选结果/po/drug.txt', 'a', encoding='utf-8') as f_result:
                for line in f:
        #             print(line.replace('\n',''))
                    result = get_result(line.replace('\n',''))
                    if result == "疑似":
                        f_result.write(line)
                    elif result == "不合规":
                        f_result.write(line)
                    elif result == "合规":
                        print(line.replace('\n','')+"检测结果为合规")
                    else:
                        print(line.replace('\n','')+"检测失效")
                        f_err.write(line)
#主函数
if __name__ == '__main__':
    get_txt()
    print("筛选结束")

三、筛选结果

敏感词筛选分为两个部分:中文敏感词和藏文敏感词。中文部分的敏感词除了分为六个大类外,还将敏感词分为正向敏感词和负向敏感词。藏文敏感词则只是将敏感词分为六个大类,未分正负向:

筛选前后的敏感词库已经上传到CSDN,需要的读者可自行下载:https://download.csdn.net/download/m0_37872090/12274456

该词库仅用于技术测试,严禁用于违法活动!

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 11
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值