add README
Browse files- README.md +37 -0
- extraction_script/extract_title_selftext.py +39 -0
- extraction_script/parse_files.py +15 -0
README.md
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Reddit (Title, Body)-Pairs
|
2 |
+
|
3 |
+
This dataset contains jsonl-Files about (title, body) pairs from Reddit. Each line is a JSON object of the following format:
|
4 |
+
```
|
5 |
+
{'title': 'The title of a thread', 'body': 'The longer body of the thread', 'subreddit': 'subreddit_name'}
|
6 |
+
```
|
7 |
+
|
8 |
+
The 2021 file contains submissions up until including 2021-06. Entries in the respective files are shuffled on a monthly basis.
|
9 |
+
|
10 |
+
The data has been filtered for:
|
11 |
+
- Remove threads with an upvote_ratio < 0.5
|
12 |
+
- Only include threads with a title more than 25 characters and bodies with `len(title)+25 < len(body) < 4096`
|
13 |
+
- Only keep threads with at least 3 comments or at least 3 upvotes.
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
## Overview
|
18 |
+
|
19 |
+
| File | Lines |
|
20 |
+
| --- | :---: |
|
21 |
+
| reddit_title_text_2010.jsonl.gz | 431,782
|
22 |
+
| reddit_title_text_2011.jsonl.gz | 1,673,264
|
23 |
+
| reddit_title_text_2012.jsonl.gz | 3,727,526
|
24 |
+
| reddit_title_text_2013.jsonl.gz | 5,713,956
|
25 |
+
| reddit_title_text_2014.jsonl.gz | 85,38,976
|
26 |
+
| reddit_title_text_2015.jsonl.gz | 11,064,453
|
27 |
+
| reddit_title_text_2016.jsonl.gz | 12,224,789
|
28 |
+
| reddit_title_text_2017.jsonl.gz | 13,558,139
|
29 |
+
| reddit_title_text_2018.jsonl.gz | 15,552,110
|
30 |
+
| reddit_title_text_2019.jsonl.gz | 19,224,970
|
31 |
+
| reddit_title_text_2020.jsonl.gz | 23,030,988
|
32 |
+
| reddit_title_text_2021.jsonl.gz | 12,704,958
|
33 |
+
|
34 |
+
|
35 |
+
Note: The data comes from [Pushshift](https://files.pushshift.io/reddit/). Please have a look at the respective license of Reddit and Pushshift before using the data.
|
36 |
+
|
37 |
+
Be aware that this dataset is not filtered for biases, hate-speech, spam, racial slurm etc. It depicts the content as it is posted on Reddit.
|
extraction_script/extract_title_selftext.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import gzip
|
3 |
+
import sys
|
4 |
+
import re
|
5 |
+
import tqdm
|
6 |
+
from collections import defaultdict
|
7 |
+
import logging
|
8 |
+
|
9 |
+
|
10 |
+
|
11 |
+
def clean_text(text):
|
12 |
+
text = text.strip()
|
13 |
+
text = re.sub(r'\[(.*)\]\(.*\)', '\g<1>', text) #Markdown
|
14 |
+
text = re.sub(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', '', text) # URLs
|
15 |
+
return text
|
16 |
+
|
17 |
+
|
18 |
+
for line in tqdm.tqdm(sys.stdin):
|
19 |
+
try:
|
20 |
+
data = json.loads(line)
|
21 |
+
if 'title' in data and 'selftext' in data and 'num_comments' in data:
|
22 |
+
title = clean_text(data['title'])
|
23 |
+
selftext = clean_text(data['selftext'])
|
24 |
+
num_comments = data['num_comments']
|
25 |
+
score = data['score']
|
26 |
+
subreddit = data['subreddit'] if 'subreddit' in data else ''
|
27 |
+
|
28 |
+
if 'upvote_ratio' in data and float(data['upvote_ratio']) < 0.5:
|
29 |
+
continue
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
if len(title) > 25 and len(title)+25 < len(selftext) < 4096 and (score >= 3 or num_comments >= 3):
|
34 |
+
print(json.dumps({'title': title, 'body': selftext, 'subreddit': subreddit}))
|
35 |
+
|
36 |
+
|
37 |
+
|
38 |
+
except:
|
39 |
+
logging.warning("exception")
|
extraction_script/parse_files.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sys
|
2 |
+
import os
|
3 |
+
import random
|
4 |
+
print("#!/bin/sh")
|
5 |
+
filepaths = sys.argv[1:]
|
6 |
+
random.shuffle(filepaths)
|
7 |
+
for filepath in filepaths:
|
8 |
+
filename = os.path.basename(filepath)
|
9 |
+
year = filename[3:7]
|
10 |
+
|
11 |
+
cmd = f"zstdcat --long=31 {filepath} | python extract_title_selftext.py | gzip >> submissions_parsed/reddit_title_text_{year}.jsonl.gz"
|
12 |
+
|
13 |
+
print(cmd)
|
14 |
+
os.system(cmd)
|
15 |
+
|