创建数据清洗任务
更新时间:2025-05-16
功能介绍
用于创建数据清洗任务。
使用说明
本文API支持通过Python SDK、Go SDK、Java SDK 和 Node.js SDK调用,调用流程请参考SDK安装及使用流程。
权限说明
调用本文API,需符合以下权限要求,权限介绍及分配,请查看角色与权限控制列表、账号创建与权限分配。需具有以下任一权限:
- 完全控制千帆大模型平台的权限:QianfanFullControlAccessPolicy
- 完全控制千帆大模型平台数据管理(除数据标注外)的权限:QianfanDataFullControlAccessPolicy
SDK调用
在千帆平台创建一个数据清洗任务,需要提供源数据集版本 ID source_dataset_id ,目标数据集版本 ID destination_dataset_id 和数据清洗使用的算子参数字典 operations。
调用示例
1import os
2from qianfan import resources
3
4# 通过环境变量初始化认证信息
5# 使用安全认证AK/SK调用,替换下列示例中参数,安全认证Access Key替换your_iam_ak,Secret Key替换your_iam_sk,如何获取请查看https://cloud.baidu.com/doc/Reference/s/9jwvz2egb
6os.environ["QIANFAN_ACCESS_KEY"] = "your_iam_ak"
7os.environ["QIANFAN_SECRET_KEY"] = "your_iam_sk"
8
9
10
11resp = resources.console.utils.call_action(
12 # 调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求结构-请求地址的后缀
13 "/wenxinworkshop/etl/create", "",
14 # 请查看本文请求参数说明,根据实际使用选择参数;对应API调用文档-请求参数-Body参数
15 {
16 "etlTaskName": "清洗任务1",
17 "sourceDatasetId": "ds-9tff1q3h7ngdmgh4",
18 "destDatasetId": "ds-3tfe1q3g7ncdmsh2",
19 "operationsV2": {
20 "clean": [{
21 "name": "remove_invisible_character",
22 "args": {}
23 }, {
24 "name": "replace_uniform_whitespace",
25 "args": {}
26 }, {
27 "name": "remove_non_meaning_characters",
28 "args": {}
29 }, {
30 "name": "replace_traditional_chinese_to_simplified",
31 "args": {}
32 }, {
33 "name": "remove_web_identifiers",
34 "args": {}
35 }, {
36 "name": "remove_emoji",
37 "args": {}
38 }],
39 "deduplication": [{
40 "name": "deduplication_simhash",
41 "args": {
42 "distance": 4
43 }
44 }],
45 "desensitization": [{
46 "name": "replace_emails",
47 "args": {}
48 }, {
49 "name": "replace_ip",
50 "args": {}
51 }, {
52 "name": "replace_identifier",
53 "args": {}
54 }],
55 "filter": [{
56 "name": "filter_check_number_words",
57 "args": {
58 "number_words_min_cutoff": 1,
59 "number_words_max_cutoff": 10000
60 }
61 }, {
62 "name": "filter_check_word_repetition_removal",
63 "args": {
64 "word_repetition_max_cutoff": 0.96
65 }
66 }, {
67 "name": "filter_check_special_characters",
68 "args": {
69 "special_characters_max_cutoff": 0.3
70 }
71 }, {
72 "name": "filter_check_flagged_words",
73 "args": {
74 "flagged_words_max_cutoff": 0.3
75 }
76 }]
77 },
78 "entityType": 2
79 }
80
81)
82
83print(resp.body)
1package main
2import (
3 "context"
4 "fmt"
5 "os"
6 "github.com/baidubce/bce-qianfan-sdk/go/qianfan"
7)
8func main() {
9 // 使用安全认证AK/SK鉴权,通过环境变量初始化;替换下列示例中参数,安全认证Access Key替换your_iam_ak,Secret Key替换your_iam_sk
10 os.Setenv("QIANFAN_ACCESS_KEY", "your_iam_ak")
11 os.Setenv("QIANFAN_SECRET_KEY", "your_iam_sk")
12
13 ca := qianfan.NewConsoleAction()
14
15 res, err := ca.Call(context.TODO(),
16 // 调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求结构-请求地址的后缀
17 "/wenxinworkshop/etl/create", "",
18 // 请查看本文请求参数说明,根据实际使用选择参数;对应API调用文档-请求参数-Body参数
19 map[string]interface{}{
20 "etlTaskName": "清洗任务1",
21 "sourceDatasetId": "ds-9tff1q3h7ngdmgh4",
22 "destDatasetId": "ds-3tfe1q3g7ncdmsh2",
23 "operationsV2": map[string]any{
24 "clean": []map[string]any{{
25 "name": "remove_invisible_character",
26 "args": map[string]any{},
27 }, {
28 "name": "replace_uniform_whitespace",
29 "args": map[string]any{},
30 }, {
31 "name": "remove_non_meaning_characters",
32 "args": map[string]any{},
33 }, {
34 "name": "replace_traditional_chinese_to_simplified",
35 "args": map[string]any{},
36 }, {
37 "name": "remove_web_identifiers",
38 "args": map[string]any{},
39 }, {
40 "name": "remove_emoji",
41 "args": map[string]any{},
42 }},
43 "deduplication": []map[string]any{{
44 "name": "deduplication_simhash",
45 "args": map[string]any{
46 "distance": 4,
47 },
48 }},
49 "desensitization": []map[string]any{{
50 "name": "replace_emails",
51 "args": map[string]any{},
52 }, {
53 "name": "replace_ip",
54 "args": map[string]any{},
55 }, {
56 "name": "replace_identifier",
57 "args": map[string]any{},
58 }},
59 "filter": []map[string]any{{
60 "name": "filter_check_number_words",
61 "args": map[string]any{
62 "number_words_min_cutoff": 1,
63 "number_words_max_cutoff": 10000,
64 },
65 }, {
66 "name": "filter_check_word_repetition_removal",
67 "args": map[string]any{
68 "word_repetition_max_cutoff": 0.96,
69 },
70 }, {
71 "name": "filter_check_special_characters",
72 "args": map[string]any{
73 "special_characters_max_cutoff": 0.3,
74 },
75 }, {
76 "name": "filter_check_flagged_words",
77 "args": map[string]any{
78 "flagged_words_max_cutoff": 0.3,
79 },
80 }},
81 },
82 "entityType": 2,
83 })
84 if err != nil {
85 panic(err)
86 }
87 fmt.Println(string(res.Body))
88
89}
1import com.baidubce.qianfan.Qianfan;
2import com.baidubce.qianfan.model.console.ConsoleResponse;
3import com.baidubce.qianfan.util.CollUtils;
4import com.baidubce.qianfan.util.Json;
5import java.util.Map;
6
7public class Dome {
8 public static void main(String args[]){
9 // 使用安全认证AK/SK鉴权,替换下列示例中参数,安全认证Access Key替换your_iam_ak,Secret Key替换your_iam_sk
10 Qianfan qianfan = new Qianfan("your_iam_ak", "your_iam_sk");
11
12 ConsoleResponse<Map<String, Object>> response = qianfan.console()
13 // 调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求结构-请求地址的后缀
14 .route("/wenxinworkshop/etl/create")
15 // 需要传入参数的场景,可以自行封装请求类,或者使用Map.of()来构建请求Body
16 // Java 8可以使用SDK提供的CollUtils.mapOf()来替代Map.of()
17 // 请查看本文请求参数说明,根据实际使用选择参数;对应API调用文档-请求参数-Body参数
18 .body(CollUtils.mapOf(
19 "etlTaskName", "清洗任务1",
20 "sourceDatasetId", "ds-9tff1q3h7ngdmgh4",
21 "destDatasetId", "ds-3tfe1q3g7ncdmsh2",
22 "operationsV2", CollUtils.mapOf(
23 "clean", new Map[]{CollUtils.mapOf(
24 "name", "remove_invisible_character",
25 "args", CollUtils.mapOf()
26 ), CollUtils.mapOf(
27 "name", "replace_uniform_whitespace",
28 "args", CollUtils.mapOf()
29 ), CollUtils.mapOf(
30 "name", "remove_non_meaning_characters",
31 "args", CollUtils.mapOf()
32 ), CollUtils.mapOf(
33 "name", "replace_traditional_chinese_to_simplified",
34 "args", CollUtils.mapOf()
35 ), CollUtils.mapOf(
36 "name", "remove_web_identifiers",
37 "args", CollUtils.mapOf()
38 ), CollUtils.mapOf(
39 "name", "remove_emoji",
40 "args", CollUtils.mapOf()
41 )},
42 "deduplication", new Map[]{CollUtils.mapOf(
43 "name", "deduplication_simhash",
44 "args", CollUtils.mapOf(
45 "distance", 4
46 )
47 )},
48 "desensitization", new Map[]{CollUtils.mapOf(
49 "name", "replace_emails",
50 "args", CollUtils.mapOf()
51 ), CollUtils.mapOf(
52 "name", "replace_ip",
53 "args", CollUtils.mapOf()
54 ), CollUtils.mapOf(
55 "name", "replace_identifier",
56 "args", CollUtils.mapOf()
57 )},
58 "filter", new Map[]{CollUtils.mapOf(
59 "name","filter_check_number_words",
60 "args", CollUtils.mapOf(
61 "number_words_min_cutoff", 1,
62 "number_words_max_cutoff", 10000
63 )
64 ), CollUtils.mapOf(
65 "name", "filter_check_word_repetition_removal",
66 "args", CollUtils.mapOf(
67 "word_repetition_max_cutoff", 0.96
68 )
69 ), CollUtils.mapOf(
70 "name", "filter_check_special_characters",
71 "args", CollUtils.mapOf(
72 "special_characters_max_cutoff", 0.3
73 )
74 ),CollUtils.mapOf(
75 "name", "filter_check_flagged_words",
76 "args", CollUtils.mapOf(
77 "flagged_words_max_cutoff", 0.3
78 )
79 )}
80 ),
81 "entityType", 2
82 ))
83 .execute();
84
85 System.out.println(Json.serialize(response));
86 }
87}
1import {consoleAction, setEnvVariable} from "@baiducloud/qianfan";
2
3// 使用安全认证AK/SK鉴权,通过环境变量初始化;替换下列示例中参数,安全认证Access Key替换your_iam_ak,Secret Key替换your_iam_sk
4setEnvVariable('QIANFAN_ACCESS_KEY','your_iam_ak');
5setEnvVariable('QIANFAN_SECRET_KEY','your_iam_sk');
6
7async function main() {
8 //base_api_route:调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求结构-请求地址的后缀
9 //data:请查看本文请求参数说明,根据实际使用选择参数;对应API调用文档-请求参数-Body参数
10 const res = await consoleAction({base_api_route: '/wenxinworkshop/etl/create', data: {
11 "etlTaskName": "清洗任务1",
12 "sourceDatasetId": "ds-9tff1q3h7ngdmgh4",
13 "destDatasetId": "ds-3tfe1q3g7ncdmsh2",
14 "operationsV2": {
15 "clean": [{
16 "name": "remove_invisible_character",
17 "args": {}
18 }, {
19 "name": "replace_uniform_whitespace",
20 "args": {}
21 }, {
22 "name": "remove_non_meaning_characters",
23 "args": {}
24 }, {
25 "name": "replace_traditional_chinese_to_simplified",
26 "args": {}
27 }, {
28 "name": "remove_web_identifiers",
29 "args": {}
30 }, {
31 "name": "remove_emoji",
32 "args": {}
33 }],
34 "deduplication": [{
35 "name": "deduplication_simhash",
36 "args": {
37 "distance": 4
38 }
39 }],
40 "desensitization": [{
41 "name": "replace_emails",
42 "args": {}
43 }, {
44 "name": "replace_ip",
45 "args": {}
46 }, {
47 "name": "replace_identifier",
48 "args": {}
49 }],
50 "filter": [{
51 "name": "filter_check_number_words",
52 "args": {
53 "number_words_min_cutoff": 1,
54 "number_words_max_cutoff": 10000
55 }
56 }, {
57 "name": "filter_check_word_repetition_removal",
58 "args": {
59 "word_repetition_max_cutoff": 0.96
60 }
61 }, {
62 "name": "filter_check_special_characters",
63 "args": {
64 "special_characters_max_cutoff": 0.3
65 }
66 }, {
67 "name": "filter_check_flagged_words",
68 "args": {
69 "flagged_words_max_cutoff": 0.3
70 }
71 }]
72 },
73 "entityType": 2
74 }
75 });
76
77 console.log(res);
78}
79
80main();
返回示例
1{
2 "log_id": "i9vswaefzbqpu92d",
3 "result": "task-wtff1q3h7nfd3g54",
4 "status": 200,
5 "success": True
6}
1{
2 "log_id": "i9vswaefzbqpu92d",
3 "result": "task-wtff1q3h7nfd3g54",
4 "status": 200,
5 "success": true
6}
1{
2 "log_id": "i9vswaefzbqpu92d",
3 "result": "task-wtff1q3h7nfd3g54",
4 "status": 200,
5 "success": true
6}
1{
2 log_id: 'i9vswaefzbqpu92d',
3 result: 'task-wtff1q3h7nfd3g54',
4 status: 200,
5 success: true
6}
请求参数
名称 | 必填 | 类型 | 描述 |
---|---|---|---|
etlTaskName | 是 | string | 清洗任务名称 |
sourceDatasetId | 是 | string | 清洗前的源数据集版本ID,说明: 该字段新增支持string类型;如果之前接入时使用的int类型,建议变更为string类型,后续将逐渐废弃int类型 |
destDatasetId | 是 | string | 清洗后的目标数据集版本ID,说明: 该字段新增支持string类型;如果之前接入时使用的int类型,建议变更为string类型,后续将逐渐废弃int类型 |
entityType | 是 | int | 清洗样本类型,固定值为2,表示文本 |
operationsV2 | 是 | map[string][]object | 清洗配置 ,说明: (1)key为string,需包括以下值: · 清洗:clean · 过滤:filter · 去重:deduplication · 去隐私:desensitization (2)value为list,值为单个阶段用户所选择的所有算子组成的列表 · 列表中的每个元素,对应某个算子的配置,格式参考operationsV2说明 · 如果用户没有在对应阶段选择任何算子,则value为空列表 |
operationV2说明
名称 | 类型 | 描述 |
---|---|---|
name | string | 算子名称,见各阶段name值和args值 (1)Clean清洗阶段算子 · remove_emoji:去除文档中的表情等 · remove_invisible_character:移除ASCII中的一些不可见字符, 如0-32 和127-160这两个范围 · replace_uniform_whitespace:将不同的unicode空格比如 u2008,转成正常的空格 · remove_non_meaning_characters:去除乱码和无意义的unicode · replace_traditional_chinese_to_simplified:繁体转简体,如“不經意,妳的笑容”清洗成“不经意,你的笑容” · remove_web_identifiers:移除文档中的html标签,如 <html>,<dev>,<p> 等(2)Filter过滤阶段算子 · filter_check_number_words:检查文档的词数目,词数目不在指定范围会被过滤掉,如中文[1,10000] · filter_check_word_repetition_removal:检查文档的词重复率,如果词重复率太高,意味着文档中重复的词太多,文档会被过滤掉 · filter_check_character_repetition_removal:检查文档的字重复率,如果字重复率太高,意味着文档中重复的字太多,文档会被过滤掉 · filter_check_special_characters:检查文档的特殊字符率,如果特殊字符率太高,意味着文档中特殊字符太多,文档会被过滤掉 ·filter_check_flagged_words:检查文档的色情暴力词率,如果色情暴力词率太高,文档会被过滤掉 · filter_check_lang_id:检查文档的语言概率,如果语言概率太低,文档会被过滤掉 · filter_check_perplexity:检查文档的困惑度,如果困惑度太高,文档会被过滤掉 (3)Deduplication去重阶段算子 · deduplication_simhash:根据海明距离计算文档相似度, 相似度<=海明距离,认为两个文档相似。 (4)Desensitization 去隐私阶段算子 · replace_emails:去除email地址 · replace_ip:去除IPv4 或者 IPv6 地址 · replace_identifier:去除数字和字母数字标识符,如电话号码、信用卡号、十六进制散列等,同时跳过年份和简单数字的实例 |
args | object | 算子参数,格式随参数名称而变化,见各阶段name值对应的args说明: · 当name为Clean清洗阶段算子,args值为空 · 当name为Desensitization 去隐私阶段算子,args值为空 · 当name为Deduplication或Desensitization,请查看args说明 |
args说明
- 当name为Clean清洗阶段算子,args值为空
- 当name为Desensitization 去隐私阶段算子,args值为空
- 当name为Deduplication去重阶段算子,args说明如下
名称 | 类型 | 描述 |
---|---|---|
distance | int | 范围4-6 |
- 当name为Filter过滤阶段算子,args说明如下
名称 | 类型 | 描述 |
---|---|---|
number_words_min_cutoff | float | 最小词数目 · 范围为[1,10000] · 当name=filter_check_number_words,该字段必填 |
number_words_max_cutoff | float | 最大词数目 · 范围为[1,10000] · 当name=filter_check_number_words,该字段必填 |
word_repetition_max_cutoff | float | 文档的词重复率 · 范围为0-1 · 当name=filter_check_word_repetition_removal,该字段必填 |
default_character_repetition_max_cutoff | float | 文档的字重复率 · 范围为0-1 · 当name=filter_check_character_repetition_removal,该字段必填 |
special_characters_max_cutoff | float | 检查文档的特殊字符率,如果特殊字符率太高,意味着文档中特殊字符太多,文档会被过滤掉 · 范围为0-1 · 当name=filter_check_special_characters,该字段必填 |
flagged_words_max_cutoff | float | 检查文档的色情暴力词率,如果色情暴力词率太高,文档会被过滤掉 ·范围为0-1 · 当name=filter_check_flagged_words,该字段必填 |
lang_id_min_cutoff | float | 检查文档的语言概率,如果语言概率太低,文档会被过滤掉 · 范围为0-1 · 当name=filter_check_lang_id,该字段必填 |
perplexity_max_cutoff | float | 检查文档的困惑度,如果困惑度太高,文档会被过滤掉 ·范围为1-5000 · 当name=filter_check_perplexity,该字段必填 |
返回参数
名称 | 类型 | 描述 |
---|---|---|
log_id | string | 操作记录id |
result | string | 清洗任务序号 |
status | int | 状态码 |
success | bool | 是否操作成功,说明: · true:成功 · false:失败 |