Datasets:

Modalities:
Tabular
Text
ArXiv:
Libraries:
Datasets
License:
Jonathan Li commited on
Commit
4b465b5
1 Parent(s): c5ace1d
Files changed (2) hide show
  1. jsonlify.py +12 -0
  2. process.ipynb +95 -0
jsonlify.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Script used to put files into jsonl format (original downloaded from web archive link, in readme)
2
+ import glob
3
+
4
+ for folder in glob.glob("*/"):
5
+ a = []
6
+ for file in glob.glob(f"./{folder}*.json"):
7
+ contents = open(file, "r").read()
8
+ a.append(contents)
9
+
10
+ with open(f"{folder[:-1]}.jsonl", "w+") as f:
11
+ f.write("\n".join(a))
12
+ a.clear()
process.ipynb ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "import pandas as pd"
10
+ ]
11
+ },
12
+ {
13
+ "cell_type": "code",
14
+ "execution_count": null,
15
+ "metadata": {},
16
+ "outputs": [],
17
+ "source": [
18
+ "_dev = pd.read_json(\"EN_dev.jsonl\", lines=True)\n",
19
+ "_test = pd.read_json(\"EN_test.jsonl\", lines=True)\n",
20
+ "_train = pd.read_json(\"EN_train.jsonl\", lines=True)"
21
+ ]
22
+ },
23
+ {
24
+ "cell_type": "code",
25
+ "execution_count": null,
26
+ "metadata": {},
27
+ "outputs": [],
28
+ "source": [
29
+ "def process(df):\n",
30
+ " df = df.copy()\n",
31
+ " df.columns = df.columns.str.lower()\n",
32
+ " df[\"violated\"] = df.violated_articles.str.len() != 0\n",
33
+ " return df\n",
34
+ "\n",
35
+ "dev = process(_dev)\n",
36
+ "test = process(_test)\n",
37
+ "train = process(_train)"
38
+ ]
39
+ },
40
+ {
41
+ "cell_type": "code",
42
+ "execution_count": null,
43
+ "metadata": {},
44
+ "outputs": [],
45
+ "source": [
46
+ "d = {k: list(v) for k, v in train.groupby(\"violated\").indices.items()}\n",
47
+ "dist = dict(dev.violated.value_counts().items())\n",
48
+ "d_train = {k: v[0:dist[k]] for k, v in d.items()}\n",
49
+ "d_remaining = {k: v[dist[k]:] for k, v in d.items()}\n",
50
+ "\n",
51
+ "new_rows = []\n",
52
+ "for label in dev[\"violated\"]:\n",
53
+ " new_rows.append(train.iloc[d_train[label].pop()])\n",
54
+ "\n",
55
+ "new_train = pd.concat([pd.DataFrame(new_rows), pd.DataFrame(train.iloc[i] for l in d_remaining.values() for i in l).sample(frac=1, random_state=42)])"
56
+ ]
57
+ },
58
+ {
59
+ "cell_type": "code",
60
+ "execution_count": null,
61
+ "metadata": {},
62
+ "outputs": [],
63
+ "source": [
64
+ "new_train.to_json(\"train.jsonl\", lines=True, orient=\"records\")"
65
+ ]
66
+ }
67
+ ],
68
+ "metadata": {
69
+ "kernelspec": {
70
+ "display_name": "Python 3.10.5 64-bit",
71
+ "language": "python",
72
+ "name": "python3"
73
+ },
74
+ "language_info": {
75
+ "codemirror_mode": {
76
+ "name": "ipython",
77
+ "version": 3
78
+ },
79
+ "file_extension": ".py",
80
+ "mimetype": "text/x-python",
81
+ "name": "python",
82
+ "nbconvert_exporter": "python",
83
+ "pygments_lexer": "ipython3",
84
+ "version": "3.10.5"
85
+ },
86
+ "orig_nbformat": 4,
87
+ "vscode": {
88
+ "interpreter": {
89
+ "hash": "e7370f93d1d0cde622a1f8e1c04877d8463912d04d973331ad4851f04de6915a"
90
+ }
91
+ }
92
+ },
93
+ "nbformat": 4,
94
+ "nbformat_minor": 2
95
+ }