update
Browse files- .gitignore +2 -0
- README.md +103 -2
- data/spam_message.jsonl +3 -0
- examples/preprocess/process_spam_message.py +77 -0
- examples/preprocess/samples_count.py +2 -1
- main.py +5 -2
- spam_detect.py +1 -0
.gitignore
CHANGED
@@ -5,3 +5,5 @@
|
|
5 |
hub_datasets/
|
6 |
|
7 |
**/__pycache__/
|
|
|
|
|
|
5 |
hub_datasets/
|
6 |
|
7 |
**/__pycache__/
|
8 |
+
|
9 |
+
examples/preprocess/data
|
README.md
CHANGED
@@ -11,15 +11,96 @@ license: apache-2.0
|
|
11 |
数据集从网上收集整理如下:
|
12 |
| 数据 | 语言 | 任务类型 | 原始数据/项目地址 | 样本个数 | 原始数据描述 | 替代数据下载地址 |
|
13 |
| :--- | :---: | :---: | :---: | :---: | :---: | :---: |
|
|
|
|
|
14 |
| sms_spam | 英语 | 垃圾短信分类 | [SMS Spam Collection](https://archive.ics.uci.edu/dataset/228/sms+spam+collection); [SMS Spam Collection Dataset](https://www.kaggle.com/datasets/uciml/sms-spam-collection-dataset) | ham: 4827; spam: 747 | SMS 垃圾邮件集合是一组公开的 SMS 标记消息,为移动电话垃圾邮件研究而收集。 | [sms_spam](https://huggingface.co/datasets/sms_spam) |
|
15 |
| spam_assassin | 英语 | 垃圾邮件分类 | [datasets-spam-assassin](https://github.com/stdlib-js/datasets-spam-assassin); [Apache SpamAssassin’s public datasets](https://spamassassin.apache.org/old/publiccorpus/); [Spam or Not Spam Dataset](https://www.kaggle.com/datasets/ozlerhakan/spam-or-not-spam-dataset) | ham: 3795; spam: 6954 | 这是一组邮件消息,适合用于测试垃圾邮件过滤系统。备注:text 很乱,不推荐使用。 | [talby/SpamAssassin](https://huggingface.co/datasets/talby/spamassassin) |
|
16 |
-
| enron_spam | 英语 | 垃圾邮件分类 | [enron_spam_data](https://github.com/MWiechmann/enron_spam_data); [Enron-Spam](https://www2.aueb.gr/users/ion/data/enron-spam/); [spam-mails-dataset](https://www.kaggle.com/datasets/venky73/spam-mails-dataset) | ham: 16545; spam: 17171 | Enron-Spam 数据集是 V. Metsis、I. Androutsopoulos 和 G. Paliouras 收集的绝佳资源 | [SetFit/enron_spam](https://huggingface.co/datasets/SetFit/enron_spam) |
|
17 |
| spam_detection | 英语 | 垃圾短信分类 | [Deysi/spam-detection-dataset](https://huggingface.co/datasets/Deysi/spam-detection-dataset) | ham: 5400; spam: 5500 | | |
|
18 |
-
|
|
19 |
|
20 |
|
21 |
### 样本示例
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
<details>
|
24 |
<summary>sms_spam 样本示例</summary>
|
25 |
<pre><code>------------
|
@@ -63,6 +144,26 @@ spam
|
|
63 |
</details>
|
64 |
|
65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
### 参考来源
|
67 |
|
68 |
<details>
|
|
|
11 |
数据集从网上收集整理如下:
|
12 |
| 数据 | 语言 | 任务类型 | 原始数据/项目地址 | 样本个数 | 原始数据描述 | 替代数据下载地址 |
|
13 |
| :--- | :---: | :---: | :---: | :---: | :---: | :---: |
|
14 |
+
| email_spam | 英语 | 垃圾短信分类 | [NotShrirang/email-spam-filter](https://huggingface.co/datasets/NotShrirang/email-spam-filter) | ham: 3672; spam: 1499 | | |
|
15 |
+
| enron_spam | 英语 | 垃圾邮件分类 | [enron_spam_data](https://github.com/MWiechmann/enron_spam_data); [Enron-Spam](https://www2.aueb.gr/users/ion/data/enron-spam/); [spam-mails-dataset](https://www.kaggle.com/datasets/venky73/spam-mails-dataset) | ham: 16545; spam: 17171 | Enron-Spam 数据集是 V. Metsis、I. Androutsopoulos 和 G. Paliouras 收集的绝佳资源 | [SetFit/enron_spam](https://huggingface.co/datasets/SetFit/enron_spam) |
|
16 |
| sms_spam | 英语 | 垃圾短信分类 | [SMS Spam Collection](https://archive.ics.uci.edu/dataset/228/sms+spam+collection); [SMS Spam Collection Dataset](https://www.kaggle.com/datasets/uciml/sms-spam-collection-dataset) | ham: 4827; spam: 747 | SMS 垃圾邮件集合是一组公开的 SMS 标记消息,为移动电话垃圾邮件研究而收集。 | [sms_spam](https://huggingface.co/datasets/sms_spam) |
|
17 |
| spam_assassin | 英语 | 垃圾邮件分类 | [datasets-spam-assassin](https://github.com/stdlib-js/datasets-spam-assassin); [Apache SpamAssassin’s public datasets](https://spamassassin.apache.org/old/publiccorpus/); [Spam or Not Spam Dataset](https://www.kaggle.com/datasets/ozlerhakan/spam-or-not-spam-dataset) | ham: 3795; spam: 6954 | 这是一组邮件消息,适合用于测试垃圾邮件过滤系统。备注:text 很乱,不推荐使用。 | [talby/SpamAssassin](https://huggingface.co/datasets/talby/spamassassin) |
|
|
|
18 |
| spam_detection | 英语 | 垃圾短信分类 | [Deysi/spam-detection-dataset](https://huggingface.co/datasets/Deysi/spam-detection-dataset) | ham: 5400; spam: 5500 | | |
|
19 |
+
| spam_message | 汉语 | 垃圾短信分类 | [SpamMessage](https://github.com/hrwhisper/SpamMessage) | ham: 720000; spam: 80000 | 其中spam的数据是正确的数据,但是做了脱敏处理(招生电话:xxxxxxxxxxx),这里的 x 可能会成为显著特征。而ham样本像是从普通文本中截断出来充作样本的,建议不要用这些数据。 | |
|
20 |
|
21 |
|
22 |
### 样本示例
|
23 |
|
24 |
+
|
25 |
+
<details>
|
26 |
+
<summary>email_spam 样本示例</summary>
|
27 |
+
<pre><code>
|
28 |
+
------------
|
29 |
+
Subject: photoshop , windows , office . cheap . main trending
|
30 |
+
abasements darer prudently fortuitous undergone
|
31 |
+
lighthearted charm orinoco taster
|
32 |
+
railroad affluent pornographic cuvier
|
33 |
+
irvin parkhouse blameworthy chlorophyll
|
34 |
+
robed diagrammatic fogarty clears bayda
|
35 |
+
inconveniencing managing represented smartness hashish
|
36 |
+
academies shareholders unload badness
|
37 |
+
danielson pure caffein
|
38 |
+
spaniard chargeable levin
|
39 |
+
<br>
|
40 |
+
spam
|
41 |
+
------------
|
42 |
+
Subject: re : indian springs
|
43 |
+
this deal is to book the teco pvr revenue . it is my understanding that teco
|
44 |
+
just sends us a check , i haven ' t received an answer as to whether there is a
|
45 |
+
predermined price associated with this deal or if teco just lets us know what
|
46 |
+
we are giving . i can continue to chase this deal down if you need .
|
47 |
+
ham
|
48 |
+
------------
|
49 |
+
Subject: report 01405 !
|
50 |
+
wffur attion brom est inst siupied 1 pgst our riwe asently rest .
|
51 |
+
tont to presyou tew cons of benco 4 . yee : fater 45 y . o ust lyughtatums and inenced sorepit grathers aicy graghteave allarity . oarity wow to yur coons , as were then 60 ve mers of oite .
|
52 |
+
ithat yoit ? ! berst thar ! enth excives 2004 . . .
|
53 |
+
<br>
|
54 |
+
spam
|
55 |
+
------------
|
56 |
+
Subject: nominations for oct . 21 - 23 , 2000
|
57 |
+
( see attached file : hplnl 021 . xls )
|
58 |
+
- hplnl 021 . xls
|
59 |
+
ham
|
60 |
+
------------
|
61 |
+
</code></pre>
|
62 |
+
</details>
|
63 |
+
|
64 |
+
|
65 |
+
<details>
|
66 |
+
<summary>enron_spam 样本示例</summary>
|
67 |
+
<pre><code>
|
68 |
+
------------
|
69 |
+
wanted to try ci 4 lis but thought it was way too expensive for you ?
|
70 |
+
<br>
|
71 |
+
viagra at $ 1 . 12 per dose
|
72 |
+
ready to boost your sex life ? positive ?
|
73 |
+
time to do it right now . order viagra at incredibly low prices
|
74 |
+
$ 1 . 12 per dose . unbelivable
|
75 |
+
remove
|
76 |
+
<br>
|
77 |
+
spam
|
78 |
+
------------
|
79 |
+
enron / hpl actuals for december 11 , 2000
|
80 |
+
<br>
|
81 |
+
teco tap 30 . 000 / enron ; 120 . 000 / hpl gas daily
|
82 |
+
ls hpl lsk ic 30 . 000 / enron
|
83 |
+
ham
|
84 |
+
------------
|
85 |
+
looking for cheap high - quality software ? rotated napoleonizes
|
86 |
+
<br>
|
87 |
+
water past also , burn , course . gave country , mass lot . act north
|
88 |
+
good . from , learn form most brother vary . when more for . up
|
89 |
+
stick , century put , song be . test , describe , plain , against wood
|
90 |
+
star . began dress ever group . here oh , most world stay .
|
91 |
+
<br>
|
92 |
+
spam
|
93 |
+
------------
|
94 |
+
ideabank website
|
95 |
+
<br>
|
96 |
+
please read the attached document for information about an exciting new
|
97 |
+
website for ets employees !
|
98 |
+
ham
|
99 |
+
------------
|
100 |
+
</code></pre>
|
101 |
+
</details>
|
102 |
+
|
103 |
+
|
104 |
<details>
|
105 |
<summary>sms_spam 样本示例</summary>
|
106 |
<pre><code>------------
|
|
|
144 |
</details>
|
145 |
|
146 |
|
147 |
+
<details>
|
148 |
+
<summary>spam_assassin 样本示例</summary>
|
149 |
+
<pre><code>
|
150 |
+
------------
|
151 |
+
"\n>>>Robert Elz said:\n > Date: Wed, 28 Aug 2002 09:22:34 -0500\n > From: Chris Garrigues <[email protected]\nm>\n > Message-ID: <[email protected]>\n > \n > \n > | so I'll probably poke around at the sequences performance issues,\n > \n > Well, there's this wonderful piece of code in MhSeqExpand ...\n > \n > # Hack to weed out sequence numbers for messages that don't exist\n > foreach m $rseq {\n > if ![file exists $mhProfile(path)/$folder/$m] {\n > Exmh_Debug $mhProfile(path)/$folder/$m not found\n > set ix [lsearch $seq $m]\n > set seq [lreplace $seq $ix $ix]\n > } else {\n > # Real hack\n\nAt least I'm up-front about my hacks :-)\n\n > break\n > }\n > }\n > \n > which is going to run slow if a sequence happens to start with a bunch\n > of messages that don't exist. I'm not sure why it is important that the\n > first message in the sequence returned exists, but not necessarily any\n > of the others, but I'm sure glad it is, as MhSeqExpand gets called lots,\n > and I don't know if I could cope if it were checking every file in the\n > sequences it is looking at, all the time...\n\nThat was my thinking. My recollection about the first message being valid\nis that the ftoc code wants to find that message to start its highlighting,\nfor example, or you are selecting a message to display.\n\n > It may help to keep a list of the valid message numbers for the current\n > folder (though that would then need to be verified against changes to the\n > directory). Does tcl have a directory read function? I assume so...\n\nglob -nocomplain $mhProfile(path)/$folder *\nwill return an unsorted list of the directory's contents.\nBut the thought of keeping an in memory list of valid messages is not fun.\nExmh already maintains in-core lists of messages in sequences, which is\nalready pretty tricky\n\n > Mh_Sequence also goes and rereads the files (.mh_sequences and the\n > context file) but I'm not sure how frequently that one is called.\n\nIn some places I maintain caches of files by checking their modify time,\nbut the sequence files are soo small that by the time you stat them to\ncheck their date stamp, you could just read them again. Also, now that\nwe checkpoint message state on every message view, that file will change\nevery time. In the old days exmh used to cache a bunch of state about\nthe folder.\n\n--\nBrent Welch\nSoftware Architect, Panasas Inc\nPioneering the World's Most Scalable and Agile Storage Network\nwww.panasas.com\[email protected]\n\n\n\n\n_______________________________________________\nExmh-workers mailing list\[email protected]\nhttps://listman.redhat.com/mailman/listinfo/exmh-workers\n\n"
|
152 |
+
spam
|
153 |
+
------------
|
154 |
+
"Whiter teeth and a brighter smile are just a click away! \nhttp://www.newnamedns.com/dental/\n\nHave you considered professional teeth whitening? If so, you know it usually costs between $300 and $500 from your local dentist!\n\nVisit our site to learn how to professionally whiten your teeth, using the exact same whitening system your dentist uses, at a fraction of the cost!\n\nWe know our product is the best on the market, and we back it with a 30 day money back guarantee!\n\nClick here to find out more!\nhttp://www.newnamedns.com/dental/\n \n \n \n \n \n---------------------------------------\nTo easily remove your address from the list, go to: \nhttp://www.newnamedns.com/stopthemailplease/\nPlease allow 48-72 hours for removal.\n\n"
|
155 |
+
ham
|
156 |
+
------------
|
157 |
+
"> Hi,\n> \n> On Sun, 01 Sep 2002 00:05:03 MDT Reg Clemens wrote: \n> \n> [...]\n> > in messages with GnuPG signatures. But punching the line ALWAYS\n> > gives\n> > \n> > Signature made Thu Aug 29 00:27:17 2002 MDT using DSA key ID BDDF997A\n> > Can't check signature: public key not found\n> > \n> > So, something else is missing.\n> \n> Yes, the public key of the signature you want to check :-).\n> \n> Are you really sure that you have the public key of the message's\n> signature? If not, try downloading it or try to check a signature from\n> which you know you have the public key.\n> \n> \n> \n\nAh, sorry for not making that clearer.\nBut no.\nPreviously (v1.0.6 of GnuPG) there would be a slight pause at this point while\nit went out to get the public key from a keyserver.\nNow, whether I have the key or NOT, I get the failure message.\n\nIts as if it cant find gpg to execute it (but I fixed that path), so there\nmust be something else that I am missing...\n\n\n-- \n Reg.Clemens\n [email protected]\n\n\n\n\n_______________________________________________\nExmh-users mailing list\[email protected]\nhttps://listman.redhat.com/mailman/listinfo/exmh-users\n\n"
|
158 |
+
spam
|
159 |
+
------------
|
160 |
+
"Below is the result of your feedback form. It was submitted by\n ([email protected]) on Tuesday, August 27, 2002 at 22:26:56\n---------------------------------------------------------------------------\n\n:: <A HREF=\"http://www.pornhere.net\">click here</A>Don't want to pay for Porn? Would you like to get it for FREE? The Honest, No Risk 100% Free Way? If you take a couple of minutes and read through our simple guide you will be able to get Free Passes to the top Paysites online!<A HREF=\"http://www.pornhere.net\">click here</A>\n\n---------------------------------------------------------------------------\n\n\n"
|
161 |
+
ham
|
162 |
+
------------
|
163 |
+
</code></pre>
|
164 |
+
</details>
|
165 |
+
|
166 |
+
|
167 |
### 参考来源
|
168 |
|
169 |
<details>
|
data/spam_message.jsonl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ed3a24959a3279fd0c1cc50efd764580ecad1869ca0b9b15e30337a91385f059
|
3 |
+
size 133678367
|
examples/preprocess/process_spam_message.py
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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("--data_file", default="data/spam_message/带标签短信.txt", type=str)
|
25 |
+
parser.add_argument(
|
26 |
+
"--output_file",
|
27 |
+
default=(project_path / "data/spam_message.jsonl"),
|
28 |
+
type=str
|
29 |
+
)
|
30 |
+
args = parser.parse_args()
|
31 |
+
return args
|
32 |
+
|
33 |
+
|
34 |
+
def main():
|
35 |
+
args = get_args()
|
36 |
+
|
37 |
+
with open(args.output_file, "w", encoding="utf-8") as fout:
|
38 |
+
with open(args.data_file, "r", encoding="utf-8") as fin:
|
39 |
+
for row in fin:
|
40 |
+
row = str(row).rstrip("\n")
|
41 |
+
row = row.split("\t", maxsplit=1)
|
42 |
+
|
43 |
+
if len(row) != 2:
|
44 |
+
print(row)
|
45 |
+
raise AssertionError
|
46 |
+
|
47 |
+
label = row[0]
|
48 |
+
text = row[1]
|
49 |
+
|
50 |
+
label = "spam" if label == "1" else "ham"
|
51 |
+
|
52 |
+
if label not in ("spam", "ham"):
|
53 |
+
raise AssertionError
|
54 |
+
|
55 |
+
num = random.random()
|
56 |
+
if num < 0.9:
|
57 |
+
split = "train"
|
58 |
+
elif num < 0.95:
|
59 |
+
split = "validation"
|
60 |
+
else:
|
61 |
+
split = "test"
|
62 |
+
|
63 |
+
row = {
|
64 |
+
"text": text,
|
65 |
+
"label": label,
|
66 |
+
"category": None,
|
67 |
+
"data_source": "spam_message",
|
68 |
+
"split": split
|
69 |
+
}
|
70 |
+
row = json.dumps(row, ensure_ascii=False)
|
71 |
+
fout.write("{}\n".format(row))
|
72 |
+
|
73 |
+
return
|
74 |
+
|
75 |
+
|
76 |
+
if __name__ == '__main__':
|
77 |
+
main()
|
examples/preprocess/samples_count.py
CHANGED
@@ -6,11 +6,12 @@ from datasets import load_dataset, DownloadMode
|
|
6 |
|
7 |
dataset_dict = load_dataset(
|
8 |
"../../spam_detect.py",
|
9 |
-
name="email_spam",
|
10 |
# name="enron_spam",
|
11 |
# name="sms_spam",
|
12 |
# name="spam_assassin",
|
13 |
# name="spam_detection",
|
|
|
14 |
split=None,
|
15 |
cache_dir=None,
|
16 |
download_mode=DownloadMode.FORCE_REDOWNLOAD
|
|
|
6 |
|
7 |
dataset_dict = load_dataset(
|
8 |
"../../spam_detect.py",
|
9 |
+
# name="email_spam",
|
10 |
# name="enron_spam",
|
11 |
# name="sms_spam",
|
12 |
# name="spam_assassin",
|
13 |
# name="spam_detection",
|
14 |
+
name="spam_message",
|
15 |
split=None,
|
16 |
cache_dir=None,
|
17 |
download_mode=DownloadMode.FORCE_REDOWNLOAD
|
main.py
CHANGED
@@ -5,9 +5,10 @@ from datasets import load_dataset, DownloadMode
|
|
5 |
|
6 |
dataset = load_dataset(
|
7 |
"spam_detect.py",
|
8 |
-
name="email_spam",
|
|
|
9 |
# name="sms_spam",
|
10 |
-
|
11 |
# name="spam_detection",
|
12 |
split="train",
|
13 |
cache_dir=None,
|
@@ -18,6 +19,8 @@ for sample in dataset:
|
|
18 |
text = sample["text"]
|
19 |
label = sample["label"]
|
20 |
|
|
|
|
|
21 |
print(text)
|
22 |
print(label)
|
23 |
print("-" * 12)
|
|
|
5 |
|
6 |
dataset = load_dataset(
|
7 |
"spam_detect.py",
|
8 |
+
# name="email_spam",
|
9 |
+
# name="enron_spam",
|
10 |
# name="sms_spam",
|
11 |
+
name="spam_assassin",
|
12 |
# name="spam_detection",
|
13 |
split="train",
|
14 |
cache_dir=None,
|
|
|
19 |
text = sample["text"]
|
20 |
label = sample["label"]
|
21 |
|
22 |
+
if label == "spam":
|
23 |
+
continue
|
24 |
print(text)
|
25 |
print(label)
|
26 |
print("-" * 12)
|
spam_detect.py
CHANGED
@@ -16,6 +16,7 @@ _urls = {
|
|
16 |
"sms_spam": "data/sms_spam.jsonl",
|
17 |
"spam_assassin": "data/spam_assassin.jsonl",
|
18 |
"spam_detection": "data/spam_detection.jsonl",
|
|
|
19 |
|
20 |
}
|
21 |
|
|
|
16 |
"sms_spam": "data/sms_spam.jsonl",
|
17 |
"spam_assassin": "data/spam_assassin.jsonl",
|
18 |
"spam_detection": "data/spam_detection.jsonl",
|
19 |
+
"spam_message": "data/spam_message.jsonl",
|
20 |
|
21 |
}
|
22 |
|