soodoku commited on
Commit
f7a5013
·
verified ·
1 Parent(s): cd46f96

mmBERT-small fine-tune, 39 Shallalist classes, T=3.416

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ language:
4
+ - multilingual
5
+ base_model: jhu-clsp/mmBERT-small
6
+ pipeline_tag: text-classification
7
+ tags:
8
+ - website-classification
9
+ - content-moderation
10
+ library_name: transformers
11
+ ---
12
+
13
+ # piedomains-text
14
+
15
+ Classifies a website into one of 39 content categories from its page text. This is
16
+ the text model behind [`piedomains`](https://github.com/themains/piedomains).
17
+
18
+ ```bash
19
+ pip install piedomains
20
+ ```
21
+
22
+ ```python
23
+ from piedomains import DomainClassifier
24
+ run = DomainClassifier().classify(["cnn.com", "amazon.com"])
25
+ ```
26
+
27
+ ## What it is
28
+
29
+ A [mmBERT-small](https://huggingface.co/jhu-clsp/mmBERT-small) fine-tune —
30
+ multilingual on purpose, since the taxonomy is applied to the whole web rather than
31
+ the English part of it.
32
+
33
+ Input is `"<domain-stem> <page text>"`; the domain is part of the input the model was
34
+ trained on, not decoration.
35
+
36
+ ## Results
37
+
38
+ Measured two ways, because they answer different questions.
39
+
40
+ **Held-out split of the training corpus** (3,466 documents, same distribution):
41
+
42
+ | accuracy | macro-F1 |
43
+ |---|---|
44
+ | 0.734 | 0.648 |
45
+
46
+ **A separate hand-labelled set of 44 popular domains** — different distribution,
47
+ different scrape, and the number that reflects real use. Against the TensorFlow model
48
+ it replaces, on identical cached content:
49
+
50
+ | | previous | this model |
51
+ |---|---|---|
52
+ | accuracy | 0.395 | **0.590** |
53
+ | macro-F1 | 0.262 | **0.607** |
54
+ | ECE | 0.210 | **0.190** |
55
+
56
+ The previous model reported 71.3% at training time and delivered 0.395 on this set;
57
+ the gap is what happens when a number is never checked against out-of-distribution
58
+ data. Treat 0.59 as the honest expectation and 0.73 as the ceiling.
59
+
60
+ ## Confidence is calibrated
61
+
62
+ `softmax(logits / T)` with **T = 3.416**, fitted on the validation split. This takes
63
+ expected calibration error from 0.203 to **0.022** — the raw model is badly
64
+ overconfident, so untemperated softmax outputs should not be read as probabilities.
65
+
66
+ ## Limits
67
+
68
+ - **Homepages.** Trained on homepage text; a deep page is out of distribution.
69
+ - **The taxonomy is from 2022.** Shallalist was discontinued, so categories like
70
+ `webradio` and `redirector` reflect an older web. `recreation` in particular is a
71
+ grab-bag — humor, martial arts, restaurants, sports, travel and wellness collapsed
72
+ into one label.
73
+ - **One label per site.** ~2% of domains legitimately belong to more than one
74
+ category; those were dropped from training rather than modelled.
75
+ - **Known confusions**, from the evaluation above: news outlets with video → `radiotv`,
76
+ and large commercial sites → `adv` or `spyware`, both of which are big, noisy
77
+ Shallalist categories.
78
+ - Not a content-safety system. The `porn` class exists but has not been tuned for the
79
+ asymmetric cost that use would require.
80
+
81
+ ## Training
82
+
83
+ Corpus is [Shallalist Web Page Data](https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/ZXTQ7V)
84
+ (Harvard Dataverse), labelled against a surviving Shallalist mirror; 34,627 documents
85
+ over 39 classes, capped per class to balance a long tail. 4 epochs, lr 3e-5, weight
86
+ decay 0.01, max length 128. Scripts are in
87
+ [`training/`](https://github.com/themains/piedomains/tree/main/training).
88
+
89
+ ## Citation
90
+
91
+ ```bibtex
92
+ @software{piedomains,
93
+ author = {Chintalapati, Rajashekar and Sood, Gaurav},
94
+ title = {piedomains: Predict the Content Category of a Domain},
95
+ url = {https://github.com/themains/piedomains}
96
+ }
97
+ ```
calibration.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "method": "temperature_scaling",
3
+ "temperature": 3.4161198139190674,
4
+ "ece_before": 0.20305442868098322,
5
+ "ece_after": 0.021952365283772132,
6
+ "fitted_on": "val"
7
+ }
config.json ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "ModernBertForSequenceClassification"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "bos_token_id": 2,
8
+ "classifier_activation": "gelu",
9
+ "classifier_bias": false,
10
+ "classifier_dropout": 0.0,
11
+ "classifier_pooling": "mean",
12
+ "cls_token_id": 1,
13
+ "decoder_bias": true,
14
+ "deterministic_flash_attn": false,
15
+ "dtype": "float32",
16
+ "embedding_dropout": 0.0,
17
+ "eos_token_id": 1,
18
+ "global_attn_every_n_layers": 3,
19
+ "gradient_checkpointing": false,
20
+ "hidden_activation": "gelu",
21
+ "hidden_size": 384,
22
+ "id2label": {
23
+ "0": "adv",
24
+ "1": "alcohol",
25
+ "2": "automobile",
26
+ "3": "dating",
27
+ "4": "downloads",
28
+ "5": "drugs",
29
+ "6": "education",
30
+ "7": "finance",
31
+ "8": "fortunetelling",
32
+ "9": "forum",
33
+ "10": "gamble",
34
+ "11": "government",
35
+ "12": "hobby",
36
+ "13": "hospitals",
37
+ "14": "imagehosting",
38
+ "15": "isp",
39
+ "16": "jobsearch",
40
+ "17": "models",
41
+ "18": "movies",
42
+ "19": "music",
43
+ "20": "news",
44
+ "21": "politics",
45
+ "22": "porn",
46
+ "23": "radiotv",
47
+ "24": "recreation",
48
+ "25": "redirector",
49
+ "26": "religion",
50
+ "27": "science",
51
+ "28": "searchengines",
52
+ "29": "sex",
53
+ "30": "shopping",
54
+ "31": "socialnet",
55
+ "32": "spyware",
56
+ "33": "tracker",
57
+ "34": "urlshortener",
58
+ "35": "warez",
59
+ "36": "weapons",
60
+ "37": "webmail",
61
+ "38": "webradio"
62
+ },
63
+ "initializer_cutoff_factor": 2.0,
64
+ "initializer_range": 0.02,
65
+ "intermediate_size": 1152,
66
+ "label2id": {
67
+ "adv": 0,
68
+ "alcohol": 1,
69
+ "automobile": 2,
70
+ "dating": 3,
71
+ "downloads": 4,
72
+ "drugs": 5,
73
+ "education": 6,
74
+ "finance": 7,
75
+ "fortunetelling": 8,
76
+ "forum": 9,
77
+ "gamble": 10,
78
+ "government": 11,
79
+ "hobby": 12,
80
+ "hospitals": 13,
81
+ "imagehosting": 14,
82
+ "isp": 15,
83
+ "jobsearch": 16,
84
+ "models": 17,
85
+ "movies": 18,
86
+ "music": 19,
87
+ "news": 20,
88
+ "politics": 21,
89
+ "porn": 22,
90
+ "radiotv": 23,
91
+ "recreation": 24,
92
+ "redirector": 25,
93
+ "religion": 26,
94
+ "science": 27,
95
+ "searchengines": 28,
96
+ "sex": 29,
97
+ "shopping": 30,
98
+ "socialnet": 31,
99
+ "spyware": 32,
100
+ "tracker": 33,
101
+ "urlshortener": 34,
102
+ "warez": 35,
103
+ "weapons": 36,
104
+ "webmail": 37,
105
+ "webradio": 38
106
+ },
107
+ "layer_norm_eps": 1e-05,
108
+ "layer_types": [
109
+ "full_attention",
110
+ "sliding_attention",
111
+ "sliding_attention",
112
+ "full_attention",
113
+ "sliding_attention",
114
+ "sliding_attention",
115
+ "full_attention",
116
+ "sliding_attention",
117
+ "sliding_attention",
118
+ "full_attention",
119
+ "sliding_attention",
120
+ "sliding_attention",
121
+ "full_attention",
122
+ "sliding_attention",
123
+ "sliding_attention",
124
+ "full_attention",
125
+ "sliding_attention",
126
+ "sliding_attention",
127
+ "full_attention",
128
+ "sliding_attention",
129
+ "sliding_attention",
130
+ "full_attention"
131
+ ],
132
+ "local_attention": 128,
133
+ "mask_token_id": 4,
134
+ "max_position_embeddings": 8192,
135
+ "mlp_bias": false,
136
+ "mlp_dropout": 0.0,
137
+ "model_type": "modernbert",
138
+ "norm_bias": false,
139
+ "norm_eps": 1e-05,
140
+ "num_attention_heads": 6,
141
+ "num_hidden_layers": 22,
142
+ "pad_token_id": 0,
143
+ "position_embedding_type": "sans_pos",
144
+ "problem_type": "single_label_classification",
145
+ "rope_parameters": {
146
+ "full_attention": {
147
+ "rope_theta": 160000,
148
+ "rope_type": "default"
149
+ },
150
+ "sliding_attention": {
151
+ "rope_theta": 160000,
152
+ "rope_type": "default"
153
+ }
154
+ },
155
+ "sep_token_id": 1,
156
+ "sparse_pred_ignore_index": -100,
157
+ "sparse_prediction": false,
158
+ "tie_word_embeddings": true,
159
+ "transformers_version": "5.14.1",
160
+ "vocab_size": 256000
161
+ }
config.json.piedomains ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_name": "jhu-clsp/mmBERT-small",
3
+ "max_length": 128,
4
+ "batch_size": 16,
5
+ "grad_accum": 1,
6
+ "epochs": 4,
7
+ "lr": 3e-05,
8
+ "weight_decay": 0.01,
9
+ "warmup_ratio": 0.06,
10
+ "seed": 42,
11
+ "patience": 2
12
+ }
labels.json ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ "adv",
3
+ "alcohol",
4
+ "automobile",
5
+ "dating",
6
+ "downloads",
7
+ "drugs",
8
+ "education",
9
+ "finance",
10
+ "fortunetelling",
11
+ "forum",
12
+ "gamble",
13
+ "government",
14
+ "hobby",
15
+ "hospitals",
16
+ "imagehosting",
17
+ "isp",
18
+ "jobsearch",
19
+ "models",
20
+ "movies",
21
+ "music",
22
+ "news",
23
+ "politics",
24
+ "porn",
25
+ "radiotv",
26
+ "recreation",
27
+ "redirector",
28
+ "religion",
29
+ "science",
30
+ "searchengines",
31
+ "sex",
32
+ "shopping",
33
+ "socialnet",
34
+ "spyware",
35
+ "tracker",
36
+ "urlshortener",
37
+ "warez",
38
+ "weapons",
39
+ "webmail",
40
+ "webradio"
41
+ ]
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a8755850f0a5355f660317b5314d8a26ce5eeb04e042cb0ba825e16cfe449988
3
+ size 562640380
test_metrics.json ADDED
@@ -0,0 +1,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "accuracy": 0.7336987882285054,
3
+ "macro_f1": 0.6480034352843916,
4
+ "per_class": {
5
+ "adv": {
6
+ "precision": 0.6521739130434783,
7
+ "recall": 0.4838709677419355,
8
+ "f1": 0.5555555555555556,
9
+ "support": 62
10
+ },
11
+ "alcohol": {
12
+ "precision": 0.8780487804878049,
13
+ "recall": 0.9230769230769231,
14
+ "f1": 0.9,
15
+ "support": 39
16
+ },
17
+ "automobile": {
18
+ "precision": 0.8633879781420765,
19
+ "recall": 0.8229166666666666,
20
+ "f1": 0.8426666666666666,
21
+ "support": 192
22
+ },
23
+ "dating": {
24
+ "precision": 0.7288135593220338,
25
+ "recall": 0.7166666666666667,
26
+ "f1": 0.7226890756302521,
27
+ "support": 60
28
+ },
29
+ "downloads": {
30
+ "precision": 0.41333333333333333,
31
+ "recall": 0.5,
32
+ "f1": 0.45255474452554745,
33
+ "support": 62
34
+ },
35
+ "drugs": {
36
+ "precision": 0.2641509433962264,
37
+ "recall": 0.2692307692307692,
38
+ "f1": 0.26666666666666666,
39
+ "support": 52
40
+ },
41
+ "education": {
42
+ "precision": 0.949438202247191,
43
+ "recall": 0.9037433155080213,
44
+ "f1": 0.9260273972602739,
45
+ "support": 187
46
+ },
47
+ "finance": {
48
+ "precision": 0.8793103448275862,
49
+ "recall": 0.8693181818181818,
50
+ "f1": 0.8742857142857142,
51
+ "support": 176
52
+ },
53
+ "fortunetelling": {
54
+ "precision": 0.8666666666666667,
55
+ "recall": 0.8387096774193549,
56
+ "f1": 0.8524590163934426,
57
+ "support": 62
58
+ },
59
+ "forum": {
60
+ "precision": 0.8187919463087249,
61
+ "recall": 0.8840579710144928,
62
+ "f1": 0.8501742160278746,
63
+ "support": 138
64
+ },
65
+ "gamble": {
66
+ "precision": 0.8843537414965986,
67
+ "recall": 0.9090909090909091,
68
+ "f1": 0.8965517241379309,
69
+ "support": 143
70
+ },
71
+ "government": {
72
+ "precision": 0.6571428571428571,
73
+ "recall": 0.6571428571428571,
74
+ "f1": 0.6571428571428571,
75
+ "support": 35
76
+ },
77
+ "hobby": {
78
+ "precision": 0.75,
79
+ "recall": 0.7164179104477612,
80
+ "f1": 0.7328244274809161,
81
+ "support": 134
82
+ },
83
+ "hospitals": {
84
+ "precision": 0.911504424778761,
85
+ "recall": 0.9537037037037037,
86
+ "f1": 0.9321266968325793,
87
+ "support": 108
88
+ },
89
+ "imagehosting": {
90
+ "precision": 0.36363636363636365,
91
+ "recall": 0.25,
92
+ "f1": 0.2962962962962963,
93
+ "support": 16
94
+ },
95
+ "isp": {
96
+ "precision": 0.42424242424242425,
97
+ "recall": 0.4666666666666667,
98
+ "f1": 0.4444444444444445,
99
+ "support": 30
100
+ },
101
+ "jobsearch": {
102
+ "precision": 0.864516129032258,
103
+ "recall": 0.8701298701298701,
104
+ "f1": 0.8673139158576051,
105
+ "support": 154
106
+ },
107
+ "models": {
108
+ "precision": 0.425,
109
+ "recall": 0.4722222222222222,
110
+ "f1": 0.4473684210526316,
111
+ "support": 36
112
+ },
113
+ "movies": {
114
+ "precision": 0.7941176470588235,
115
+ "recall": 0.7883211678832117,
116
+ "f1": 0.7912087912087912,
117
+ "support": 137
118
+ },
119
+ "music": {
120
+ "precision": 0.9144736842105263,
121
+ "recall": 0.9205298013245033,
122
+ "f1": 0.9174917491749175,
123
+ "support": 151
124
+ },
125
+ "news": {
126
+ "precision": 0.44936708860759494,
127
+ "recall": 0.46405228758169936,
128
+ "f1": 0.4565916398713826,
129
+ "support": 153
130
+ },
131
+ "politics": {
132
+ "precision": 0.8170731707317073,
133
+ "recall": 0.788235294117647,
134
+ "f1": 0.8023952095808382,
135
+ "support": 85
136
+ },
137
+ "porn": {
138
+ "precision": 0.7647058823529411,
139
+ "recall": 0.7358490566037735,
140
+ "f1": 0.7499999999999999,
141
+ "support": 106
142
+ },
143
+ "radiotv": {
144
+ "precision": 0.7341040462427746,
145
+ "recall": 0.7470588235294118,
146
+ "f1": 0.740524781341108,
147
+ "support": 170
148
+ },
149
+ "recreation": {
150
+ "precision": 0.7231638418079096,
151
+ "recall": 0.8,
152
+ "f1": 0.7596439169139466,
153
+ "support": 160
154
+ },
155
+ "redirector": {
156
+ "precision": 0.5873015873015873,
157
+ "recall": 0.4457831325301205,
158
+ "f1": 0.5068493150684932,
159
+ "support": 83
160
+ },
161
+ "religion": {
162
+ "precision": 0.9438202247191011,
163
+ "recall": 0.96,
164
+ "f1": 0.951841359773371,
165
+ "support": 175
166
+ },
167
+ "science": {
168
+ "precision": 0.9821428571428571,
169
+ "recall": 0.9322033898305084,
170
+ "f1": 0.9565217391304348,
171
+ "support": 59
172
+ },
173
+ "searchengines": {
174
+ "precision": 0.44,
175
+ "recall": 0.44,
176
+ "f1": 0.44,
177
+ "support": 25
178
+ },
179
+ "sex": {
180
+ "precision": 0.8,
181
+ "recall": 0.631578947368421,
182
+ "f1": 0.7058823529411765,
183
+ "support": 38
184
+ },
185
+ "shopping": {
186
+ "precision": 0.4627659574468085,
187
+ "recall": 0.5576923076923077,
188
+ "f1": 0.5058139534883721,
189
+ "support": 156
190
+ },
191
+ "socialnet": {
192
+ "precision": 0.1724137931034483,
193
+ "recall": 0.20833333333333334,
194
+ "f1": 0.18867924528301888,
195
+ "support": 24
196
+ },
197
+ "spyware": {
198
+ "precision": 0.18571428571428572,
199
+ "recall": 0.1780821917808219,
200
+ "f1": 0.18181818181818182,
201
+ "support": 73
202
+ },
203
+ "tracker": {
204
+ "precision": 0.6111111111111112,
205
+ "recall": 0.4782608695652174,
206
+ "f1": 0.5365853658536586,
207
+ "support": 23
208
+ },
209
+ "urlshortener": {
210
+ "precision": 0.5,
211
+ "recall": 0.4,
212
+ "f1": 0.4444444444444445,
213
+ "support": 15
214
+ },
215
+ "warez": {
216
+ "precision": 0.23529411764705882,
217
+ "recall": 0.19047619047619047,
218
+ "f1": 0.21052631578947367,
219
+ "support": 21
220
+ },
221
+ "weapons": {
222
+ "precision": 0.75,
223
+ "recall": 0.782608695652174,
224
+ "f1": 0.7659574468085107,
225
+ "support": 23
226
+ },
227
+ "webmail": {
228
+ "precision": 0.6,
229
+ "recall": 0.5217391304347826,
230
+ "f1": 0.5581395348837209,
231
+ "support": 46
232
+ },
233
+ "webradio": {
234
+ "precision": 0.5892857142857143,
235
+ "recall": 0.5789473684210527,
236
+ "f1": 0.584070796460177,
237
+ "support": 57
238
+ }
239
+ }
240
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:aa6396b645325378a159ce20800b8fdf4d3724306a7d601d47de108272e5761c
3
+ size 34363453
tokenizer_config.json ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "backend": "tokenizers",
3
+ "bos_token": "<bos>",
4
+ "clean_up_tokenization_spaces": false,
5
+ "cls_token": "<bos>",
6
+ "eos_token": "<eos>",
7
+ "extra_special_tokens": [
8
+ "<start_of_turn>",
9
+ "<end_of_turn>"
10
+ ],
11
+ "is_local": false,
12
+ "local_files_only": false,
13
+ "mask_token": "<mask>",
14
+ "model_input_names": [
15
+ "input_ids",
16
+ "attention_mask"
17
+ ],
18
+ "model_max_length": 8192,
19
+ "pad_token": "<pad>",
20
+ "padding_side": "right",
21
+ "sep_token": "<eos>",
22
+ "spaces_between_special_tokens": false,
23
+ "tokenizer_class": "TokenizersBackend",
24
+ "unk_token": "<unk>"
25
+ }