pawizard commited on
Commit
aa7739c
·
verified ·
1 Parent(s): fc7ad74

Upload traffic classifier with ONNX exports

Browse files
DATA_SOURCES.md ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 数据源说明
2
+
3
+ 本项目当前使用三分类标签:
4
+
5
+ | label | 含义 |
6
+ | --- | --- |
7
+ | 0 | 非研发相关 |
8
+ | 1 | 研发相关 |
9
+ | 2 | 中性 |
10
+
11
+ ## 当前推荐数据集
12
+
13
+ 推荐使用精简后的数据集:
14
+
15
+ - 原始精简 CSV:`data/refined_compact_labeled.csv`
16
+ - 训练集:`data_refined/train.csv`
17
+ - 验证集:`data_refined/val.csv`
18
+ - 测试集:`data_refined/test.csv`
19
+
20
+ 当前精简 CSV 的类别分布:
21
+
22
+ | label | 含义 | 数量 |
23
+ | --- | --- | ---: |
24
+ | 0 | 非研发相关 | 22337 |
25
+ | 1 | 研发相关 | 68779 |
26
+ | 2 | 中性 | 2312 |
27
+
28
+ 切分比例由 `data_prep.py` 生成,约为 `8:1:1`。
29
+
30
+ ## 数据来源
31
+
32
+ ### THUOCL
33
+
34
+ - 仓库:https://github.com/thunlp/THUOCL
35
+ - 用途:提供中文领域词库。
36
+ - 中间产物:`data/thuocl_labeled.csv`
37
+
38
+ 初始映射中,`THUOCL_IT.txt` 标为研发相关,其他领域曾用于非研发或中性候选。当前精简数据集中仅保留部分高权重词:
39
+
40
+ - `IT`:研发相关,全量保留去重后的词条
41
+ - 其他 THUOCL 领域:非研发相关,每个领域最多保留 300 条
42
+
43
+ ### DomainWordsDict
44
+
45
+ - 仓库:https://github.com/liuhuanyong/DomainWordsDict
46
+ - 用途:提供大规模中文领域词库。
47
+ - 中间产物:`data/domain_words_labeled.csv`
48
+
49
+ 当前精简映射:
50
+
51
+ - `计算机业`:研发相关,全量保留去重后的词条
52
+ - `电子工程`:研发相关,全量保留去重后的词条
53
+ - `通信工程`:研发相关,全量保留去重后的词条
54
+ - 其他领域:非研发相关,每个领域最多保留 300 条
55
+
56
+ 旧版曾把 `网络用语`、`诗词歌赋`、`文学名著`、`汉语言学` 标为中性;当前已取消这个策略,这些领域在精简数据集中都按非研发相关处理。
57
+
58
+ ### computerese-cross-references
59
+
60
+ - 仓库:https://github.com/EarsEyesMouth/computerese-cross-references
61
+ - 用途:补充计算机专业术语中英文对照。
62
+ - 中间产物:`data/computerese_labeled.csv`
63
+
64
+ 该仓库主要内容在 `README.md` 的 Markdown 表格中。当前抽取策略:
65
+
66
+ - 英文术语全部标为研发相关
67
+ - 中文释义只保留明显具有技术语义的短语
68
+ - 过滤掉过于泛化的中文词,例如“获取”这类容易导致误判的词
69
+
70
+ 当前精简数据集中,`computerese` 全量保留去重后的词条,约 1650 条。
71
+
72
+ ### stopwords
73
+
74
+ - 仓库:https://github.com/goto456/stopwords
75
+ - 用途:提供中性类样本。
76
+ - 使用文件:
77
+ - `baidu_stopwords.txt`
78
+ - `cn_stopwords.txt`
79
+ - `hit_stopwords.txt`
80
+ - `scu_stopwords.txt`
81
+
82
+ 当前策略:
83
+
84
+ - 所有去重后的停用词标为 `2=中性`
85
+ - 中性类只来自该停用词仓库
86
+ - 例如“继续”会被标为中性
87
+
88
+ ## 生成策略
89
+
90
+ 精简数据集的目标是避免中性和非研发样本过多,降低类别不均衡和噪声。
91
+
92
+ 当前规则:
93
+
94
+ | 类别 | 来源 | 保留策略 |
95
+ | --- | --- | --- |
96
+ | 研发相关 | `IT`、`计算机业`、`电子工程`、`通信工程`、`computerese` | 全量保留去重后的词条,并优先于非研发来源 |
97
+ | 中性 | stopwords | 全量去重保留 |
98
+ | 非研发相关 | 其他领域词库 | 每个领域最多 300 条 |
99
+
100
+ 生成后的 CSV 字段:
101
+
102
+ | 字段 | 含义 |
103
+ | --- | --- |
104
+ | `text` | 训练文本 |
105
+ | `label` | 标签 ID |
106
+ | `label_name` | 标签名称 |
107
+ | `category` | 来源领域或类别 |
108
+ | `df` | 原词库权重或词频,部分来源为空 |
109
+ | `source_file` | 来源文件 |
110
+
111
+ ## 注意事项
112
+
113
+ - 当前数据主要是词库,不是完整用户 query。训练出的模型更偏向领域词识别,后续应补充真实用户话术。
114
+ - 中性类目前使用停用词近似表达,如“继续”“好的”“然后”等,适合覆盖短指令和弱语义输入。
115
+ - 非研发相关按领域抽样压缩后,与研发相关数量大致均衡,适合先训练一个轻量 baseline。
116
+ - 若后续新增真实标注样本,建议优先加入 `data/refined_compact_labeled.csv` 或单独维护一个人工标注 CSV,再合并后重新切分。
README.md ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - zh
4
+ pipeline_tag: text-classification
5
+ tags:
6
+ - chinese
7
+ - text-classification
8
+ - onnx
9
+ - intent-classification
10
+ library_name: transformers
11
+ ---
12
+
13
+ # traffic-classify
14
+
15
+ Chinese text classifier for traffic / intent classification into three labels:
16
+
17
+ - `0`: 非研发相关
18
+ - `1`: 研发相关
19
+ - `2`: 中性
20
+
21
+ ## Files
22
+
23
+ - Root directory: Transformers model, tokenizer, and config.
24
+ - `onnx/model_fp32.onnx`: FP32 ONNX export.
25
+ - `onnx/model_int8.onnx`: INT8 quantized ONNX model for CPU inference.
26
+
27
+ ## Evaluation
28
+ On the held-out evaluation set, the classifier achieves an overall accuracy of
29
+ approximately `94%`, with a weighted F1-score of approximately `94%`,
30
+ demonstrating strong classification capability across different traffic types.
31
+
32
+ The per-class F1-scores are:
33
+
34
+ - 研发相关: `0.96`
35
+ - 中性: `0.93`
36
+ - 非研发相关: `0.88`
37
+
38
+ The results indicate that the model performs particularly well in identifying
39
+ 研发-related traffic, while non-研发 traffic remains relatively more
40
+ challenging due to semantic overlap with technical discussions.
41
+
42
+ ## Dataset Policy
43
+
44
+ The dataset uses a compact three-class policy:
45
+
46
+ - 研发相关: full software / IT / electronics / communication terminology sources.
47
+ - 中性: stopwords only.
48
+ - 非研发相关: remaining dictionary categories, compactly sampled.
49
+
50
+ See the project `DATA_SOURCES.md` for source details.
51
+
52
+ ## Usage
53
+
54
+ ```python
55
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
56
+ import torch
57
+
58
+ repo_id = "pawizard/traffic-classify"
59
+ tokenizer = AutoTokenizer.from_pretrained(repo_id)
60
+ model = AutoModelForSequenceClassification.from_pretrained(repo_id)
61
+
62
+ text = "这个 NullPointerException 报错怎么修复"
63
+ inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=128)
64
+
65
+ with torch.no_grad():
66
+ logits = model(**inputs).logits
67
+ pred = int(logits.argmax(dim=-1).item())
68
+
69
+ print(model.config.id2label[pred])
70
+ ```
config.json ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "BertForSequenceClassification"
4
+ ],
5
+ "attention_probs_dropout_prob": 0.1,
6
+ "classifier_dropout": null,
7
+ "directionality": "bidi",
8
+ "dtype": "float32",
9
+ "gradient_checkpointing": false,
10
+ "hidden_act": "gelu",
11
+ "hidden_dropout_prob": 0.1,
12
+ "hidden_size": 768,
13
+ "id2label": {
14
+ "0": "\u975e\u7814\u53d1\u76f8\u5173",
15
+ "1": "\u7814\u53d1\u76f8\u5173",
16
+ "2": "\u4e2d\u6027"
17
+ },
18
+ "initializer_range": 0.02,
19
+ "intermediate_size": 3072,
20
+ "label2id": {
21
+ "\u4e2d\u6027": 2,
22
+ "\u7814\u53d1\u76f8\u5173": 1,
23
+ "\u975e\u7814\u53d1\u76f8\u5173": 0
24
+ },
25
+ "layer_norm_eps": 1e-12,
26
+ "max_position_embeddings": 512,
27
+ "model_type": "bert",
28
+ "num_attention_heads": 12,
29
+ "num_hidden_layers": 12,
30
+ "pad_token_id": 0,
31
+ "pooler_fc_size": 768,
32
+ "pooler_num_attention_heads": 12,
33
+ "pooler_num_fc_layers": 3,
34
+ "pooler_size_per_head": 128,
35
+ "pooler_type": "first_token_transform",
36
+ "position_embedding_type": "absolute",
37
+ "transformers_version": "4.57.6",
38
+ "type_vocab_size": 2,
39
+ "use_cache": true,
40
+ "vocab_size": 21128
41
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1a6069ff6eb49177c3cdb6af9346ae7ff0c758948f43c4cda5e330e44b858992
3
+ size 409103316
onnx/model_fp32.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:61f5f979e68c905893f42ed7c6d193a0aa529e0e6fc682ee2796bcb5037b2d6c
3
+ size 409343847
onnx/model_int8.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:34faa12a375093cd90d0aa26b369f2e655f975df855aa669f34d1fdf38fd19ba
3
+ size 103101880
onnx/special_tokens_map.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": {
3
+ "content": "[CLS]",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "mask_token": {
10
+ "content": "[MASK]",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": {
17
+ "content": "[PAD]",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "sep_token": {
24
+ "content": "[SEP]",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ },
30
+ "unk_token": {
31
+ "content": "[UNK]",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false
36
+ }
37
+ }
onnx/tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
onnx/tokenizer_config.json ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "[PAD]",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "100": {
12
+ "content": "[UNK]",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "101": {
20
+ "content": "[CLS]",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "102": {
28
+ "content": "[SEP]",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "103": {
36
+ "content": "[MASK]",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "clean_up_tokenization_spaces": false,
45
+ "cls_token": "[CLS]",
46
+ "do_lower_case": true,
47
+ "extra_special_tokens": {},
48
+ "mask_token": "[MASK]",
49
+ "max_length": 128,
50
+ "model_max_length": 1000000000000000019884624838656,
51
+ "pad_to_multiple_of": null,
52
+ "pad_token": "[PAD]",
53
+ "pad_token_type_id": 0,
54
+ "padding_side": "right",
55
+ "sep_token": "[SEP]",
56
+ "stride": 0,
57
+ "strip_accents": null,
58
+ "tokenize_chinese_chars": true,
59
+ "tokenizer_class": "BertTokenizer",
60
+ "truncation_side": "right",
61
+ "truncation_strategy": "longest_first",
62
+ "unk_token": "[UNK]"
63
+ }
onnx/vocab.txt ADDED
The diff for this file is too large to render. See raw diff
 
special_tokens_map.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": {
3
+ "content": "[CLS]",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "mask_token": {
10
+ "content": "[MASK]",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": {
17
+ "content": "[PAD]",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "sep_token": {
24
+ "content": "[SEP]",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ },
30
+ "unk_token": {
31
+ "content": "[UNK]",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false
36
+ }
37
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "[PAD]",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "100": {
12
+ "content": "[UNK]",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "101": {
20
+ "content": "[CLS]",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "102": {
28
+ "content": "[SEP]",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "103": {
36
+ "content": "[MASK]",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "clean_up_tokenization_spaces": false,
45
+ "cls_token": "[CLS]",
46
+ "do_lower_case": true,
47
+ "extra_special_tokens": {},
48
+ "mask_token": "[MASK]",
49
+ "model_max_length": 1000000000000000019884624838656,
50
+ "pad_token": "[PAD]",
51
+ "sep_token": "[SEP]",
52
+ "strip_accents": null,
53
+ "tokenize_chinese_chars": true,
54
+ "tokenizer_class": "BertTokenizer",
55
+ "unk_token": "[UNK]"
56
+ }
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:772ab76968477d5a4289da87bbdd0f254aef4a28339fe192732b6f0c3de8a847
3
+ size 5841
vocab.txt ADDED
The diff for this file is too large to render. See raw diff