update
Browse files
examples/preprocess/process_email_spam.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/python3
|
2 |
+
# -*- coding: utf-8 -*-
|
3 |
+
|
4 |
+
|
5 |
+
if __name__ == '__main__':
|
6 |
+
pass
|
examples/preprocess/process_enron_spam.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/python3
|
2 |
+
# -*- coding: utf-8 -*-
|
3 |
+
|
4 |
+
|
5 |
+
if __name__ == '__main__':
|
6 |
+
pass
|
examples/preprocess/process_spam_assassin.py
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/python3
|
2 |
+
# -*- coding: utf-8 -*-
|
3 |
+
import argparse
|
4 |
+
from collections import defaultdict
|
5 |
+
import json
|
6 |
+
import os
|
7 |
+
from pathlib import Path
|
8 |
+
import random
|
9 |
+
import re
|
10 |
+
import sys
|
11 |
+
|
12 |
+
pwd = os.path.abspath(os.path.dirname(__file__))
|
13 |
+
sys.path.append(os.path.join(pwd, '../../'))
|
14 |
+
|
15 |
+
from datasets import load_dataset
|
16 |
+
from tqdm import tqdm
|
17 |
+
|
18 |
+
from project_settings import project_path
|
19 |
+
|
20 |
+
|
21 |
+
def get_args():
|
22 |
+
parser = argparse.ArgumentParser()
|
23 |
+
|
24 |
+
parser.add_argument("--dataset_path", default="talby/spamassassin", type=str)
|
25 |
+
parser.add_argument(
|
26 |
+
"--dataset_cache_dir",
|
27 |
+
default=(project_path / "hub_datasets").as_posix(),
|
28 |
+
type=str
|
29 |
+
)
|
30 |
+
parser.add_argument(
|
31 |
+
"--output_file",
|
32 |
+
default=(project_path / "data/spam_assassin.jsonl"),
|
33 |
+
type=str
|
34 |
+
)
|
35 |
+
args = parser.parse_args()
|
36 |
+
return args
|
37 |
+
|
38 |
+
|
39 |
+
def main():
|
40 |
+
args = get_args()
|
41 |
+
|
42 |
+
dataset_dict = load_dataset(
|
43 |
+
path=args.dataset_path,
|
44 |
+
cache_dir=args.dataset_cache_dir,
|
45 |
+
)
|
46 |
+
print(dataset_dict)
|
47 |
+
|
48 |
+
with open(args.output_file, "w", encoding="utf-8") as f:
|
49 |
+
for split, dataset in dataset_dict.items():
|
50 |
+
for sample in tqdm(dataset):
|
51 |
+
# print(sample)
|
52 |
+
# text = sample["text"]
|
53 |
+
subject = sample["subject"]
|
54 |
+
message = sample["message"]
|
55 |
+
label = sample["label_text"]
|
56 |
+
|
57 |
+
text = "{}\n\n{}".format(subject, message)
|
58 |
+
|
59 |
+
row = {
|
60 |
+
"text": text,
|
61 |
+
"label": label,
|
62 |
+
"data_source": "enron_spam",
|
63 |
+
"split": split
|
64 |
+
}
|
65 |
+
row = json.dumps(row, ensure_ascii=False)
|
66 |
+
f.write("{}\n".format(row))
|
67 |
+
|
68 |
+
return
|
69 |
+
|
70 |
+
|
71 |
+
if __name__ == '__main__':
|
72 |
+
main()
|
examples/preprocess/process_spam_detection.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/python3
|
2 |
+
# -*- coding: utf-8 -*-
|
3 |
+
|
4 |
+
|
5 |
+
if __name__ == '__main__':
|
6 |
+
pass
|
examples/preprocess/samples_count.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/python3
|
2 |
+
# -*- coding: utf-8 -*-
|
3 |
+
|
4 |
+
|
5 |
+
if __name__ == '__main__':
|
6 |
+
pass
|