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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"attachments": {},
|
5 |
+
"cell_type": "markdown",
|
6 |
+
"metadata": {},
|
7 |
+
"source": [
|
8 |
+
"# Create HF Dataset\n",
|
9 |
+
"Create a huggingface dataset from the word frequencies from Danish Gigaword \n",
|
10 |
+
"(collected before 2022-22-01).\n",
|
11 |
+
"These word frequencies are from the Danish Gigaword Corpus which are tokenized using\n",
|
12 |
+
"the spacy pipeline for Danish `\"da_core_news_lg\"` using `spacy>=3.0.0,<3.4.0`.\n",
|
13 |
+
"See the script \"word_freq.py\" for more details.\n",
|
14 |
+
"\n"
|
15 |
+
]
|
16 |
+
},
|
17 |
+
{
|
18 |
+
"attachments": {},
|
19 |
+
"cell_type": "markdown",
|
20 |
+
"metadata": {},
|
21 |
+
"source": [
|
22 |
+
"## Setup"
|
23 |
+
]
|
24 |
+
},
|
25 |
+
{
|
26 |
+
"cell_type": "code",
|
27 |
+
"execution_count": 1,
|
28 |
+
"metadata": {},
|
29 |
+
"outputs": [],
|
30 |
+
"source": [
|
31 |
+
"# !pip install datasets==2.8.0"
|
32 |
+
]
|
33 |
+
},
|
34 |
+
{
|
35 |
+
"cell_type": "code",
|
36 |
+
"execution_count": 2,
|
37 |
+
"metadata": {},
|
38 |
+
"outputs": [
|
39 |
+
{
|
40 |
+
"name": "stderr",
|
41 |
+
"output_type": "stream",
|
42 |
+
"text": [
|
43 |
+
"/home/kenneth/.Envs/word_freq/lib/python3.8/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
|
44 |
+
" from .autonotebook import tqdm as notebook_tqdm\n"
|
45 |
+
]
|
46 |
+
}
|
47 |
+
],
|
48 |
+
"source": [
|
49 |
+
"import json\n",
|
50 |
+
"import os\n",
|
51 |
+
"from pathlib import Path\n",
|
52 |
+
"import pandas as pd\n",
|
53 |
+
"from datasets import Dataset, DatasetInfo, DatasetDict\n",
|
54 |
+
"import numpy as np"
|
55 |
+
]
|
56 |
+
},
|
57 |
+
{
|
58 |
+
"cell_type": "code",
|
59 |
+
"execution_count": 3,
|
60 |
+
"metadata": {},
|
61 |
+
"outputs": [],
|
62 |
+
"source": [
|
63 |
+
"# mapping from domain to top-level domain\n",
|
64 |
+
"domain_mapping_dict = {\n",
|
65 |
+
" \"retsinformationdk\": \"Legal\",\n",
|
66 |
+
" \"skat\": \"Legal\",\n",
|
67 |
+
" \"retspraksis\": \"Legal\",\n",
|
68 |
+
" \"hest\": \"Social Media\",\n",
|
69 |
+
" \"cc\": \"Web\",\n",
|
70 |
+
" \"adl\": \"Wiki & Books\",\n",
|
71 |
+
" \"botxt\": \"Other\",\n",
|
72 |
+
" \"danavis\": \"News\",\n",
|
73 |
+
" \"dannet\": \"dannet\",\n",
|
74 |
+
" \"depbank\": \"Other\",\n",
|
75 |
+
" \"ep\": \"Conversation\",\n",
|
76 |
+
" \"ft\": \"Conversation\",\n",
|
77 |
+
" \"gutenberg\": \"Wiki & Books\",\n",
|
78 |
+
" \"jvj\": \"Wiki & Books\",\n",
|
79 |
+
" \"naat\": \"Conversation\",\n",
|
80 |
+
" \"opensub\": \"Conversation\",\n",
|
81 |
+
" \"relig\": \"Wiki & Books\",\n",
|
82 |
+
" \"spont\": \"Conversation\",\n",
|
83 |
+
" \"synne\": \"Other\",\n",
|
84 |
+
" \"tv2r\": \"News\",\n",
|
85 |
+
" \"wiki\": \"Wiki & Books\",\n",
|
86 |
+
" \"wikibooks\": \"Wiki & Books\",\n",
|
87 |
+
" \"wikisource\": \"Wiki & Books\",\n",
|
88 |
+
" \"twfv19\": \"Social Media\",\n",
|
89 |
+
"}\n",
|
90 |
+
"\n",
|
91 |
+
"# mapping from domain to its long name format\n",
|
92 |
+
"longname_mapping_dict = {\n",
|
93 |
+
" \"retsinformationdk\": \"retsinformation.dk (Danish legal information)\",\n",
|
94 |
+
" \"skat\": \"Skat (Danish tax authority)\",\n",
|
95 |
+
" \"retspraksis\": \"retspraksis (Danish legal information)\",\n",
|
96 |
+
" \"hest\": \"Hestenettet (Danish debate forum)\",\n",
|
97 |
+
" \"cc\": \"Common Crawl\",\n",
|
98 |
+
" \"adl\": \" Archive for Danish Literature\",\n",
|
99 |
+
" \"botxt\": \"Bornholmsk (Danish dialect)\",\n",
|
100 |
+
" \"danavis\": \"Danish daily newspapers\",\n",
|
101 |
+
" \"dannet\": \"DanNet (Danish WordNet)\",\n",
|
102 |
+
" \"depbank\": \"Danish Dependency Treebank\",\n",
|
103 |
+
" \"ep\": \"European Parliament\",\n",
|
104 |
+
" \"ft\": \"Folketinget (Danish Parliament)\",\n",
|
105 |
+
" \"gutenberg\": \"Gutenberg\",\n",
|
106 |
+
" \"jvj\": \"Johannes V. Jensen (Danish poet)\",\n",
|
107 |
+
" \"naat\": \"NAAT\",\n",
|
108 |
+
" \"opensub\": \"Open Subtitles\",\n",
|
109 |
+
" \"relig\": \"Religious texts\",\n",
|
110 |
+
" \"spont\": \"Spontaneous speech\",\n",
|
111 |
+
" \"synne\": \"Synderjysk (Danish dialect)\",\n",
|
112 |
+
" \"tv2r\": \"TV 2 Radio (Danish news)\",\n",
|
113 |
+
" \"wiki\": \"Wikipedia\",\n",
|
114 |
+
" \"wikibooks\": \"Wikibooks\",\n",
|
115 |
+
" \"wikisource\": \"Wikisource\",\n",
|
116 |
+
" \"twfv19\": \"Twitter Folketingsvalget 2019 (Danish election tweets)\",\n",
|
117 |
+
"}\n"
|
118 |
+
]
|
119 |
+
},
|
120 |
+
{
|
121 |
+
"attachments": {},
|
122 |
+
"cell_type": "markdown",
|
123 |
+
"metadata": {},
|
124 |
+
"source": [
|
125 |
+
"## The Data"
|
126 |
+
]
|
127 |
+
},
|
128 |
+
{
|
129 |
+
"cell_type": "code",
|
130 |
+
"execution_count": 4,
|
131 |
+
"metadata": {},
|
132 |
+
"outputs": [
|
133 |
+
{
|
134 |
+
"name": "stdout",
|
135 |
+
"output_type": "stream",
|
136 |
+
"text": [
|
137 |
+
"teder {'NOUN': 1}\n",
|
138 |
+
"i {'ADP': 81002, 'ADV': 708, 'CCONJ': 1, 'PRON': 5, 'X': 2}\n",
|
139 |
+
"Marbæk {'PROPN': 3}\n",
|
140 |
+
"? {'PUNCT': 31558}\n",
|
141 |
+
"ville {'AUX': 9184, 'VERB': 177}\n",
|
142 |
+
"jo {'ADV': 15825, 'SCONJ': 227, 'INTJ': 88}\n",
|
143 |
+
"være {'AUX': 12805, 'VERB': 3773, 'X': 1, 'ADJ': 3, 'NOUN': 1, 'PRON': 1}\n"
|
144 |
+
]
|
145 |
+
}
|
146 |
+
],
|
147 |
+
"source": [
|
148 |
+
"path = Path(\"/data/DAGW/word_freqs\")\n",
|
149 |
+
"json_files = [str(path / f) for f in os.listdir(path) if f.endswith(\".json\")]\n",
|
150 |
+
"\n",
|
151 |
+
"\n",
|
152 |
+
"with open(json_files[0]) as f:\n",
|
153 |
+
" data = json.load(f)\n",
|
154 |
+
"\n",
|
155 |
+
"# inspect\n",
|
156 |
+
"for i, (k, v) in enumerate(data.items()):\n",
|
157 |
+
" print(k, v)\n",
|
158 |
+
" if i > 5:\n",
|
159 |
+
" break"
|
160 |
+
]
|
161 |
+
},
|
162 |
+
{
|
163 |
+
"cell_type": "code",
|
164 |
+
"execution_count": 5,
|
165 |
+
"metadata": {},
|
166 |
+
"outputs": [
|
167 |
+
{
|
168 |
+
"name": "stdout",
|
169 |
+
"output_type": "stream",
|
170 |
+
"text": [
|
171 |
+
"{'dannet', 'adl', 'hest', 'wiki', 'relig', 'botxt', 'synne', 'depbank', 'cc', 'tv2r', 'opensub', 'twfv19', 'retsinformationdk', 'wikibooks', 'jvj', 'ft', 'gutenberg', 'retspraksis', 'ep', 'skat', 'spont', 'wikisource', 'naat'}\n"
|
172 |
+
]
|
173 |
+
}
|
174 |
+
],
|
175 |
+
"source": [
|
176 |
+
"def get_subdomain(json_file):\n",
|
177 |
+
" return json_file.split(\"/\")[-1].split(\".\")[0].split(\"_\")[1]\n",
|
178 |
+
"\n",
|
179 |
+
"\n",
|
180 |
+
"domains = set([get_subdomain(json_file) for json_file in json_files])\n",
|
181 |
+
"print(domains)\n"
|
182 |
+
]
|
183 |
+
},
|
184 |
+
{
|
185 |
+
"attachments": {},
|
186 |
+
"cell_type": "markdown",
|
187 |
+
"metadata": {},
|
188 |
+
"source": [
|
189 |
+
"## Create the Datasets\n",
|
190 |
+
"We will here create 4 different datasets:\n",
|
191 |
+
"\n",
|
192 |
+
"- `word_frequencies` - Danish word frequencies from Danish Gigaword.\n",
|
193 |
+
"- `by_domain` - word frequencies pr. domain.\n",
|
194 |
+
"- `with_pos ` - word frequencies pr. domain with their part-of-speech tags derived from the spacy pipeline for Danish `\"da_core_news_lg\"`.\n",
|
195 |
+
"- `normalized` - word frequencies pr. domain normalized by the top-level domain.\n",
|
196 |
+
"\n",
|
197 |
+
"> Note: This notebook is not very efficient, it is mainly here for documentation of the process.\n"
|
198 |
+
]
|
199 |
+
},
|
200 |
+
{
|
201 |
+
"cell_type": "code",
|
202 |
+
"execution_count": 6,
|
203 |
+
"metadata": {},
|
204 |
+
"outputs": [],
|
205 |
+
"source": [
|
206 |
+
"def convert_to_dataset_format(json_file):\n",
|
207 |
+
" with open(json_file) as f:\n",
|
208 |
+
" data = json.load(f)\n",
|
209 |
+
"\n",
|
210 |
+
" domain_origin = get_subdomain(json_file)\n",
|
211 |
+
" domain = domain_mapping_dict[domain_origin]\n",
|
212 |
+
"\n",
|
213 |
+
" return [\n",
|
214 |
+
" {\n",
|
215 |
+
" \"word\": word,\n",
|
216 |
+
" \"pos\": pos,\n",
|
217 |
+
" \"freq\": freq,\n",
|
218 |
+
" \"domain\": longname_mapping_dict[domain_origin],\n",
|
219 |
+
" \"domain_short\": domain_origin,\n",
|
220 |
+
" \"top_level_domain\": domain,\n",
|
221 |
+
" }\n",
|
222 |
+
" for word, posdict in data.items()\n",
|
223 |
+
" for pos, freq in posdict.items()\n",
|
224 |
+
" ]\n",
|
225 |
+
"\n",
|
226 |
+
"\n",
|
227 |
+
"# load and convert all dataset\n",
|
228 |
+
"def load_and_convert_gen(n=None):\n",
|
229 |
+
" for i, json_file in enumerate(json_files[:n]):\n",
|
230 |
+
" print(f\"Loading {json_file} ({i+1}/{len(json_files)})\")\n",
|
231 |
+
" samples = convert_to_dataset_format(json_file)\n",
|
232 |
+
" for sample in samples:\n",
|
233 |
+
" yield sample\n"
|
234 |
+
]
|
235 |
+
},
|
236 |
+
{
|
237 |
+
"cell_type": "code",
|
238 |
+
"execution_count": 7,
|
239 |
+
"metadata": {},
|
240 |
+
"outputs": [],
|
241 |
+
"source": [
|
242 |
+
"# add dataset info for each of the datasets\n",
|
243 |
+
"info = DatasetInfo(\n",
|
244 |
+
" description=\"Danish word frequencies\",\n",
|
245 |
+
" citation=\"Derczynski, L., Ciosici, M. R., Baglini, R., Christiansen, M. H., Dalsgaard, J. A., Fusaroli, R., ... & Varab, D. (2021). The Danish Gigaword Corpus. In Proceedings of the 23rd Nordic Conference on Computational Linguistics (NoDaLiDa) (pp. 413-421).\",\n",
|
246 |
+
" homepage=\"https://huggingface.co/datasets/DDSC/partial-danish-gigaword-no-twitter\",\n",
|
247 |
+
" version=\"1.0.0\",\n",
|
248 |
+
" license=\"\",\n",
|
249 |
+
")"
|
250 |
+
]
|
251 |
+
},
|
252 |
+
{
|
253 |
+
"cell_type": "code",
|
254 |
+
"execution_count": 8,
|
255 |
+
"metadata": {},
|
256 |
+
"outputs": [
|
257 |
+
{
|
258 |
+
"name": "stdout",
|
259 |
+
"output_type": "stream",
|
260 |
+
"text": [
|
261 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_11.json (1/294)\n",
|
262 |
+
"Loading /data/DAGW/word_freqs/wordfreq_ep_12.json (2/294)\n",
|
263 |
+
"Loading /data/DAGW/word_freqs/wordfreq_skat_1.json (3/294)\n",
|
264 |
+
"Loading /data/DAGW/word_freqs/wordfreq_wiki_12.json (4/294)\n",
|
265 |
+
"Loading /data/DAGW/word_freqs/wordfreq_adl_2.json (5/294)\n",
|
266 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_46.json (6/294)\n",
|
267 |
+
"Loading /data/DAGW/word_freqs/wordfreq_cc_24.json (7/294)\n",
|
268 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_20.json (8/294)\n",
|
269 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_18.json (9/294)\n",
|
270 |
+
"Loading /data/DAGW/word_freqs/wordfreq_relig_0.json (10/294)\n",
|
271 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_12.json (11/294)\n",
|
272 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_59.json (12/294)\n",
|
273 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_42.json (13/294)\n",
|
274 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_22.json (14/294)\n",
|
275 |
+
"Loading /data/DAGW/word_freqs/wordfreq_cc_2.json (15/294)\n",
|
276 |
+
"Loading /data/DAGW/word_freqs/wordfreq_ft_11.json (16/294)\n",
|
277 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_28.json (17/294)\n",
|
278 |
+
"Loading /data/DAGW/word_freqs/wordfreq_adl_3.json (18/294)\n",
|
279 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_33.json (19/294)\n",
|
280 |
+
"Loading /data/DAGW/word_freqs/wordfreq_ft_7.json (20/294)\n",
|
281 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_48.json (21/294)\n",
|
282 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_4.json (22/294)\n",
|
283 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_13.json (23/294)\n",
|
284 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_4.json (24/294)\n",
|
285 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_46.json (25/294)\n",
|
286 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_28.json (26/294)\n",
|
287 |
+
"Loading /data/DAGW/word_freqs/wordfreq_cc_22.json (27/294)\n",
|
288 |
+
"Loading /data/DAGW/word_freqs/wordfreq_ep_2.json (28/294)\n",
|
289 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_53.json (29/294)\n",
|
290 |
+
"Loading /data/DAGW/word_freqs/wordfreq_cc_7.json (30/294)\n",
|
291 |
+
"Loading /data/DAGW/word_freqs/wordfreq_skat_12.json (31/294)\n",
|
292 |
+
"Loading /data/DAGW/word_freqs/wordfreq_tv2r_4.json (32/294)\n",
|
293 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_10.json (33/294)\n",
|
294 |
+
"Loading /data/DAGW/word_freqs/wordfreq_tv2r_2.json (34/294)\n",
|
295 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_40.json (35/294)\n",
|
296 |
+
"Loading /data/DAGW/word_freqs/wordfreq_adl_6.json (36/294)\n",
|
297 |
+
"Loading /data/DAGW/word_freqs/wordfreq_ft_10.json (37/294)\n",
|
298 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_27.json (38/294)\n",
|
299 |
+
"Loading /data/DAGW/word_freqs/wordfreq_dannet_2.json (39/294)\n",
|
300 |
+
"Loading /data/DAGW/word_freqs/wordfreq_wiki_26.json (40/294)\n",
|
301 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_30.json (41/294)\n",
|
302 |
+
"Loading /data/DAGW/word_freqs/wordfreq_wiki_11.json (42/294)\n",
|
303 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_2.json (43/294)\n",
|
304 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_21.json (44/294)\n",
|
305 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_16.json (45/294)\n",
|
306 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_37.json (46/294)\n",
|
307 |
+
"Loading /data/DAGW/word_freqs/wordfreq_wiki_0.json (47/294)\n",
|
308 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_29.json (48/294)\n",
|
309 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_33.json (49/294)\n",
|
310 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_49.json (50/294)\n",
|
311 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_47.json (51/294)\n",
|
312 |
+
"Loading /data/DAGW/word_freqs/wordfreq_wiki_18.json (52/294)\n",
|
313 |
+
"Loading /data/DAGW/word_freqs/wordfreq_wiki_20.json (53/294)\n",
|
314 |
+
"Loading /data/DAGW/word_freqs/wordfreq_wiki_13.json (54/294)\n",
|
315 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_39.json (55/294)\n",
|
316 |
+
"Loading /data/DAGW/word_freqs/wordfreq_cc_4.json (56/294)\n",
|
317 |
+
"Loading /data/DAGW/word_freqs/wordfreq_adl_0.json (57/294)\n",
|
318 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_3.json (58/294)\n",
|
319 |
+
"Loading /data/DAGW/word_freqs/wordfreq_ft_9.json (59/294)\n",
|
320 |
+
"Loading /data/DAGW/word_freqs/wordfreq_cc_17.json (60/294)\n",
|
321 |
+
"Loading /data/DAGW/word_freqs/wordfreq_ft_4.json (61/294)\n",
|
322 |
+
"Loading /data/DAGW/word_freqs/wordfreq_wiki_5.json (62/294)\n",
|
323 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retspraksis_7.json (63/294)\n",
|
324 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_47.json (64/294)\n",
|
325 |
+
"Loading /data/DAGW/word_freqs/wordfreq_wiki_22.json (65/294)\n",
|
326 |
+
"Loading /data/DAGW/word_freqs/wordfreq_cc_29.json (66/294)\n",
|
327 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_55.json (67/294)\n",
|
328 |
+
"Loading /data/DAGW/word_freqs/wordfreq_ft_6.json (68/294)\n",
|
329 |
+
"Loading /data/DAGW/word_freqs/wordfreq_skat_8.json (69/294)\n",
|
330 |
+
"Loading /data/DAGW/word_freqs/wordfreq_ep_7.json (70/294)\n",
|
331 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_41.json (71/294)\n",
|
332 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_9.json (72/294)\n",
|
333 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_15.json (73/294)\n",
|
334 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retspraksis_4.json (74/294)\n",
|
335 |
+
"Loading /data/DAGW/word_freqs/wordfreq_cc_26.json (75/294)\n",
|
336 |
+
"Loading /data/DAGW/word_freqs/wordfreq_skat_14.json (76/294)\n",
|
337 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_2.json (77/294)\n",
|
338 |
+
"Loading /data/DAGW/word_freqs/wordfreq_cc_0.json (78/294)\n",
|
339 |
+
"Loading /data/DAGW/word_freqs/wordfreq_cc_20.json (79/294)\n",
|
340 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_4.json (80/294)\n",
|
341 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retspraksis_5.json (81/294)\n",
|
342 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_24.json (82/294)\n",
|
343 |
+
"Loading /data/DAGW/word_freqs/wordfreq_cc_10.json (83/294)\n",
|
344 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_9.json (84/294)\n",
|
345 |
+
"Loading /data/DAGW/word_freqs/wordfreq_skat_11.json (85/294)\n",
|
346 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_6.json (86/294)\n",
|
347 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_19.json (87/294)\n",
|
348 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_6.json (88/294)\n",
|
349 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_5.json (89/294)\n",
|
350 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retspraksis_8.json (90/294)\n",
|
351 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_26.json (91/294)\n",
|
352 |
+
"Loading /data/DAGW/word_freqs/wordfreq_ft_12.json (92/294)\n",
|
353 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_21.json (93/294)\n",
|
354 |
+
"Loading /data/DAGW/word_freqs/wordfreq_ep_13.json (94/294)\n",
|
355 |
+
"Loading /data/DAGW/word_freqs/wordfreq_cc_13.json (95/294)\n",
|
356 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retspraksis_2.json (96/294)\n",
|
357 |
+
"Loading /data/DAGW/word_freqs/wordfreq_skat_6.json (97/294)\n",
|
358 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_1.json (98/294)\n",
|
359 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_5.json (99/294)\n",
|
360 |
+
"Loading /data/DAGW/word_freqs/wordfreq_wiki_2.json (100/294)\n",
|
361 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_17.json (101/294)\n",
|
362 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_54.json (102/294)\n",
|
363 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_34.json (103/294)\n",
|
364 |
+
"Loading /data/DAGW/word_freqs/wordfreq_jvj_0.json (104/294)\n",
|
365 |
+
"Loading /data/DAGW/word_freqs/wordfreq_cc_1.json (105/294)\n",
|
366 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_29.json (106/294)\n",
|
367 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_18.json (107/294)\n",
|
368 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_13.json (108/294)\n",
|
369 |
+
"Loading /data/DAGW/word_freqs/wordfreq_wiki_4.json (109/294)\n",
|
370 |
+
"Loading /data/DAGW/word_freqs/wordfreq_dannet_4.json (110/294)\n",
|
371 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_17.json (111/294)\n",
|
372 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_7.json (112/294)\n",
|
373 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_6.json (113/294)\n",
|
374 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retspraksis_0.json (114/294)\n",
|
375 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_5.json (115/294)\n",
|
376 |
+
"Loading /data/DAGW/word_freqs/wordfreq_skat_13.json (116/294)\n",
|
377 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_24.json (117/294)\n",
|
378 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_32.json (118/294)\n",
|
379 |
+
"Loading /data/DAGW/word_freqs/wordfreq_cc_14.json (119/294)\n",
|
380 |
+
"Loading /data/DAGW/word_freqs/wordfreq_skat_15.json (120/294)\n",
|
381 |
+
"Loading /data/DAGW/word_freqs/wordfreq_ft_0.json (121/294)\n",
|
382 |
+
"Loading /data/DAGW/word_freqs/wordfreq_ft_8.json (122/294)\n",
|
383 |
+
"Loading /data/DAGW/word_freqs/wordfreq_ep_1.json (123/294)\n",
|
384 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_13.json (124/294)\n",
|
385 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_21.json (125/294)\n",
|
386 |
+
"Loading /data/DAGW/word_freqs/wordfreq_ep_11.json (126/294)\n",
|
387 |
+
"Loading /data/DAGW/word_freqs/wordfreq_wiki_25.json (127/294)\n",
|
388 |
+
"Loading /data/DAGW/word_freqs/wordfreq_wiki_28.json (128/294)\n",
|
389 |
+
"Loading /data/DAGW/word_freqs/wordfreq_dannet_3.json (129/294)\n",
|
390 |
+
"Loading /data/DAGW/word_freqs/wordfreq_cc_28.json (130/294)\n",
|
391 |
+
"Loading /data/DAGW/word_freqs/wordfreq_wiki_21.json (131/294)\n",
|
392 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_60.json (132/294)\n",
|
393 |
+
"Loading /data/DAGW/word_freqs/wordfreq_wiki_8.json (133/294)\n",
|
394 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_22.json (134/294)\n",
|
395 |
+
"Loading /data/DAGW/word_freqs/wordfreq_skat_0.json (135/294)\n",
|
396 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_19.json (136/294)\n",
|
397 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_11.json (137/294)\n",
|
398 |
+
"Loading /data/DAGW/word_freqs/wordfreq_cc_12.json (138/294)\n",
|
399 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_32.json (139/294)\n",
|
400 |
+
"Loading /data/DAGW/word_freqs/wordfreq_cc_23.json (140/294)\n",
|
401 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_52.json (141/294)\n",
|
402 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_17.json (142/294)\n",
|
403 |
+
"Loading /data/DAGW/word_freqs/wordfreq_botxt_0.json (143/294)\n",
|
404 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_2.json (144/294)\n",
|
405 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_35.json (145/294)\n",
|
406 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_27.json (146/294)\n",
|
407 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_23.json (147/294)\n",
|
408 |
+
"Loading /data/DAGW/word_freqs/wordfreq_wiki_10.json (148/294)\n",
|
409 |
+
"Loading /data/DAGW/word_freqs/wordfreq_cc_9.json (149/294)\n",
|
410 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_20.json (150/294)\n",
|
411 |
+
"Loading /data/DAGW/word_freqs/wordfreq_wiki_14.json (151/294)\n",
|
412 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_15.json (152/294)\n",
|
413 |
+
"Loading /data/DAGW/word_freqs/wordfreq_skat_4.json (153/294)\n",
|
414 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_0.json (154/294)\n",
|
415 |
+
"Loading /data/DAGW/word_freqs/wordfreq_cc_19.json (155/294)\n",
|
416 |
+
"Loading /data/DAGW/word_freqs/wordfreq_tv2r_1.json (156/294)\n",
|
417 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_37.json (157/294)\n",
|
418 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_58.json (158/294)\n",
|
419 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_31.json (159/294)\n",
|
420 |
+
"Loading /data/DAGW/word_freqs/wordfreq_skat_9.json (160/294)\n",
|
421 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_43.json (161/294)\n",
|
422 |
+
"Loading /data/DAGW/word_freqs/wordfreq_wiki_17.json (162/294)\n",
|
423 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_22.json (163/294)\n",
|
424 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_34.json (164/294)\n",
|
425 |
+
"Loading /data/DAGW/word_freqs/wordfreq_depbank_0.json (165/294)\n",
|
426 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_23.json (166/294)\n",
|
427 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retspraksis_1.json (167/294)\n",
|
428 |
+
"Loading /data/DAGW/word_freqs/wordfreq_wiki_1.json (168/294)\n",
|
429 |
+
"Loading /data/DAGW/word_freqs/wordfreq_ep_5.json (169/294)\n",
|
430 |
+
"Loading /data/DAGW/word_freqs/wordfreq_skat_7.json (170/294)\n",
|
431 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_40.json (171/294)\n",
|
432 |
+
"Loading /data/DAGW/word_freqs/wordfreq_tv2r_5.json (172/294)\n",
|
433 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_0.json (173/294)\n",
|
434 |
+
"Loading /data/DAGW/word_freqs/wordfreq_gutenberg_0.json (174/294)\n",
|
435 |
+
"Loading /data/DAGW/word_freqs/wordfreq_wiki_6.json (175/294)\n",
|
436 |
+
"Loading /data/DAGW/word_freqs/wordfreq_adl_4.json (176/294)\n",
|
437 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_44.json (177/294)\n",
|
438 |
+
"Loading /data/DAGW/word_freqs/wordfreq_cc_11.json (178/294)\n",
|
439 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_16.json (179/294)\n",
|
440 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_26.json (180/294)\n",
|
441 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_30.json (181/294)\n",
|
442 |
+
"Loading /data/DAGW/word_freqs/wordfreq_wiki_7.json (182/294)\n",
|
443 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_36.json (183/294)\n",
|
444 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_1.json (184/294)\n",
|
445 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_23.json (185/294)\n",
|
446 |
+
"Loading /data/DAGW/word_freqs/wordfreq_cc_25.json (186/294)\n",
|
447 |
+
"Loading /data/DAGW/word_freqs/wordfreq_cc_18.json (187/294)\n",
|
448 |
+
"Loading /data/DAGW/word_freqs/wordfreq_ep_10.json (188/294)\n",
|
449 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_15.json (189/294)\n",
|
450 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_28.json (190/294)\n",
|
451 |
+
"Loading /data/DAGW/word_freqs/wordfreq_wiki_27.json (191/294)\n",
|
452 |
+
"Loading /data/DAGW/word_freqs/wordfreq_wiki_3.json (192/294)\n",
|
453 |
+
"Loading /data/DAGW/word_freqs/wordfreq_ft_3.json (193/294)\n",
|
454 |
+
"Loading /data/DAGW/word_freqs/wordfreq_wikibooks_0.json (194/294)\n",
|
455 |
+
"Loading /data/DAGW/word_freqs/wordfreq_cc_6.json (195/294)\n",
|
456 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_8.json (196/294)\n",
|
457 |
+
"Loading /data/DAGW/word_freqs/wordfreq_cc_16.json (197/294)\n",
|
458 |
+
"Loading /data/DAGW/word_freqs/wordfreq_cc_15.json (198/294)\n",
|
459 |
+
"Loading /data/DAGW/word_freqs/wordfreq_ep_6.json (199/294)\n",
|
460 |
+
"Loading /data/DAGW/word_freqs/wordfreq_cc_8.json (200/294)\n",
|
461 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_11.json (201/294)\n",
|
462 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_34.json (202/294)\n",
|
463 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_36.json (203/294)\n",
|
464 |
+
"Loading /data/DAGW/word_freqs/wordfreq_twfv19_0.json (204/294)\n",
|
465 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_12.json (205/294)\n",
|
466 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_50.json (206/294)\n",
|
467 |
+
"Loading /data/DAGW/word_freqs/wordfreq_cc_21.json (207/294)\n",
|
468 |
+
"Loading /data/DAGW/word_freqs/wordfreq_ep_4.json (208/294)\n",
|
469 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_25.json (209/294)\n",
|
470 |
+
"Loading /data/DAGW/word_freqs/wordfreq_spont_0.json (210/294)\n",
|
471 |
+
"Loading /data/DAGW/word_freqs/wordfreq_wiki_23.json (211/294)\n",
|
472 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_50.json (212/294)\n",
|
473 |
+
"Loading /data/DAGW/word_freqs/wordfreq_ep_3.json (213/294)\n",
|
474 |
+
"Loading /data/DAGW/word_freqs/wordfreq_naat_0.json (214/294)\n",
|
475 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_10.json (215/294)\n",
|
476 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_35.json (216/294)\n",
|
477 |
+
"Loading /data/DAGW/word_freqs/wordfreq_wikisource_0.json (217/294)\n",
|
478 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_30.json (218/294)\n",
|
479 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_12.json (219/294)\n",
|
480 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_27.json (220/294)\n",
|
481 |
+
"Loading /data/DAGW/word_freqs/wordfreq_ep_9.json (221/294)\n",
|
482 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_31.json (222/294)\n",
|
483 |
+
"Loading /data/DAGW/word_freqs/wordfreq_twfv19_2.json (223/294)\n",
|
484 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_8.json (224/294)\n",
|
485 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_38.json (225/294)\n",
|
486 |
+
"Loading /data/DAGW/word_freqs/wordfreq_wiki_24.json (226/294)\n",
|
487 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_3.json (227/294)\n",
|
488 |
+
"Loading /data/DAGW/word_freqs/wordfreq_ep_0.json (228/294)\n",
|
489 |
+
"Loading /data/DAGW/word_freqs/wordfreq_tv2r_0.json (229/294)\n",
|
490 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_62.json (230/294)\n",
|
491 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_25.json (231/294)\n",
|
492 |
+
"Loading /data/DAGW/word_freqs/wordfreq_dannet_1.json (232/294)\n",
|
493 |
+
"Loading /data/DAGW/word_freqs/wordfreq_wiki_9.json (233/294)\n",
|
494 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_26.json (234/294)\n",
|
495 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_45.json (235/294)\n",
|
496 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_14.json (236/294)\n",
|
497 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_42.json (237/294)\n",
|
498 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_18.json (238/294)\n",
|
499 |
+
"Loading /data/DAGW/word_freqs/wordfreq_cc_5.json (239/294)\n",
|
500 |
+
"Loading /data/DAGW/word_freqs/wordfreq_wiki_16.json (240/294)\n",
|
501 |
+
"Loading /data/DAGW/word_freqs/wordfreq_wiki_15.json (241/294)\n",
|
502 |
+
"Loading /data/DAGW/word_freqs/wordfreq_skat_10.json (242/294)\n",
|
503 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_44.json (243/294)\n",
|
504 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_41.json (244/294)\n",
|
505 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_7.json (245/294)\n",
|
506 |
+
"Loading /data/DAGW/word_freqs/wordfreq_cc_3.json (246/294)\n",
|
507 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_24.json (247/294)\n",
|
508 |
+
"Loading /data/DAGW/word_freqs/wordfreq_tv2r_3.json (248/294)\n",
|
509 |
+
"Loading /data/DAGW/word_freqs/wordfreq_skat_3.json (249/294)\n",
|
510 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_56.json (250/294)\n",
|
511 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_8.json (251/294)\n",
|
512 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_16.json (252/294)\n",
|
513 |
+
"Loading /data/DAGW/word_freqs/wordfreq_adl_5.json (253/294)\n",
|
514 |
+
"Loading /data/DAGW/word_freqs/wordfreq_cc_27.json (254/294)\n",
|
515 |
+
"Loading /data/DAGW/word_freqs/wordfreq_dannet_0.json (255/294)\n",
|
516 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_1.json (256/294)\n",
|
517 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_19.json (257/294)\n",
|
518 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_14.json (258/294)\n",
|
519 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_20.json (259/294)\n",
|
520 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_29.json (260/294)\n",
|
521 |
+
"Loading /data/DAGW/word_freqs/wordfreq_skat_5.json (261/294)\n",
|
522 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_10.json (262/294)\n",
|
523 |
+
"Loading /data/DAGW/word_freqs/wordfreq_ep_8.json (263/294)\n",
|
524 |
+
"Loading /data/DAGW/word_freqs/wordfreq_synne_0.json (264/294)\n",
|
525 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_57.json (265/294)\n",
|
526 |
+
"Loading /data/DAGW/word_freqs/wordfreq_ft_2.json (266/294)\n",
|
527 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_51.json (267/294)\n",
|
528 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_61.json (268/294)\n",
|
529 |
+
"Loading /data/DAGW/word_freqs/wordfreq_twfv19_1.json (269/294)\n",
|
530 |
+
"Loading /data/DAGW/word_freqs/wordfreq_ft_1.json (270/294)\n",
|
531 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_36.json (271/294)\n",
|
532 |
+
"Loading /data/DAGW/word_freqs/wordfreq_skat_2.json (272/294)\n",
|
533 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_25.json (273/294)\n",
|
534 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retspraksis_3.json (274/294)\n",
|
535 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_48.json (275/294)\n",
|
536 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_49.json (276/294)\n",
|
537 |
+
"Loading /data/DAGW/word_freqs/wordfreq_ft_5.json (277/294)\n",
|
538 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_35.json (278/294)\n",
|
539 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_43.json (279/294)\n",
|
540 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_0.json (280/294)\n",
|
541 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retspraksis_6.json (281/294)\n",
|
542 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_45.json (282/294)\n",
|
543 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_37.json (283/294)\n",
|
544 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_9.json (284/294)\n",
|
545 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_7.json (285/294)\n",
|
546 |
+
"Loading /data/DAGW/word_freqs/wordfreq_opensub_31.json (286/294)\n",
|
547 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_39.json (287/294)\n",
|
548 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_14.json (288/294)\n",
|
549 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_3.json (289/294)\n",
|
550 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_38.json (290/294)\n",
|
551 |
+
"Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_33.json (291/294)\n",
|
552 |
+
"Loading /data/DAGW/word_freqs/wordfreq_wiki_19.json (292/294)\n",
|
553 |
+
"Loading /data/DAGW/word_freqs/wordfreq_hest_32.json (293/294)\n",
|
554 |
+
"Loading /data/DAGW/word_freqs/wordfreq_adl_1.json (294/294)\n"
|
555 |
+
]
|
556 |
+
}
|
557 |
+
],
|
558 |
+
"source": [
|
559 |
+
"# convert to huggingface dataset\n",
|
560 |
+
"dataset = Dataset.from_list(list(load_and_convert_gen()), info=info)\n"
|
561 |
+
]
|
562 |
+
},
|
563 |
+
{
|
564 |
+
"attachments": {},
|
565 |
+
"cell_type": "markdown",
|
566 |
+
"metadata": {},
|
567 |
+
"source": [
|
568 |
+
"### Create the word_frequencies dataset"
|
569 |
+
]
|
570 |
+
},
|
571 |
+
{
|
572 |
+
"cell_type": "code",
|
573 |
+
"execution_count": 28,
|
574 |
+
"metadata": {},
|
575 |
+
"outputs": [],
|
576 |
+
"source": [
|
577 |
+
"df = dataset.to_pandas()\n"
|
578 |
+
]
|
579 |
+
},
|
580 |
+
{
|
581 |
+
"cell_type": "code",
|
582 |
+
"execution_count": 10,
|
583 |
+
"metadata": {},
|
584 |
+
"outputs": [
|
585 |
+
{
|
586 |
+
"data": {
|
587 |
+
"text/html": [
|
588 |
+
"<div>\n",
|
589 |
+
"<style scoped>\n",
|
590 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
591 |
+
" vertical-align: middle;\n",
|
592 |
+
" }\n",
|
593 |
+
"\n",
|
594 |
+
" .dataframe tbody tr th {\n",
|
595 |
+
" vertical-align: top;\n",
|
596 |
+
" }\n",
|
597 |
+
"\n",
|
598 |
+
" .dataframe thead th {\n",
|
599 |
+
" text-align: right;\n",
|
600 |
+
" }\n",
|
601 |
+
"</style>\n",
|
602 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
603 |
+
" <thead>\n",
|
604 |
+
" <tr style=\"text-align: right;\">\n",
|
605 |
+
" <th></th>\n",
|
606 |
+
" <th>word</th>\n",
|
607 |
+
" <th>pos</th>\n",
|
608 |
+
" <th>freq</th>\n",
|
609 |
+
" <th>domain</th>\n",
|
610 |
+
" <th>domain_short</th>\n",
|
611 |
+
" <th>top_level_domain</th>\n",
|
612 |
+
" </tr>\n",
|
613 |
+
" </thead>\n",
|
614 |
+
" <tbody>\n",
|
615 |
+
" <tr>\n",
|
616 |
+
" <th>0</th>\n",
|
617 |
+
" <td>teder</td>\n",
|
618 |
+
" <td>NOUN</td>\n",
|
619 |
+
" <td>1</td>\n",
|
620 |
+
" <td>Hestenettet (Danish debate forum)</td>\n",
|
621 |
+
" <td>hest</td>\n",
|
622 |
+
" <td>Social Media</td>\n",
|
623 |
+
" </tr>\n",
|
624 |
+
" <tr>\n",
|
625 |
+
" <th>1</th>\n",
|
626 |
+
" <td>i</td>\n",
|
627 |
+
" <td>ADP</td>\n",
|
628 |
+
" <td>81002</td>\n",
|
629 |
+
" <td>Hestenettet (Danish debate forum)</td>\n",
|
630 |
+
" <td>hest</td>\n",
|
631 |
+
" <td>Social Media</td>\n",
|
632 |
+
" </tr>\n",
|
633 |
+
" <tr>\n",
|
634 |
+
" <th>2</th>\n",
|
635 |
+
" <td>i</td>\n",
|
636 |
+
" <td>ADV</td>\n",
|
637 |
+
" <td>708</td>\n",
|
638 |
+
" <td>Hestenettet (Danish debate forum)</td>\n",
|
639 |
+
" <td>hest</td>\n",
|
640 |
+
" <td>Social Media</td>\n",
|
641 |
+
" </tr>\n",
|
642 |
+
" <tr>\n",
|
643 |
+
" <th>3</th>\n",
|
644 |
+
" <td>i</td>\n",
|
645 |
+
" <td>CCONJ</td>\n",
|
646 |
+
" <td>1</td>\n",
|
647 |
+
" <td>Hestenettet (Danish debate forum)</td>\n",
|
648 |
+
" <td>hest</td>\n",
|
649 |
+
" <td>Social Media</td>\n",
|
650 |
+
" </tr>\n",
|
651 |
+
" <tr>\n",
|
652 |
+
" <th>4</th>\n",
|
653 |
+
" <td>i</td>\n",
|
654 |
+
" <td>PRON</td>\n",
|
655 |
+
" <td>5</td>\n",
|
656 |
+
" <td>Hestenettet (Danish debate forum)</td>\n",
|
657 |
+
" <td>hest</td>\n",
|
658 |
+
" <td>Social Media</td>\n",
|
659 |
+
" </tr>\n",
|
660 |
+
" <tr>\n",
|
661 |
+
" <th>...</th>\n",
|
662 |
+
" <td>...</td>\n",
|
663 |
+
" <td>...</td>\n",
|
664 |
+
" <td>...</td>\n",
|
665 |
+
" <td>...</td>\n",
|
666 |
+
" <td>...</td>\n",
|
667 |
+
" <td>...</td>\n",
|
668 |
+
" </tr>\n",
|
669 |
+
" <tr>\n",
|
670 |
+
" <th>51035982</th>\n",
|
671 |
+
" <td>Leverandører</td>\n",
|
672 |
+
" <td>NOUN</td>\n",
|
673 |
+
" <td>1</td>\n",
|
674 |
+
" <td>Archive for Danish Literature</td>\n",
|
675 |
+
" <td>adl</td>\n",
|
676 |
+
" <td>Wiki & Books</td>\n",
|
677 |
+
" </tr>\n",
|
678 |
+
" <tr>\n",
|
679 |
+
" <th>51035983</th>\n",
|
680 |
+
" <td>halvlé</td>\n",
|
681 |
+
" <td>NOUN</td>\n",
|
682 |
+
" <td>1</td>\n",
|
683 |
+
" <td>Archive for Danish Literature</td>\n",
|
684 |
+
" <td>adl</td>\n",
|
685 |
+
" <td>Wiki & Books</td>\n",
|
686 |
+
" </tr>\n",
|
687 |
+
" <tr>\n",
|
688 |
+
" <th>51035984</th>\n",
|
689 |
+
" <td>Spejlruder</td>\n",
|
690 |
+
" <td>NOUN</td>\n",
|
691 |
+
" <td>1</td>\n",
|
692 |
+
" <td>Archive for Danish Literature</td>\n",
|
693 |
+
" <td>adl</td>\n",
|
694 |
+
" <td>Wiki & Books</td>\n",
|
695 |
+
" </tr>\n",
|
696 |
+
" <tr>\n",
|
697 |
+
" <th>51035985</th>\n",
|
698 |
+
" <td>Restavrationssalen</td>\n",
|
699 |
+
" <td>PROPN</td>\n",
|
700 |
+
" <td>1</td>\n",
|
701 |
+
" <td>Archive for Danish Literature</td>\n",
|
702 |
+
" <td>adl</td>\n",
|
703 |
+
" <td>Wiki & Books</td>\n",
|
704 |
+
" </tr>\n",
|
705 |
+
" <tr>\n",
|
706 |
+
" <th>51035986</th>\n",
|
707 |
+
" <td>Kølere</td>\n",
|
708 |
+
" <td>NOUN</td>\n",
|
709 |
+
" <td>1</td>\n",
|
710 |
+
" <td>Archive for Danish Literature</td>\n",
|
711 |
+
" <td>adl</td>\n",
|
712 |
+
" <td>Wiki & Books</td>\n",
|
713 |
+
" </tr>\n",
|
714 |
+
" </tbody>\n",
|
715 |
+
"</table>\n",
|
716 |
+
"<p>51035987 rows × 6 columns</p>\n",
|
717 |
+
"</div>"
|
718 |
+
],
|
719 |
+
"text/plain": [
|
720 |
+
" word pos freq domain \\\n",
|
721 |
+
"0 teder NOUN 1 Hestenettet (Danish debate forum) \n",
|
722 |
+
"1 i ADP 81002 Hestenettet (Danish debate forum) \n",
|
723 |
+
"2 i ADV 708 Hestenettet (Danish debate forum) \n",
|
724 |
+
"3 i CCONJ 1 Hestenettet (Danish debate forum) \n",
|
725 |
+
"4 i PRON 5 Hestenettet (Danish debate forum) \n",
|
726 |
+
"... ... ... ... ... \n",
|
727 |
+
"51035982 Leverandører NOUN 1 Archive for Danish Literature \n",
|
728 |
+
"51035983 halvlé NOUN 1 Archive for Danish Literature \n",
|
729 |
+
"51035984 Spejlruder NOUN 1 Archive for Danish Literature \n",
|
730 |
+
"51035985 Restavrationssalen PROPN 1 Archive for Danish Literature \n",
|
731 |
+
"51035986 Kølere NOUN 1 Archive for Danish Literature \n",
|
732 |
+
"\n",
|
733 |
+
" domain_short top_level_domain \n",
|
734 |
+
"0 hest Social Media \n",
|
735 |
+
"1 hest Social Media \n",
|
736 |
+
"2 hest Social Media \n",
|
737 |
+
"3 hest Social Media \n",
|
738 |
+
"4 hest Social Media \n",
|
739 |
+
"... ... ... \n",
|
740 |
+
"51035982 adl Wiki & Books \n",
|
741 |
+
"51035983 adl Wiki & Books \n",
|
742 |
+
"51035984 adl Wiki & Books \n",
|
743 |
+
"51035985 adl Wiki & Books \n",
|
744 |
+
"51035986 adl Wiki & Books \n",
|
745 |
+
"\n",
|
746 |
+
"[51035987 rows x 6 columns]"
|
747 |
+
]
|
748 |
+
},
|
749 |
+
"execution_count": 10,
|
750 |
+
"metadata": {},
|
751 |
+
"output_type": "execute_result"
|
752 |
+
}
|
753 |
+
],
|
754 |
+
"source": [
|
755 |
+
"df"
|
756 |
+
]
|
757 |
+
},
|
758 |
+
{
|
759 |
+
"cell_type": "code",
|
760 |
+
"execution_count": 11,
|
761 |
+
"metadata": {},
|
762 |
+
"outputs": [
|
763 |
+
{
|
764 |
+
"name": "stderr",
|
765 |
+
"output_type": "stream",
|
766 |
+
"text": [
|
767 |
+
"/tmp/ipykernel_38251/3531764134.py:1: FutureWarning: The default value of numeric_only in DataFrameGroupBy.sum is deprecated. In a future version, numeric_only will default to False. Either specify numeric_only or select only columns which should be valid for the function.\n",
|
768 |
+
" df = df.groupby([\"word\"]).sum().reset_index()\n"
|
769 |
+
]
|
770 |
+
}
|
771 |
+
],
|
772 |
+
"source": [
|
773 |
+
"df = df.groupby([\"word\"]).sum().reset_index()\n",
|
774 |
+
"\n",
|
775 |
+
"# recalculate log prob\n",
|
776 |
+
"total_freq = df[\"freq\"].sum()\n",
|
777 |
+
"df[\"log_prob\"] = np.log(df[\"freq\"] / total_freq)\n",
|
778 |
+
"df[\"log_prob_smoothed\"] = np.log((df[\"freq\"] + 1) / (total_freq + len(df)))"
|
779 |
+
]
|
780 |
+
},
|
781 |
+
{
|
782 |
+
"cell_type": "code",
|
783 |
+
"execution_count": 12,
|
784 |
+
"metadata": {},
|
785 |
+
"outputs": [
|
786 |
+
{
|
787 |
+
"data": {
|
788 |
+
"text/html": [
|
789 |
+
"<div>\n",
|
790 |
+
"<style scoped>\n",
|
791 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
792 |
+
" vertical-align: middle;\n",
|
793 |
+
" }\n",
|
794 |
+
"\n",
|
795 |
+
" .dataframe tbody tr th {\n",
|
796 |
+
" vertical-align: top;\n",
|
797 |
+
" }\n",
|
798 |
+
"\n",
|
799 |
+
" .dataframe thead th {\n",
|
800 |
+
" text-align: right;\n",
|
801 |
+
" }\n",
|
802 |
+
"</style>\n",
|
803 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
804 |
+
" <thead>\n",
|
805 |
+
" <tr style=\"text-align: right;\">\n",
|
806 |
+
" <th></th>\n",
|
807 |
+
" <th>word</th>\n",
|
808 |
+
" <th>freq</th>\n",
|
809 |
+
" <th>log_prob</th>\n",
|
810 |
+
" <th>log_prob_smoothed</th>\n",
|
811 |
+
" </tr>\n",
|
812 |
+
" </thead>\n",
|
813 |
+
" <tbody>\n",
|
814 |
+
" <tr>\n",
|
815 |
+
" <th>0</th>\n",
|
816 |
+
" <td>\u0001</td>\n",
|
817 |
+
" <td>11523</td>\n",
|
818 |
+
" <td>-11.557025</td>\n",
|
819 |
+
" <td>-11.566130</td>\n",
|
820 |
+
" </tr>\n",
|
821 |
+
" <tr>\n",
|
822 |
+
" <th>1</th>\n",
|
823 |
+
" <td>\u0001generalforsamling</td>\n",
|
824 |
+
" <td>1</td>\n",
|
825 |
+
" <td>-20.909125</td>\n",
|
826 |
+
" <td>-20.225169</td>\n",
|
827 |
+
" </tr>\n",
|
828 |
+
" <tr>\n",
|
829 |
+
" <th>2</th>\n",
|
830 |
+
" <td>\u0002</td>\n",
|
831 |
+
" <td>25873</td>\n",
|
832 |
+
" <td>-10.748170</td>\n",
|
833 |
+
" <td>-10.757323</td>\n",
|
834 |
+
" </tr>\n",
|
835 |
+
" <tr>\n",
|
836 |
+
" <th>3</th>\n",
|
837 |
+
" <td>\u0003</td>\n",
|
838 |
+
" <td>32510</td>\n",
|
839 |
+
" <td>-10.519822</td>\n",
|
840 |
+
" <td>-10.528983</td>\n",
|
841 |
+
" </tr>\n",
|
842 |
+
" <tr>\n",
|
843 |
+
" <th>4</th>\n",
|
844 |
+
" <td>\u0003\u0003</td>\n",
|
845 |
+
" <td>7</td>\n",
|
846 |
+
" <td>-18.963215</td>\n",
|
847 |
+
" <td>-18.838875</td>\n",
|
848 |
+
" </tr>\n",
|
849 |
+
" <tr>\n",
|
850 |
+
" <th>...</th>\n",
|
851 |
+
" <td>...</td>\n",
|
852 |
+
" <td>...</td>\n",
|
853 |
+
" <td>...</td>\n",
|
854 |
+
" <td>...</td>\n",
|
855 |
+
" </tr>\n",
|
856 |
+
" <tr>\n",
|
857 |
+
" <th>11120014</th>\n",
|
858 |
+
" <td>Passer</td>\n",
|
859 |
+
" <td>3</td>\n",
|
860 |
+
" <td>-19.810513</td>\n",
|
861 |
+
" <td>-19.532022</td>\n",
|
862 |
+
" </tr>\n",
|
863 |
+
" <tr>\n",
|
864 |
+
" <th>11120015</th>\n",
|
865 |
+
" <td>Rygning</td>\n",
|
866 |
+
" <td>10</td>\n",
|
867 |
+
" <td>-18.606540</td>\n",
|
868 |
+
" <td>-18.520421</td>\n",
|
869 |
+
" </tr>\n",
|
870 |
+
" <tr>\n",
|
871 |
+
" <th>11120016</th>\n",
|
872 |
+
" <td></td>\n",
|
873 |
+
" <td>1</td>\n",
|
874 |
+
" <td>-20.909125</td>\n",
|
875 |
+
" <td>-20.225169</td>\n",
|
876 |
+
" </tr>\n",
|
877 |
+
" <tr>\n",
|
878 |
+
" <th>11120017</th>\n",
|
879 |
+
" <td></td>\n",
|
880 |
+
" <td>24</td>\n",
|
881 |
+
" <td>-17.731071</td>\n",
|
882 |
+
" <td>-17.699441</td>\n",
|
883 |
+
" </tr>\n",
|
884 |
+
" <tr>\n",
|
885 |
+
" <th>11120018</th>\n",
|
886 |
+
" <td></td>\n",
|
887 |
+
" <td>3</td>\n",
|
888 |
+
" <td>-19.810513</td>\n",
|
889 |
+
" <td>-19.532022</td>\n",
|
890 |
+
" </tr>\n",
|
891 |
+
" </tbody>\n",
|
892 |
+
"</table>\n",
|
893 |
+
"<p>11120019 rows × 4 columns</p>\n",
|
894 |
+
"</div>"
|
895 |
+
],
|
896 |
+
"text/plain": [
|
897 |
+
" word freq log_prob log_prob_smoothed\n",
|
898 |
+
"0 \u0001 11523 -11.557025 -11.566130\n",
|
899 |
+
"1 \u0001generalforsamling 1 -20.909125 -20.225169\n",
|
900 |
+
"2 \u0002 25873 -10.748170 -10.757323\n",
|
901 |
+
"3 \u0003 32510 -10.519822 -10.528983\n",
|
902 |
+
"4 \u0003\u0003 7 -18.963215 -18.838875\n",
|
903 |
+
"... ... ... ... ...\n",
|
904 |
+
"11120014 Passer 3 -19.810513 -19.532022\n",
|
905 |
+
"11120015 Rygning 10 -18.606540 -18.520421\n",
|
906 |
+
"11120016 1 -20.909125 -20.225169\n",
|
907 |
+
"11120017 24 -17.731071 -17.699441\n",
|
908 |
+
"11120018 3 -19.810513 -19.532022\n",
|
909 |
+
"\n",
|
910 |
+
"[11120019 rows x 4 columns]"
|
911 |
+
]
|
912 |
+
},
|
913 |
+
"execution_count": 12,
|
914 |
+
"metadata": {},
|
915 |
+
"output_type": "execute_result"
|
916 |
+
}
|
917 |
+
],
|
918 |
+
"source": [
|
919 |
+
"df # inspect"
|
920 |
+
]
|
921 |
+
},
|
922 |
+
{
|
923 |
+
"cell_type": "code",
|
924 |
+
"execution_count": 15,
|
925 |
+
"metadata": {},
|
926 |
+
"outputs": [
|
927 |
+
{
|
928 |
+
"name": "stderr",
|
929 |
+
"output_type": "stream",
|
930 |
+
"text": [
|
931 |
+
"Using custom data configuration default-db8b733866850efe\n",
|
932 |
+
"/home/kenneth/.Envs/word_freq/lib/python3.8/site-packages/datasets/builder.py:712: FutureWarning: 'use_auth_token' was deprecated in version 2.7.1 and will be removed in 3.0.0. Pass `use_auth_token` to the initializer/`load_dataset_builder` instead.\n",
|
933 |
+
" warnings.warn(\n"
|
934 |
+
]
|
935 |
+
},
|
936 |
+
{
|
937 |
+
"name": "stdout",
|
938 |
+
"output_type": "stream",
|
939 |
+
"text": [
|
940 |
+
"Downloading and preparing dataset csv/default to /home/kenneth/.cache/huggingface/datasets/csv/default-db8b733866850efe/0.0.0...\n"
|
941 |
+
]
|
942 |
+
},
|
943 |
+
{
|
944 |
+
"name": "stderr",
|
945 |
+
"output_type": "stream",
|
946 |
+
"text": [
|
947 |
+
"Downloading data files: 100%|██████████| 1/1 [00:00<00:00, 1030.29it/s]\n",
|
948 |
+
"Extracting data files: 100%|██████████| 1/1 [00:00<00:00, 839.70it/s]\n",
|
949 |
+
"Generating train split: 0 examples [00:00, ? examples/s]/home/kenneth/.Envs/word_freq/lib/python3.8/site-packages/datasets/download/streaming_download_manager.py:727: FutureWarning: the 'mangle_dupe_cols' keyword is deprecated and will be removed in a future version. Please take steps to stop the use of 'mangle_dupe_cols'\n",
|
950 |
+
" return pd.read_csv(xopen(filepath_or_buffer, \"rb\", use_auth_token=use_auth_token), **kwargs)\n",
|
951 |
+
" \r"
|
952 |
+
]
|
953 |
+
},
|
954 |
+
{
|
955 |
+
"name": "stdout",
|
956 |
+
"output_type": "stream",
|
957 |
+
"text": [
|
958 |
+
"Dataset csv downloaded and prepared to /home/kenneth/.cache/huggingface/datasets/csv/default-db8b733866850efe/0.0.0. Subsequent calls will reuse this data.\n"
|
959 |
+
]
|
960 |
+
}
|
961 |
+
],
|
962 |
+
"source": [
|
963 |
+
"# save to csv\n",
|
964 |
+
"df.to_csv(\"danish_word_freqs.csv\", index=False)\n",
|
965 |
+
"\n",
|
966 |
+
"# load using huggingface datasets\n",
|
967 |
+
"word_frequencies = Dataset.from_csv(\"danish_word_freqs.csv\")"
|
968 |
+
]
|
969 |
+
},
|
970 |
+
{
|
971 |
+
"attachments": {},
|
972 |
+
"cell_type": "markdown",
|
973 |
+
"metadata": {},
|
974 |
+
"source": [
|
975 |
+
"### Create the by_domain dataset\n"
|
976 |
+
]
|
977 |
+
},
|
978 |
+
{
|
979 |
+
"cell_type": "code",
|
980 |
+
"execution_count": 49,
|
981 |
+
"metadata": {},
|
982 |
+
"outputs": [],
|
983 |
+
"source": [
|
984 |
+
"df = dataset.to_pandas()"
|
985 |
+
]
|
986 |
+
},
|
987 |
+
{
|
988 |
+
"cell_type": "code",
|
989 |
+
"execution_count": 50,
|
990 |
+
"metadata": {},
|
991 |
+
"outputs": [
|
992 |
+
{
|
993 |
+
"data": {
|
994 |
+
"text/html": [
|
995 |
+
"<div>\n",
|
996 |
+
"<style scoped>\n",
|
997 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
998 |
+
" vertical-align: middle;\n",
|
999 |
+
" }\n",
|
1000 |
+
"\n",
|
1001 |
+
" .dataframe tbody tr th {\n",
|
1002 |
+
" vertical-align: top;\n",
|
1003 |
+
" }\n",
|
1004 |
+
"\n",
|
1005 |
+
" .dataframe thead th {\n",
|
1006 |
+
" text-align: right;\n",
|
1007 |
+
" }\n",
|
1008 |
+
"</style>\n",
|
1009 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
1010 |
+
" <thead>\n",
|
1011 |
+
" <tr style=\"text-align: right;\">\n",
|
1012 |
+
" <th></th>\n",
|
1013 |
+
" <th>word</th>\n",
|
1014 |
+
" <th>pos</th>\n",
|
1015 |
+
" <th>freq</th>\n",
|
1016 |
+
" <th>domain</th>\n",
|
1017 |
+
" <th>domain_short</th>\n",
|
1018 |
+
" <th>top_level_domain</th>\n",
|
1019 |
+
" </tr>\n",
|
1020 |
+
" </thead>\n",
|
1021 |
+
" <tbody>\n",
|
1022 |
+
" <tr>\n",
|
1023 |
+
" <th>0</th>\n",
|
1024 |
+
" <td>teder</td>\n",
|
1025 |
+
" <td>NOUN</td>\n",
|
1026 |
+
" <td>1</td>\n",
|
1027 |
+
" <td>Hestenettet (Danish debate forum)</td>\n",
|
1028 |
+
" <td>hest</td>\n",
|
1029 |
+
" <td>Social Media</td>\n",
|
1030 |
+
" </tr>\n",
|
1031 |
+
" <tr>\n",
|
1032 |
+
" <th>1</th>\n",
|
1033 |
+
" <td>i</td>\n",
|
1034 |
+
" <td>ADP</td>\n",
|
1035 |
+
" <td>81002</td>\n",
|
1036 |
+
" <td>Hestenettet (Danish debate forum)</td>\n",
|
1037 |
+
" <td>hest</td>\n",
|
1038 |
+
" <td>Social Media</td>\n",
|
1039 |
+
" </tr>\n",
|
1040 |
+
" <tr>\n",
|
1041 |
+
" <th>2</th>\n",
|
1042 |
+
" <td>i</td>\n",
|
1043 |
+
" <td>ADV</td>\n",
|
1044 |
+
" <td>708</td>\n",
|
1045 |
+
" <td>Hestenettet (Danish debate forum)</td>\n",
|
1046 |
+
" <td>hest</td>\n",
|
1047 |
+
" <td>Social Media</td>\n",
|
1048 |
+
" </tr>\n",
|
1049 |
+
" <tr>\n",
|
1050 |
+
" <th>3</th>\n",
|
1051 |
+
" <td>i</td>\n",
|
1052 |
+
" <td>CCONJ</td>\n",
|
1053 |
+
" <td>1</td>\n",
|
1054 |
+
" <td>Hestenettet (Danish debate forum)</td>\n",
|
1055 |
+
" <td>hest</td>\n",
|
1056 |
+
" <td>Social Media</td>\n",
|
1057 |
+
" </tr>\n",
|
1058 |
+
" <tr>\n",
|
1059 |
+
" <th>4</th>\n",
|
1060 |
+
" <td>i</td>\n",
|
1061 |
+
" <td>PRON</td>\n",
|
1062 |
+
" <td>5</td>\n",
|
1063 |
+
" <td>Hestenettet (Danish debate forum)</td>\n",
|
1064 |
+
" <td>hest</td>\n",
|
1065 |
+
" <td>Social Media</td>\n",
|
1066 |
+
" </tr>\n",
|
1067 |
+
" <tr>\n",
|
1068 |
+
" <th>...</th>\n",
|
1069 |
+
" <td>...</td>\n",
|
1070 |
+
" <td>...</td>\n",
|
1071 |
+
" <td>...</td>\n",
|
1072 |
+
" <td>...</td>\n",
|
1073 |
+
" <td>...</td>\n",
|
1074 |
+
" <td>...</td>\n",
|
1075 |
+
" </tr>\n",
|
1076 |
+
" <tr>\n",
|
1077 |
+
" <th>51035982</th>\n",
|
1078 |
+
" <td>Leverandører</td>\n",
|
1079 |
+
" <td>NOUN</td>\n",
|
1080 |
+
" <td>1</td>\n",
|
1081 |
+
" <td>Archive for Danish Literature</td>\n",
|
1082 |
+
" <td>adl</td>\n",
|
1083 |
+
" <td>Wiki & Books</td>\n",
|
1084 |
+
" </tr>\n",
|
1085 |
+
" <tr>\n",
|
1086 |
+
" <th>51035983</th>\n",
|
1087 |
+
" <td>halvlé</td>\n",
|
1088 |
+
" <td>NOUN</td>\n",
|
1089 |
+
" <td>1</td>\n",
|
1090 |
+
" <td>Archive for Danish Literature</td>\n",
|
1091 |
+
" <td>adl</td>\n",
|
1092 |
+
" <td>Wiki & Books</td>\n",
|
1093 |
+
" </tr>\n",
|
1094 |
+
" <tr>\n",
|
1095 |
+
" <th>51035984</th>\n",
|
1096 |
+
" <td>Spejlruder</td>\n",
|
1097 |
+
" <td>NOUN</td>\n",
|
1098 |
+
" <td>1</td>\n",
|
1099 |
+
" <td>Archive for Danish Literature</td>\n",
|
1100 |
+
" <td>adl</td>\n",
|
1101 |
+
" <td>Wiki & Books</td>\n",
|
1102 |
+
" </tr>\n",
|
1103 |
+
" <tr>\n",
|
1104 |
+
" <th>51035985</th>\n",
|
1105 |
+
" <td>Restavrationssalen</td>\n",
|
1106 |
+
" <td>PROPN</td>\n",
|
1107 |
+
" <td>1</td>\n",
|
1108 |
+
" <td>Archive for Danish Literature</td>\n",
|
1109 |
+
" <td>adl</td>\n",
|
1110 |
+
" <td>Wiki & Books</td>\n",
|
1111 |
+
" </tr>\n",
|
1112 |
+
" <tr>\n",
|
1113 |
+
" <th>51035986</th>\n",
|
1114 |
+
" <td>Kølere</td>\n",
|
1115 |
+
" <td>NOUN</td>\n",
|
1116 |
+
" <td>1</td>\n",
|
1117 |
+
" <td>Archive for Danish Literature</td>\n",
|
1118 |
+
" <td>adl</td>\n",
|
1119 |
+
" <td>Wiki & Books</td>\n",
|
1120 |
+
" </tr>\n",
|
1121 |
+
" </tbody>\n",
|
1122 |
+
"</table>\n",
|
1123 |
+
"<p>51035987 rows × 6 columns</p>\n",
|
1124 |
+
"</div>"
|
1125 |
+
],
|
1126 |
+
"text/plain": [
|
1127 |
+
" word pos freq domain \\\n",
|
1128 |
+
"0 teder NOUN 1 Hestenettet (Danish debate forum) \n",
|
1129 |
+
"1 i ADP 81002 Hestenettet (Danish debate forum) \n",
|
1130 |
+
"2 i ADV 708 Hestenettet (Danish debate forum) \n",
|
1131 |
+
"3 i CCONJ 1 Hestenettet (Danish debate forum) \n",
|
1132 |
+
"4 i PRON 5 Hestenettet (Danish debate forum) \n",
|
1133 |
+
"... ... ... ... ... \n",
|
1134 |
+
"51035982 Leverandører NOUN 1 Archive for Danish Literature \n",
|
1135 |
+
"51035983 halvlé NOUN 1 Archive for Danish Literature \n",
|
1136 |
+
"51035984 Spejlruder NOUN 1 Archive for Danish Literature \n",
|
1137 |
+
"51035985 Restavrationssalen PROPN 1 Archive for Danish Literature \n",
|
1138 |
+
"51035986 Kølere NOUN 1 Archive for Danish Literature \n",
|
1139 |
+
"\n",
|
1140 |
+
" domain_short top_level_domain \n",
|
1141 |
+
"0 hest Social Media \n",
|
1142 |
+
"1 hest Social Media \n",
|
1143 |
+
"2 hest Social Media \n",
|
1144 |
+
"3 hest Social Media \n",
|
1145 |
+
"4 hest Social Media \n",
|
1146 |
+
"... ... ... \n",
|
1147 |
+
"51035982 adl Wiki & Books \n",
|
1148 |
+
"51035983 adl Wiki & Books \n",
|
1149 |
+
"51035984 adl Wiki & Books \n",
|
1150 |
+
"51035985 adl Wiki & Books \n",
|
1151 |
+
"51035986 adl Wiki & Books \n",
|
1152 |
+
"\n",
|
1153 |
+
"[51035987 rows x 6 columns]"
|
1154 |
+
]
|
1155 |
+
},
|
1156 |
+
"execution_count": 50,
|
1157 |
+
"metadata": {},
|
1158 |
+
"output_type": "execute_result"
|
1159 |
+
}
|
1160 |
+
],
|
1161 |
+
"source": [
|
1162 |
+
"df"
|
1163 |
+
]
|
1164 |
+
},
|
1165 |
+
{
|
1166 |
+
"cell_type": "code",
|
1167 |
+
"execution_count": 51,
|
1168 |
+
"metadata": {},
|
1169 |
+
"outputs": [
|
1170 |
+
{
|
1171 |
+
"name": "stderr",
|
1172 |
+
"output_type": "stream",
|
1173 |
+
"text": [
|
1174 |
+
"/tmp/ipykernel_38251/2877160612.py:4: FutureWarning: The default value of numeric_only in DataFrameGroupBy.sum is deprecated. In a future version, numeric_only will default to False. Either specify numeric_only or select only columns which should be valid for the function.\n",
|
1175 |
+
" df = df.groupby([\"word\", \"domain\", \"domain_short\"]).sum().reset_index()\n"
|
1176 |
+
]
|
1177 |
+
},
|
1178 |
+
{
|
1179 |
+
"name": "stdout",
|
1180 |
+
"output_type": "stream",
|
1181 |
+
"text": [
|
1182 |
+
"dannet\n",
|
1183 |
+
"adl\n",
|
1184 |
+
"hest\n",
|
1185 |
+
"wiki\n",
|
1186 |
+
"relig\n",
|
1187 |
+
"botxt\n",
|
1188 |
+
"synne\n",
|
1189 |
+
"depbank\n",
|
1190 |
+
"cc\n",
|
1191 |
+
"tv2r\n",
|
1192 |
+
"opensub\n",
|
1193 |
+
"twfv19\n",
|
1194 |
+
"retsinformationdk\n",
|
1195 |
+
"wikibooks\n",
|
1196 |
+
"jvj\n",
|
1197 |
+
"ft\n",
|
1198 |
+
"gutenberg\n",
|
1199 |
+
"retspraksis\n",
|
1200 |
+
"ep\n",
|
1201 |
+
"skat\n",
|
1202 |
+
"spont\n",
|
1203 |
+
"wikisource\n",
|
1204 |
+
"naat\n"
|
1205 |
+
]
|
1206 |
+
}
|
1207 |
+
],
|
1208 |
+
"source": [
|
1209 |
+
"# hide pandas warnings\n",
|
1210 |
+
"pd.options.mode.chained_assignment = None\n",
|
1211 |
+
"\n",
|
1212 |
+
"df = df.groupby([\"word\", \"domain\", \"domain_short\"]).sum().reset_index()\n",
|
1213 |
+
"\n",
|
1214 |
+
"# recalculate log prob\n",
|
1215 |
+
"def calc_log_prob_pr_domain(df, domains):\n",
|
1216 |
+
" dfs = []\n",
|
1217 |
+
" for domain in domains:\n",
|
1218 |
+
" print(domain)\n",
|
1219 |
+
" df_domains = df.loc[df[\"domain_short\"] == domain]\n",
|
1220 |
+
" total_freq = df_domains[\"freq\"].sum()\n",
|
1221 |
+
" df_domains[\"log_prob\"] = np.log(df_domains[\"freq\"] / total_freq)\n",
|
1222 |
+
" df_domains[\"log_prob_smoothed\"] = np.log((df_domains[\"freq\"] + 1) / (total_freq + len(df_domains)))\n",
|
1223 |
+
" dfs.append(df_domains)\n",
|
1224 |
+
" \n",
|
1225 |
+
" return pd.concat(dfs)\n",
|
1226 |
+
"\n",
|
1227 |
+
"df = calc_log_prob_pr_domain(df, domains)"
|
1228 |
+
]
|
1229 |
+
},
|
1230 |
+
{
|
1231 |
+
"cell_type": "code",
|
1232 |
+
"execution_count": 52,
|
1233 |
+
"metadata": {},
|
1234 |
+
"outputs": [
|
1235 |
+
{
|
1236 |
+
"data": {
|
1237 |
+
"text/html": [
|
1238 |
+
"<div>\n",
|
1239 |
+
"<style scoped>\n",
|
1240 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
1241 |
+
" vertical-align: middle;\n",
|
1242 |
+
" }\n",
|
1243 |
+
"\n",
|
1244 |
+
" .dataframe tbody tr th {\n",
|
1245 |
+
" vertical-align: top;\n",
|
1246 |
+
" }\n",
|
1247 |
+
"\n",
|
1248 |
+
" .dataframe thead th {\n",
|
1249 |
+
" text-align: right;\n",
|
1250 |
+
" }\n",
|
1251 |
+
"</style>\n",
|
1252 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
1253 |
+
" <thead>\n",
|
1254 |
+
" <tr style=\"text-align: right;\">\n",
|
1255 |
+
" <th></th>\n",
|
1256 |
+
" <th>word</th>\n",
|
1257 |
+
" <th>domain</th>\n",
|
1258 |
+
" <th>domain_short</th>\n",
|
1259 |
+
" <th>freq</th>\n",
|
1260 |
+
" <th>log_prob</th>\n",
|
1261 |
+
" <th>log_prob_smoothed</th>\n",
|
1262 |
+
" </tr>\n",
|
1263 |
+
" </thead>\n",
|
1264 |
+
" <tbody>\n",
|
1265 |
+
" <tr>\n",
|
1266 |
+
" <th>4486</th>\n",
|
1267 |
+
" <td></td>\n",
|
1268 |
+
" <td>DanNet (Danish WordNet)</td>\n",
|
1269 |
+
" <td>dannet</td>\n",
|
1270 |
+
" <td>38</td>\n",
|
1271 |
+
" <td>-9.948003</td>\n",
|
1272 |
+
" <td>-10.034464</td>\n",
|
1273 |
+
" </tr>\n",
|
1274 |
+
" <tr>\n",
|
1275 |
+
" <th>14344</th>\n",
|
1276 |
+
" <td>!</td>\n",
|
1277 |
+
" <td>DanNet (Danish WordNet)</td>\n",
|
1278 |
+
" <td>dannet</td>\n",
|
1279 |
+
" <td>686</td>\n",
|
1280 |
+
" <td>-7.054711</td>\n",
|
1281 |
+
" <td>-7.165691</td>\n",
|
1282 |
+
" </tr>\n",
|
1283 |
+
" <tr>\n",
|
1284 |
+
" <th>15182</th>\n",
|
1285 |
+
" <td>$</td>\n",
|
1286 |
+
" <td>DanNet (Danish WordNet)</td>\n",
|
1287 |
+
" <td>dannet</td>\n",
|
1288 |
+
" <td>2</td>\n",
|
1289 |
+
" <td>-12.892442</td>\n",
|
1290 |
+
" <td>-12.599413</td>\n",
|
1291 |
+
" </tr>\n",
|
1292 |
+
" <tr>\n",
|
1293 |
+
" <th>15231</th>\n",
|
1294 |
+
" <td>%</td>\n",
|
1295 |
+
" <td>DanNet (Danish WordNet)</td>\n",
|
1296 |
+
" <td>dannet</td>\n",
|
1297 |
+
" <td>104</td>\n",
|
1298 |
+
" <td>-8.941198</td>\n",
|
1299 |
+
" <td>-9.044065</td>\n",
|
1300 |
+
" </tr>\n",
|
1301 |
+
" <tr>\n",
|
1302 |
+
" <th>15272</th>\n",
|
1303 |
+
" <td>&</td>\n",
|
1304 |
+
" <td>DanNet (Danish WordNet)</td>\n",
|
1305 |
+
" <td>dannet</td>\n",
|
1306 |
+
" <td>49</td>\n",
|
1307 |
+
" <td>-9.693769</td>\n",
|
1308 |
+
" <td>-9.786003</td>\n",
|
1309 |
+
" </tr>\n",
|
1310 |
+
" <tr>\n",
|
1311 |
+
" <th>...</th>\n",
|
1312 |
+
" <td>...</td>\n",
|
1313 |
+
" <td>...</td>\n",
|
1314 |
+
" <td>...</td>\n",
|
1315 |
+
" <td>...</td>\n",
|
1316 |
+
" <td>...</td>\n",
|
1317 |
+
" <td>...</td>\n",
|
1318 |
+
" </tr>\n",
|
1319 |
+
" <tr>\n",
|
1320 |
+
" <th>15308188</th>\n",
|
1321 |
+
" <td>’</td>\n",
|
1322 |
+
" <td>NAAT</td>\n",
|
1323 |
+
" <td>naat</td>\n",
|
1324 |
+
" <td>123</td>\n",
|
1325 |
+
" <td>-7.307371</td>\n",
|
1326 |
+
" <td>-7.369814</td>\n",
|
1327 |
+
" </tr>\n",
|
1328 |
+
" <tr>\n",
|
1329 |
+
" <th>15309280</th>\n",
|
1330 |
+
" <td>“</td>\n",
|
1331 |
+
" <td>NAAT</td>\n",
|
1332 |
+
" <td>naat</td>\n",
|
1333 |
+
" <td>47</td>\n",
|
1334 |
+
" <td>-8.269408</td>\n",
|
1335 |
+
" <td>-8.318895</td>\n",
|
1336 |
+
" </tr>\n",
|
1337 |
+
" <tr>\n",
|
1338 |
+
" <th>15309314</th>\n",
|
1339 |
+
" <td>”</td>\n",
|
1340 |
+
" <td>NAAT</td>\n",
|
1341 |
+
" <td>naat</td>\n",
|
1342 |
+
" <td>139</td>\n",
|
1343 |
+
" <td>-7.185082</td>\n",
|
1344 |
+
" <td>-7.248453</td>\n",
|
1345 |
+
" </tr>\n",
|
1346 |
+
" <tr>\n",
|
1347 |
+
" <th>15309694</th>\n",
|
1348 |
+
" <td>•</td>\n",
|
1349 |
+
" <td>NAAT</td>\n",
|
1350 |
+
" <td>naat</td>\n",
|
1351 |
+
" <td>5</td>\n",
|
1352 |
+
" <td>-10.510118</td>\n",
|
1353 |
+
" <td>-10.398336</td>\n",
|
1354 |
+
" </tr>\n",
|
1355 |
+
" <tr>\n",
|
1356 |
+
" <th>15310402</th>\n",
|
1357 |
+
" <td>…</td>\n",
|
1358 |
+
" <td>NAAT</td>\n",
|
1359 |
+
" <td>naat</td>\n",
|
1360 |
+
" <td>11</td>\n",
|
1361 |
+
" <td>-9.721660</td>\n",
|
1362 |
+
" <td>-9.705189</td>\n",
|
1363 |
+
" </tr>\n",
|
1364 |
+
" </tbody>\n",
|
1365 |
+
"</table>\n",
|
1366 |
+
"<p>15326084 rows × 6 columns</p>\n",
|
1367 |
+
"</div>"
|
1368 |
+
],
|
1369 |
+
"text/plain": [
|
1370 |
+
" word domain domain_short freq log_prob \\\n",
|
1371 |
+
"4486 DanNet (Danish WordNet) dannet 38 -9.948003 \n",
|
1372 |
+
"14344 ! DanNet (Danish WordNet) dannet 686 -7.054711 \n",
|
1373 |
+
"15182 $ DanNet (Danish WordNet) dannet 2 -12.892442 \n",
|
1374 |
+
"15231 % DanNet (Danish WordNet) dannet 104 -8.941198 \n",
|
1375 |
+
"15272 & DanNet (Danish WordNet) dannet 49 -9.693769 \n",
|
1376 |
+
"... ... ... ... ... ... \n",
|
1377 |
+
"15308188 ’ NAAT naat 123 -7.307371 \n",
|
1378 |
+
"15309280 “ NAAT naat 47 -8.269408 \n",
|
1379 |
+
"15309314 ” NAAT naat 139 -7.185082 \n",
|
1380 |
+
"15309694 • NAAT naat 5 -10.510118 \n",
|
1381 |
+
"15310402 … NAAT naat 11 -9.721660 \n",
|
1382 |
+
"\n",
|
1383 |
+
" log_prob_smoothed \n",
|
1384 |
+
"4486 -10.034464 \n",
|
1385 |
+
"14344 -7.165691 \n",
|
1386 |
+
"15182 -12.599413 \n",
|
1387 |
+
"15231 -9.044065 \n",
|
1388 |
+
"15272 -9.786003 \n",
|
1389 |
+
"... ... \n",
|
1390 |
+
"15308188 -7.369814 \n",
|
1391 |
+
"15309280 -8.318895 \n",
|
1392 |
+
"15309314 -7.248453 \n",
|
1393 |
+
"15309694 -10.398336 \n",
|
1394 |
+
"15310402 -9.705189 \n",
|
1395 |
+
"\n",
|
1396 |
+
"[15326084 rows x 6 columns]"
|
1397 |
+
]
|
1398 |
+
},
|
1399 |
+
"execution_count": 52,
|
1400 |
+
"metadata": {},
|
1401 |
+
"output_type": "execute_result"
|
1402 |
+
}
|
1403 |
+
],
|
1404 |
+
"source": [
|
1405 |
+
"df"
|
1406 |
+
]
|
1407 |
+
},
|
1408 |
+
{
|
1409 |
+
"cell_type": "code",
|
1410 |
+
"execution_count": 55,
|
1411 |
+
"metadata": {},
|
1412 |
+
"outputs": [
|
1413 |
+
{
|
1414 |
+
"name": "stderr",
|
1415 |
+
"output_type": "stream",
|
1416 |
+
"text": [
|
1417 |
+
"Using custom data configuration default-bcdefdf7aa1acd36\n",
|
1418 |
+
"/home/kenneth/.Envs/word_freq/lib/python3.8/site-packages/datasets/builder.py:712: FutureWarning: 'use_auth_token' was deprecated in version 2.7.1 and will be removed in 3.0.0. Pass `use_auth_token` to the initializer/`load_dataset_builder` instead.\n",
|
1419 |
+
" warnings.warn(\n"
|
1420 |
+
]
|
1421 |
+
},
|
1422 |
+
{
|
1423 |
+
"name": "stdout",
|
1424 |
+
"output_type": "stream",
|
1425 |
+
"text": [
|
1426 |
+
"Downloading and preparing dataset csv/default to /home/kenneth/.cache/huggingface/datasets/csv/default-bcdefdf7aa1acd36/0.0.0...\n"
|
1427 |
+
]
|
1428 |
+
},
|
1429 |
+
{
|
1430 |
+
"name": "stderr",
|
1431 |
+
"output_type": "stream",
|
1432 |
+
"text": [
|
1433 |
+
"Downloading data files: 100%|██████████| 1/1 [00:00<00:00, 1062.39it/s]\n",
|
1434 |
+
"Extracting data files: 100%|██████████| 1/1 [00:00<00:00, 565.04it/s]\n",
|
1435 |
+
"Generating train split: 0 examples [00:00, ? examples/s]/home/kenneth/.Envs/word_freq/lib/python3.8/site-packages/datasets/download/streaming_download_manager.py:727: FutureWarning: the 'mangle_dupe_cols' keyword is deprecated and will be removed in a future version. Please take steps to stop the use of 'mangle_dupe_cols'\n",
|
1436 |
+
" return pd.read_csv(xopen(filepath_or_buffer, \"rb\", use_auth_token=use_auth_token), **kwargs)\n",
|
1437 |
+
" \r"
|
1438 |
+
]
|
1439 |
+
},
|
1440 |
+
{
|
1441 |
+
"name": "stdout",
|
1442 |
+
"output_type": "stream",
|
1443 |
+
"text": [
|
1444 |
+
"Dataset csv downloaded and prepared to /home/kenneth/.cache/huggingface/datasets/csv/default-bcdefdf7aa1acd36/0.0.0. Subsequent calls will reuse this data.\n"
|
1445 |
+
]
|
1446 |
+
}
|
1447 |
+
],
|
1448 |
+
"source": [
|
1449 |
+
"# save to csv\n",
|
1450 |
+
"df.to_csv(\"danish_word_freqs_by_domain.csv\", index=False)\n",
|
1451 |
+
"\n",
|
1452 |
+
"# load using huggingface datasets\n",
|
1453 |
+
"by_domain = Dataset.from_csv(\"danish_word_freqs_by_domain.csv\")"
|
1454 |
+
]
|
1455 |
+
},
|
1456 |
+
{
|
1457 |
+
"attachments": {},
|
1458 |
+
"cell_type": "markdown",
|
1459 |
+
"metadata": {},
|
1460 |
+
"source": [
|
1461 |
+
"### Create the with_pos dataset"
|
1462 |
+
]
|
1463 |
+
},
|
1464 |
+
{
|
1465 |
+
"cell_type": "code",
|
1466 |
+
"execution_count": 56,
|
1467 |
+
"metadata": {},
|
1468 |
+
"outputs": [
|
1469 |
+
{
|
1470 |
+
"name": "stderr",
|
1471 |
+
"output_type": "stream",
|
1472 |
+
"text": [
|
1473 |
+
"/tmp/ipykernel_38251/2868179020.py:2: FutureWarning: The default value of numeric_only in DataFrameGroupBy.sum is deprecated. In a future version, numeric_only will default to False. Either specify numeric_only or select only columns which should be valid for the function.\n",
|
1474 |
+
" df = df.groupby([\"word\", \"domain\", \"domain_short\"]).sum().reset_index()\n"
|
1475 |
+
]
|
1476 |
+
},
|
1477 |
+
{
|
1478 |
+
"name": "stdout",
|
1479 |
+
"output_type": "stream",
|
1480 |
+
"text": [
|
1481 |
+
"dannet\n",
|
1482 |
+
"adl\n",
|
1483 |
+
"hest\n",
|
1484 |
+
"wiki\n",
|
1485 |
+
"relig\n",
|
1486 |
+
"botxt\n",
|
1487 |
+
"synne\n",
|
1488 |
+
"depbank\n",
|
1489 |
+
"cc\n",
|
1490 |
+
"tv2r\n",
|
1491 |
+
"opensub\n",
|
1492 |
+
"twfv19\n",
|
1493 |
+
"retsinformationdk\n",
|
1494 |
+
"wikibooks\n",
|
1495 |
+
"jvj\n",
|
1496 |
+
"ft\n",
|
1497 |
+
"gutenberg\n",
|
1498 |
+
"retspraksis\n",
|
1499 |
+
"ep\n",
|
1500 |
+
"skat\n",
|
1501 |
+
"spont\n",
|
1502 |
+
"wikisource\n",
|
1503 |
+
"naat\n"
|
1504 |
+
]
|
1505 |
+
},
|
1506 |
+
{
|
1507 |
+
"data": {
|
1508 |
+
"text/html": [
|
1509 |
+
"<div>\n",
|
1510 |
+
"<style scoped>\n",
|
1511 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
1512 |
+
" vertical-align: middle;\n",
|
1513 |
+
" }\n",
|
1514 |
+
"\n",
|
1515 |
+
" .dataframe tbody tr th {\n",
|
1516 |
+
" vertical-align: top;\n",
|
1517 |
+
" }\n",
|
1518 |
+
"\n",
|
1519 |
+
" .dataframe thead th {\n",
|
1520 |
+
" text-align: right;\n",
|
1521 |
+
" }\n",
|
1522 |
+
"</style>\n",
|
1523 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
1524 |
+
" <thead>\n",
|
1525 |
+
" <tr style=\"text-align: right;\">\n",
|
1526 |
+
" <th></th>\n",
|
1527 |
+
" <th>word</th>\n",
|
1528 |
+
" <th>domain</th>\n",
|
1529 |
+
" <th>domain_short</th>\n",
|
1530 |
+
" <th>freq</th>\n",
|
1531 |
+
" <th>log_prob</th>\n",
|
1532 |
+
" <th>log_prob_smoothed</th>\n",
|
1533 |
+
" </tr>\n",
|
1534 |
+
" </thead>\n",
|
1535 |
+
" <tbody>\n",
|
1536 |
+
" <tr>\n",
|
1537 |
+
" <th>4486</th>\n",
|
1538 |
+
" <td></td>\n",
|
1539 |
+
" <td>DanNet (Danish WordNet)</td>\n",
|
1540 |
+
" <td>dannet</td>\n",
|
1541 |
+
" <td>38</td>\n",
|
1542 |
+
" <td>-9.948003</td>\n",
|
1543 |
+
" <td>-10.034464</td>\n",
|
1544 |
+
" </tr>\n",
|
1545 |
+
" <tr>\n",
|
1546 |
+
" <th>14344</th>\n",
|
1547 |
+
" <td>!</td>\n",
|
1548 |
+
" <td>DanNet (Danish WordNet)</td>\n",
|
1549 |
+
" <td>dannet</td>\n",
|
1550 |
+
" <td>686</td>\n",
|
1551 |
+
" <td>-7.054711</td>\n",
|
1552 |
+
" <td>-7.165691</td>\n",
|
1553 |
+
" </tr>\n",
|
1554 |
+
" <tr>\n",
|
1555 |
+
" <th>15182</th>\n",
|
1556 |
+
" <td>$</td>\n",
|
1557 |
+
" <td>DanNet (Danish WordNet)</td>\n",
|
1558 |
+
" <td>dannet</td>\n",
|
1559 |
+
" <td>2</td>\n",
|
1560 |
+
" <td>-12.892442</td>\n",
|
1561 |
+
" <td>-12.599413</td>\n",
|
1562 |
+
" </tr>\n",
|
1563 |
+
" <tr>\n",
|
1564 |
+
" <th>15231</th>\n",
|
1565 |
+
" <td>%</td>\n",
|
1566 |
+
" <td>DanNet (Danish WordNet)</td>\n",
|
1567 |
+
" <td>dannet</td>\n",
|
1568 |
+
" <td>104</td>\n",
|
1569 |
+
" <td>-8.941198</td>\n",
|
1570 |
+
" <td>-9.044065</td>\n",
|
1571 |
+
" </tr>\n",
|
1572 |
+
" <tr>\n",
|
1573 |
+
" <th>15272</th>\n",
|
1574 |
+
" <td>&</td>\n",
|
1575 |
+
" <td>DanNet (Danish WordNet)</td>\n",
|
1576 |
+
" <td>dannet</td>\n",
|
1577 |
+
" <td>49</td>\n",
|
1578 |
+
" <td>-9.693769</td>\n",
|
1579 |
+
" <td>-9.786003</td>\n",
|
1580 |
+
" </tr>\n",
|
1581 |
+
" <tr>\n",
|
1582 |
+
" <th>...</th>\n",
|
1583 |
+
" <td>...</td>\n",
|
1584 |
+
" <td>...</td>\n",
|
1585 |
+
" <td>...</td>\n",
|
1586 |
+
" <td>...</td>\n",
|
1587 |
+
" <td>...</td>\n",
|
1588 |
+
" <td>...</td>\n",
|
1589 |
+
" </tr>\n",
|
1590 |
+
" <tr>\n",
|
1591 |
+
" <th>15308188</th>\n",
|
1592 |
+
" <td>’</td>\n",
|
1593 |
+
" <td>NAAT</td>\n",
|
1594 |
+
" <td>naat</td>\n",
|
1595 |
+
" <td>123</td>\n",
|
1596 |
+
" <td>-7.307371</td>\n",
|
1597 |
+
" <td>-7.369814</td>\n",
|
1598 |
+
" </tr>\n",
|
1599 |
+
" <tr>\n",
|
1600 |
+
" <th>15309280</th>\n",
|
1601 |
+
" <td>“</td>\n",
|
1602 |
+
" <td>NAAT</td>\n",
|
1603 |
+
" <td>naat</td>\n",
|
1604 |
+
" <td>47</td>\n",
|
1605 |
+
" <td>-8.269408</td>\n",
|
1606 |
+
" <td>-8.318895</td>\n",
|
1607 |
+
" </tr>\n",
|
1608 |
+
" <tr>\n",
|
1609 |
+
" <th>15309314</th>\n",
|
1610 |
+
" <td>”</td>\n",
|
1611 |
+
" <td>NAAT</td>\n",
|
1612 |
+
" <td>naat</td>\n",
|
1613 |
+
" <td>139</td>\n",
|
1614 |
+
" <td>-7.185082</td>\n",
|
1615 |
+
" <td>-7.248453</td>\n",
|
1616 |
+
" </tr>\n",
|
1617 |
+
" <tr>\n",
|
1618 |
+
" <th>15309694</th>\n",
|
1619 |
+
" <td>•</td>\n",
|
1620 |
+
" <td>NAAT</td>\n",
|
1621 |
+
" <td>naat</td>\n",
|
1622 |
+
" <td>5</td>\n",
|
1623 |
+
" <td>-10.510118</td>\n",
|
1624 |
+
" <td>-10.398336</td>\n",
|
1625 |
+
" </tr>\n",
|
1626 |
+
" <tr>\n",
|
1627 |
+
" <th>15310402</th>\n",
|
1628 |
+
" <td>…</td>\n",
|
1629 |
+
" <td>NAAT</td>\n",
|
1630 |
+
" <td>naat</td>\n",
|
1631 |
+
" <td>11</td>\n",
|
1632 |
+
" <td>-9.721660</td>\n",
|
1633 |
+
" <td>-9.705189</td>\n",
|
1634 |
+
" </tr>\n",
|
1635 |
+
" </tbody>\n",
|
1636 |
+
"</table>\n",
|
1637 |
+
"<p>15326084 rows × 6 columns</p>\n",
|
1638 |
+
"</div>"
|
1639 |
+
],
|
1640 |
+
"text/plain": [
|
1641 |
+
" word domain domain_short freq log_prob \\\n",
|
1642 |
+
"4486 DanNet (Danish WordNet) dannet 38 -9.948003 \n",
|
1643 |
+
"14344 ! DanNet (Danish WordNet) dannet 686 -7.054711 \n",
|
1644 |
+
"15182 $ DanNet (Danish WordNet) dannet 2 -12.892442 \n",
|
1645 |
+
"15231 % DanNet (Danish WordNet) dannet 104 -8.941198 \n",
|
1646 |
+
"15272 & DanNet (Danish WordNet) dannet 49 -9.693769 \n",
|
1647 |
+
"... ... ... ... ... ... \n",
|
1648 |
+
"15308188 ’ NAAT naat 123 -7.307371 \n",
|
1649 |
+
"15309280 “ NAAT naat 47 -8.269408 \n",
|
1650 |
+
"15309314 ” NAAT naat 139 -7.185082 \n",
|
1651 |
+
"15309694 • NAAT naat 5 -10.510118 \n",
|
1652 |
+
"15310402 … NAAT naat 11 -9.721660 \n",
|
1653 |
+
"\n",
|
1654 |
+
" log_prob_smoothed \n",
|
1655 |
+
"4486 -10.034464 \n",
|
1656 |
+
"14344 -7.165691 \n",
|
1657 |
+
"15182 -12.599413 \n",
|
1658 |
+
"15231 -9.044065 \n",
|
1659 |
+
"15272 -9.786003 \n",
|
1660 |
+
"... ... \n",
|
1661 |
+
"15308188 -7.369814 \n",
|
1662 |
+
"15309280 -8.318895 \n",
|
1663 |
+
"15309314 -7.248453 \n",
|
1664 |
+
"15309694 -10.398336 \n",
|
1665 |
+
"15310402 -9.705189 \n",
|
1666 |
+
"\n",
|
1667 |
+
"[15326084 rows x 6 columns]"
|
1668 |
+
]
|
1669 |
+
},
|
1670 |
+
"execution_count": 56,
|
1671 |
+
"metadata": {},
|
1672 |
+
"output_type": "execute_result"
|
1673 |
+
}
|
1674 |
+
],
|
1675 |
+
"source": [
|
1676 |
+
"df = dataset.to_pandas()\n",
|
1677 |
+
"df = df.groupby([\"word\", \"domain\", \"domain_short\"]).sum().reset_index()\n",
|
1678 |
+
"\n",
|
1679 |
+
"# calculate without domains log prob\n",
|
1680 |
+
"df = calc_log_prob_pr_domain(df, domains)\n",
|
1681 |
+
"\n",
|
1682 |
+
"# inspect\n",
|
1683 |
+
"df"
|
1684 |
+
]
|
1685 |
+
},
|
1686 |
+
{
|
1687 |
+
"cell_type": "code",
|
1688 |
+
"execution_count": 57,
|
1689 |
+
"metadata": {},
|
1690 |
+
"outputs": [
|
1691 |
+
{
|
1692 |
+
"name": "stderr",
|
1693 |
+
"output_type": "stream",
|
1694 |
+
"text": [
|
1695 |
+
"Using custom data configuration default-21900efb838e4bd8\n",
|
1696 |
+
"/home/kenneth/.Envs/word_freq/lib/python3.8/site-packages/datasets/builder.py:712: FutureWarning: 'use_auth_token' was deprecated in version 2.7.1 and will be removed in 3.0.0. Pass `use_auth_token` to the initializer/`load_dataset_builder` instead.\n",
|
1697 |
+
" warnings.warn(\n"
|
1698 |
+
]
|
1699 |
+
},
|
1700 |
+
{
|
1701 |
+
"name": "stdout",
|
1702 |
+
"output_type": "stream",
|
1703 |
+
"text": [
|
1704 |
+
"Downloading and preparing dataset csv/default to /home/kenneth/.cache/huggingface/datasets/csv/default-21900efb838e4bd8/0.0.0...\n"
|
1705 |
+
]
|
1706 |
+
},
|
1707 |
+
{
|
1708 |
+
"name": "stderr",
|
1709 |
+
"output_type": "stream",
|
1710 |
+
"text": [
|
1711 |
+
"Downloading data files: 100%|██████████| 1/1 [00:00<00:00, 1636.48it/s]\n",
|
1712 |
+
"Extracting data files: 100%|██���███████| 1/1 [00:00<00:00, 455.46it/s]\n",
|
1713 |
+
"Generating train split: 0 examples [00:00, ? examples/s]/home/kenneth/.Envs/word_freq/lib/python3.8/site-packages/datasets/download/streaming_download_manager.py:727: FutureWarning: the 'mangle_dupe_cols' keyword is deprecated and will be removed in a future version. Please take steps to stop the use of 'mangle_dupe_cols'\n",
|
1714 |
+
" return pd.read_csv(xopen(filepath_or_buffer, \"rb\", use_auth_token=use_auth_token), **kwargs)\n",
|
1715 |
+
" \r"
|
1716 |
+
]
|
1717 |
+
},
|
1718 |
+
{
|
1719 |
+
"name": "stdout",
|
1720 |
+
"output_type": "stream",
|
1721 |
+
"text": [
|
1722 |
+
"Dataset csv downloaded and prepared to /home/kenneth/.cache/huggingface/datasets/csv/default-21900efb838e4bd8/0.0.0. Subsequent calls will reuse this data.\n"
|
1723 |
+
]
|
1724 |
+
}
|
1725 |
+
],
|
1726 |
+
"source": [
|
1727 |
+
"# with_pos = Dataset.from_pandas(df, info=info)\n",
|
1728 |
+
"\n",
|
1729 |
+
"# save to csv\n",
|
1730 |
+
"df.to_csv(\"danish_word_freqs_with_pos.csv\", index=False)\n",
|
1731 |
+
"with_pos = Dataset.from_csv(\"danish_word_freqs_with_pos.csv\")"
|
1732 |
+
]
|
1733 |
+
},
|
1734 |
+
{
|
1735 |
+
"attachments": {},
|
1736 |
+
"cell_type": "markdown",
|
1737 |
+
"metadata": {},
|
1738 |
+
"source": [
|
1739 |
+
"### Create the normalized dataset\n"
|
1740 |
+
]
|
1741 |
+
},
|
1742 |
+
{
|
1743 |
+
"cell_type": "code",
|
1744 |
+
"execution_count": 59,
|
1745 |
+
"metadata": {},
|
1746 |
+
"outputs": [
|
1747 |
+
{
|
1748 |
+
"name": "stderr",
|
1749 |
+
"output_type": "stream",
|
1750 |
+
"text": [
|
1751 |
+
"/tmp/ipykernel_38251/710725097.py:6: FutureWarning: The default value of numeric_only in DataFrameGroupBy.sum is deprecated. In a future version, numeric_only will default to False. Either specify numeric_only or select only columns which should be valid for the function.\n",
|
1752 |
+
" df = df.groupby([\"word\", \"top_level_domain\"]).sum().reset_index()\n"
|
1753 |
+
]
|
1754 |
+
},
|
1755 |
+
{
|
1756 |
+
"name": "stdout",
|
1757 |
+
"output_type": "stream",
|
1758 |
+
"text": [
|
1759 |
+
"Social Media\n",
|
1760 |
+
"dannet\n",
|
1761 |
+
"Web\n",
|
1762 |
+
"News\n",
|
1763 |
+
"Legal\n",
|
1764 |
+
"Wiki & Books\n",
|
1765 |
+
"Conversation\n",
|
1766 |
+
"Other\n",
|
1767 |
+
"top_level_domain\n",
|
1768 |
+
"Conversation 150531583.5\n",
|
1769 |
+
"Legal 150531583.5\n",
|
1770 |
+
"News 150531583.5\n",
|
1771 |
+
"Other 150531583.5\n",
|
1772 |
+
"Social Media 150531583.5\n",
|
1773 |
+
"Web 150531583.5\n",
|
1774 |
+
"Wiki & Books 150531583.5\n",
|
1775 |
+
"dannet 150531583.5\n",
|
1776 |
+
"Name: freq, dtype: float64\n"
|
1777 |
+
]
|
1778 |
+
},
|
1779 |
+
{
|
1780 |
+
"data": {
|
1781 |
+
"text/html": [
|
1782 |
+
"<div>\n",
|
1783 |
+
"<style scoped>\n",
|
1784 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
1785 |
+
" vertical-align: middle;\n",
|
1786 |
+
" }\n",
|
1787 |
+
"\n",
|
1788 |
+
" .dataframe tbody tr th {\n",
|
1789 |
+
" vertical-align: top;\n",
|
1790 |
+
" }\n",
|
1791 |
+
"\n",
|
1792 |
+
" .dataframe thead th {\n",
|
1793 |
+
" text-align: right;\n",
|
1794 |
+
" }\n",
|
1795 |
+
"</style>\n",
|
1796 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
1797 |
+
" <thead>\n",
|
1798 |
+
" <tr style=\"text-align: right;\">\n",
|
1799 |
+
" <th></th>\n",
|
1800 |
+
" <th>word</th>\n",
|
1801 |
+
" <th>top_level_domain</th>\n",
|
1802 |
+
" <th>freq</th>\n",
|
1803 |
+
" <th>log_prob</th>\n",
|
1804 |
+
" <th>log_prob_smoothed</th>\n",
|
1805 |
+
" </tr>\n",
|
1806 |
+
" </thead>\n",
|
1807 |
+
" <tbody>\n",
|
1808 |
+
" <tr>\n",
|
1809 |
+
" <th>297</th>\n",
|
1810 |
+
" <td>\\n</td>\n",
|
1811 |
+
" <td>Social Media</td>\n",
|
1812 |
+
" <td>1.721349e+06</td>\n",
|
1813 |
+
" <td>-6.550506</td>\n",
|
1814 |
+
" <td>-6.561969</td>\n",
|
1815 |
+
" </tr>\n",
|
1816 |
+
" <tr>\n",
|
1817 |
+
" <th>359</th>\n",
|
1818 |
+
" <td>\\n\\n</td>\n",
|
1819 |
+
" <td>Social Media</td>\n",
|
1820 |
+
" <td>1.643463e+03</td>\n",
|
1821 |
+
" <td>-13.504564</td>\n",
|
1822 |
+
" <td>-13.515419</td>\n",
|
1823 |
+
" </tr>\n",
|
1824 |
+
" <tr>\n",
|
1825 |
+
" <th>370</th>\n",
|
1826 |
+
" <td>\\n\\n\\n\\n</td>\n",
|
1827 |
+
" <td>Social Media</td>\n",
|
1828 |
+
" <td>1.148070e+00</td>\n",
|
1829 |
+
" <td>-20.771043</td>\n",
|
1830 |
+
" <td>-20.156018</td>\n",
|
1831 |
+
" </tr>\n",
|
1832 |
+
" <tr>\n",
|
1833 |
+
" <th>507</th>\n",
|
1834 |
+
" <td>\\n\\n\\n\\n \\n \\n\\n\\n \\n \\n\\n\\n \\n \\n\\n\\n \\n \\n\\n...</td>\n",
|
1835 |
+
" <td>Social Media</td>\n",
|
1836 |
+
" <td>5.740351e-01</td>\n",
|
1837 |
+
" <td>-21.464190</td>\n",
|
1838 |
+
" <td>-20.466946</td>\n",
|
1839 |
+
" </tr>\n",
|
1840 |
+
" <tr>\n",
|
1841 |
+
" <th>508</th>\n",
|
1842 |
+
" <td>\\n\\n\\n\\n \\n \\n \\n \\n \\n \\n\\n\\n \\n \\n \\n \\n \\n ...</td>\n",
|
1843 |
+
" <td>Social Media</td>\n",
|
1844 |
+
" <td>5.740351e-01</td>\n",
|
1845 |
+
" <td>-21.464190</td>\n",
|
1846 |
+
" <td>-20.466946</td>\n",
|
1847 |
+
" </tr>\n",
|
1848 |
+
" <tr>\n",
|
1849 |
+
" <th>...</th>\n",
|
1850 |
+
" <td>...</td>\n",
|
1851 |
+
" <td>...</td>\n",
|
1852 |
+
" <td>...</td>\n",
|
1853 |
+
" <td>...</td>\n",
|
1854 |
+
" <td>...</td>\n",
|
1855 |
+
" </tr>\n",
|
1856 |
+
" <tr>\n",
|
1857 |
+
" <th>13869006</th>\n",
|
1858 |
+
" <td>…</td>\n",
|
1859 |
+
" <td>Other</td>\n",
|
1860 |
+
" <td>1.269625e+04</td>\n",
|
1861 |
+
" <td>-11.460063</td>\n",
|
1862 |
+
" <td>-11.471448</td>\n",
|
1863 |
+
" </tr>\n",
|
1864 |
+
" <tr>\n",
|
1865 |
+
" <th>13869011</th>\n",
|
1866 |
+
" <td>……</td>\n",
|
1867 |
+
" <td>Other</td>\n",
|
1868 |
+
" <td>6.925227e+02</td>\n",
|
1869 |
+
" <td>-14.368784</td>\n",
|
1870 |
+
" <td>-14.378804</td>\n",
|
1871 |
+
" </tr>\n",
|
1872 |
+
" <tr>\n",
|
1873 |
+
" <th>13871529</th>\n",
|
1874 |
+
" <td>⟨hanj⟩</td>\n",
|
1875 |
+
" <td>Other</td>\n",
|
1876 |
+
" <td>4.616818e+02</td>\n",
|
1877 |
+
" <td>-14.774249</td>\n",
|
1878 |
+
" <td>-14.783549</td>\n",
|
1879 |
+
" </tr>\n",
|
1880 |
+
" <tr>\n",
|
1881 |
+
" <th>13871552</th>\n",
|
1882 |
+
" <td>⟩Gånga</td>\n",
|
1883 |
+
" <td>Other</td>\n",
|
1884 |
+
" <td>2.308409e+02</td>\n",
|
1885 |
+
" <td>-15.467396</td>\n",
|
1886 |
+
" <td>-15.474537</td>\n",
|
1887 |
+
" </tr>\n",
|
1888 |
+
" <tr>\n",
|
1889 |
+
" <th>13882710</th>\n",
|
1890 |
+
" <td>Goa</td>\n",
|
1891 |
+
" <td>Other</td>\n",
|
1892 |
+
" <td>2.308409e+02</td>\n",
|
1893 |
+
" <td>-15.467396</td>\n",
|
1894 |
+
" <td>-15.474537</td>\n",
|
1895 |
+
" </tr>\n",
|
1896 |
+
" </tbody>\n",
|
1897 |
+
"</table>\n",
|
1898 |
+
"<p>13884033 rows × 5 columns</p>\n",
|
1899 |
+
"</div>"
|
1900 |
+
],
|
1901 |
+
"text/plain": [
|
1902 |
+
" word top_level_domain \\\n",
|
1903 |
+
"297 \\n Social Media \n",
|
1904 |
+
"359 \\n\\n Social Media \n",
|
1905 |
+
"370 \\n\\n\\n\\n Social Media \n",
|
1906 |
+
"507 \\n\\n\\n\\n \\n \\n\\n\\n \\n \\n\\n\\n \\n \\n\\n\\n \\n \\n\\n... Social Media \n",
|
1907 |
+
"508 \\n\\n\\n\\n \\n \\n \\n \\n \\n \\n\\n\\n \\n \\n \\n \\n \\n ... Social Media \n",
|
1908 |
+
"... ... ... \n",
|
1909 |
+
"13869006 … Other \n",
|
1910 |
+
"13869011 …… Other \n",
|
1911 |
+
"13871529 ⟨hanj⟩ Other \n",
|
1912 |
+
"13871552 ⟩Gånga Other \n",
|
1913 |
+
"13882710 Goa Other \n",
|
1914 |
+
"\n",
|
1915 |
+
" freq log_prob log_prob_smoothed \n",
|
1916 |
+
"297 1.721349e+06 -6.550506 -6.561969 \n",
|
1917 |
+
"359 1.643463e+03 -13.504564 -13.515419 \n",
|
1918 |
+
"370 1.148070e+00 -20.771043 -20.156018 \n",
|
1919 |
+
"507 5.740351e-01 -21.464190 -20.466946 \n",
|
1920 |
+
"508 5.740351e-01 -21.464190 -20.466946 \n",
|
1921 |
+
"... ... ... ... \n",
|
1922 |
+
"13869006 1.269625e+04 -11.460063 -11.471448 \n",
|
1923 |
+
"13869011 6.925227e+02 -14.368784 -14.378804 \n",
|
1924 |
+
"13871529 4.616818e+02 -14.774249 -14.783549 \n",
|
1925 |
+
"13871552 2.308409e+02 -15.467396 -15.474537 \n",
|
1926 |
+
"13882710 2.308409e+02 -15.467396 -15.474537 \n",
|
1927 |
+
"\n",
|
1928 |
+
"[13884033 rows x 5 columns]"
|
1929 |
+
]
|
1930 |
+
},
|
1931 |
+
"execution_count": 59,
|
1932 |
+
"metadata": {},
|
1933 |
+
"output_type": "execute_result"
|
1934 |
+
}
|
1935 |
+
],
|
1936 |
+
"source": [
|
1937 |
+
"df = dataset.to_pandas()\n",
|
1938 |
+
"total_freq = df[\"freq\"].sum()\n",
|
1939 |
+
"tl_domains = set(df[\"top_level_domain\"])\n",
|
1940 |
+
"words_pr_domain = total_freq / len(tl_domains)\n",
|
1941 |
+
"\n",
|
1942 |
+
"df = df.groupby([\"word\", \"top_level_domain\"]).sum().reset_index()\n",
|
1943 |
+
"\n",
|
1944 |
+
"dfs = []\n",
|
1945 |
+
"for dom in tl_domains:\n",
|
1946 |
+
" print(dom)\n",
|
1947 |
+
" # break\n",
|
1948 |
+
" dom_df = df[df[\"top_level_domain\"] == dom]\n",
|
1949 |
+
" dom_total_freq = dom_df[\"freq\"].sum()\n",
|
1950 |
+
" dom_df[\"freq\"] = dom_df[\"freq\"] * words_pr_domain / dom_total_freq\n",
|
1951 |
+
" assert dom_df[\"freq\"].sum() - words_pr_domain < 1e-5\n",
|
1952 |
+
" dfs.append(dom_df)\n",
|
1953 |
+
"\n",
|
1954 |
+
"df = pd.concat(dfs)\n",
|
1955 |
+
"df[\"log_prob\"] = np.log(df[\"freq\"] / total_freq)\n",
|
1956 |
+
"df[\"log_prob_smoothed\"] = np.log((df[\"freq\"] + 1) / (total_freq + len(df)))\n",
|
1957 |
+
"\n",
|
1958 |
+
"# check that the total freq is the same\n",
|
1959 |
+
"assert df[\"freq\"].sum() - total_freq < 1e-5\n",
|
1960 |
+
"# check that the total freq is the same pr domain\n",
|
1961 |
+
"print(df.groupby(\"top_level_domain\")[\"freq\"].sum())\n",
|
1962 |
+
"\n",
|
1963 |
+
"# inspect\n",
|
1964 |
+
"df"
|
1965 |
+
]
|
1966 |
+
},
|
1967 |
+
{
|
1968 |
+
"cell_type": "code",
|
1969 |
+
"execution_count": 60,
|
1970 |
+
"metadata": {},
|
1971 |
+
"outputs": [
|
1972 |
+
{
|
1973 |
+
"name": "stderr",
|
1974 |
+
"output_type": "stream",
|
1975 |
+
"text": [
|
1976 |
+
"Using custom data configuration default-dde703a9c875a737\n",
|
1977 |
+
"/home/kenneth/.Envs/word_freq/lib/python3.8/site-packages/datasets/builder.py:712: FutureWarning: 'use_auth_token' was deprecated in version 2.7.1 and will be removed in 3.0.0. Pass `use_auth_token` to the initializer/`load_dataset_builder` instead.\n",
|
1978 |
+
" warnings.warn(\n"
|
1979 |
+
]
|
1980 |
+
},
|
1981 |
+
{
|
1982 |
+
"name": "stdout",
|
1983 |
+
"output_type": "stream",
|
1984 |
+
"text": [
|
1985 |
+
"Downloading and preparing dataset csv/default to /home/kenneth/.cache/huggingface/datasets/csv/default-dde703a9c875a737/0.0.0...\n"
|
1986 |
+
]
|
1987 |
+
},
|
1988 |
+
{
|
1989 |
+
"name": "stderr",
|
1990 |
+
"output_type": "stream",
|
1991 |
+
"text": [
|
1992 |
+
"Downloading data files: 100%|██████████| 1/1 [00:00<00:00, 2280.75it/s]\n",
|
1993 |
+
"Extracting data files: 100%|██████████| 1/1 [00:00<00:00, 569.72it/s]\n",
|
1994 |
+
"Generating train split: 0 examples [00:00, ? examples/s]/home/kenneth/.Envs/word_freq/lib/python3.8/site-packages/datasets/download/streaming_download_manager.py:727: FutureWarning: the 'mangle_dupe_cols' keyword is deprecated and will be removed in a future version. Please take steps to stop the use of 'mangle_dupe_cols'\n",
|
1995 |
+
" return pd.read_csv(xopen(filepath_or_buffer, \"rb\", use_auth_token=use_auth_token), **kwargs)\n",
|
1996 |
+
" \r"
|
1997 |
+
]
|
1998 |
+
},
|
1999 |
+
{
|
2000 |
+
"name": "stdout",
|
2001 |
+
"output_type": "stream",
|
2002 |
+
"text": [
|
2003 |
+
"Dataset csv downloaded and prepared to /home/kenneth/.cache/huggingface/datasets/csv/default-dde703a9c875a737/0.0.0. Subsequent calls will reuse this data.\n"
|
2004 |
+
]
|
2005 |
+
}
|
2006 |
+
],
|
2007 |
+
"source": [
|
2008 |
+
"# normalized = Dataset.from_pandas(df, info=info)\n",
|
2009 |
+
"\n",
|
2010 |
+
"# save to csv\n",
|
2011 |
+
"df.to_csv(\"danish_word_freqs_normalized.csv\", index=False)\n",
|
2012 |
+
"normalized = Dataset.from_csv(\"danish_word_freqs_normalized.csv\")"
|
2013 |
+
]
|
2014 |
+
},
|
2015 |
+
{
|
2016 |
+
"attachments": {},
|
2017 |
+
"cell_type": "markdown",
|
2018 |
+
"metadata": {},
|
2019 |
+
"source": [
|
2020 |
+
"## Upload to Huggingface Hub"
|
2021 |
+
]
|
2022 |
+
},
|
2023 |
+
{
|
2024 |
+
"cell_type": "code",
|
2025 |
+
"execution_count": 61,
|
2026 |
+
"metadata": {},
|
2027 |
+
"outputs": [],
|
2028 |
+
"source": [
|
2029 |
+
"ds_dict = DatasetDict({\n",
|
2030 |
+
" \"word_frequencies\": word_frequencies,\n",
|
2031 |
+
" \"by_domain\": by_domain,\n",
|
2032 |
+
" \"with_pos\": with_pos,\n",
|
2033 |
+
" \"normalized\": normalized,\n",
|
2034 |
+
"})"
|
2035 |
+
]
|
2036 |
+
},
|
2037 |
+
{
|
2038 |
+
"cell_type": "code",
|
2039 |
+
"execution_count": 64,
|
2040 |
+
"metadata": {},
|
2041 |
+
"outputs": [
|
2042 |
+
{
|
2043 |
+
"name": "stderr",
|
2044 |
+
"output_type": "stream",
|
2045 |
+
"text": [
|
2046 |
+
"Pushing dataset shards to the dataset hub: 100%|██████████| 1/1 [00:18<00:00, 18.75s/it]\n"
|
2047 |
+
]
|
2048 |
+
}
|
2049 |
+
],
|
2050 |
+
"source": [
|
2051 |
+
"word_frequencies.push_to_hub(\"chcaa/dagw-word-frequencies\")"
|
2052 |
+
]
|
2053 |
+
},
|
2054 |
+
{
|
2055 |
+
"cell_type": "code",
|
2056 |
+
"execution_count": 65,
|
2057 |
+
"metadata": {},
|
2058 |
+
"outputs": [
|
2059 |
+
{
|
2060 |
+
"name": "stderr",
|
2061 |
+
"output_type": "stream",
|
2062 |
+
"text": [
|
2063 |
+
"Pushing dataset shards to the dataset hub: 100%|██████████| 3/3 [00:36<00:00, 12.04s/it]\n"
|
2064 |
+
]
|
2065 |
+
}
|
2066 |
+
],
|
2067 |
+
"source": [
|
2068 |
+
"by_domain.push_to_hub(\"chcaa/dagw-word-frequencies-by-domain\")"
|
2069 |
+
]
|
2070 |
+
},
|
2071 |
+
{
|
2072 |
+
"cell_type": "code",
|
2073 |
+
"execution_count": 66,
|
2074 |
+
"metadata": {},
|
2075 |
+
"outputs": [
|
2076 |
+
{
|
2077 |
+
"name": "stderr",
|
2078 |
+
"output_type": "stream",
|
2079 |
+
"text": [
|
2080 |
+
"Pushing dataset shards to the dataset hub: 100%|██████████| 3/3 [00:38<00:00, 12.80s/it]\n"
|
2081 |
+
]
|
2082 |
+
}
|
2083 |
+
],
|
2084 |
+
"source": [
|
2085 |
+
"with_pos.push_to_hub(\"chcaa/dagw-word-frequencies-by-domain-with-pos-tags\")"
|
2086 |
+
]
|
2087 |
+
},
|
2088 |
+
{
|
2089 |
+
"cell_type": "code",
|
2090 |
+
"execution_count": 67,
|
2091 |
+
"metadata": {},
|
2092 |
+
"outputs": [
|
2093 |
+
{
|
2094 |
+
"name": "stderr",
|
2095 |
+
"output_type": "stream",
|
2096 |
+
"text": [
|
2097 |
+
"Pushing dataset shards to the dataset hub: 100%|██████████| 2/2 [00:27<00:00, 13.59s/it]\n"
|
2098 |
+
]
|
2099 |
+
}
|
2100 |
+
],
|
2101 |
+
"source": [
|
2102 |
+
"normalized.push_to_hub(\"chcaa/dagw-word-frequencies-normalized-by-domain\")"
|
2103 |
+
]
|
2104 |
+
},
|
2105 |
+
{
|
2106 |
+
"cell_type": "code",
|
2107 |
+
"execution_count": null,
|
2108 |
+
"metadata": {},
|
2109 |
+
"outputs": [],
|
2110 |
+
"source": []
|
2111 |
+
}
|
2112 |
+
],
|
2113 |
+
"metadata": {
|
2114 |
+
"kernelspec": {
|
2115 |
+
"display_name": "word_freq",
|
2116 |
+
"language": "python",
|
2117 |
+
"name": "python3"
|
2118 |
+
},
|
2119 |
+
"language_info": {
|
2120 |
+
"codemirror_mode": {
|
2121 |
+
"name": "ipython",
|
2122 |
+
"version": 3
|
2123 |
+
},
|
2124 |
+
"file_extension": ".py",
|
2125 |
+
"mimetype": "text/x-python",
|
2126 |
+
"name": "python",
|
2127 |
+
"nbconvert_exporter": "python",
|
2128 |
+
"pygments_lexer": "ipython3",
|
2129 |
+
"version": "3.8.13"
|
2130 |
+
},
|
2131 |
+
"orig_nbformat": 4,
|
2132 |
+
"vscode": {
|
2133 |
+
"interpreter": {
|
2134 |
+
"hash": "c10b2b53a6cd3acf03ed810a769e61720ca332994d31c08dc7197a28d260da6e"
|
2135 |
+
}
|
2136 |
+
}
|
2137 |
+
},
|
2138 |
+
"nbformat": 4,
|
2139 |
+
"nbformat_minor": 2
|
2140 |
+
}
|
wordfreq.py
ADDED
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
a quick script for getting wordcounts of all danish words in gigaword
|
3 |
+
"""
|
4 |
+
# import torch
|
5 |
+
# import torch.multiprocessing as mp
|
6 |
+
# mp.set_start_method('spawn', force=True)
|
7 |
+
# torch.set_num_threads(1)
|
8 |
+
|
9 |
+
import json
|
10 |
+
import os
|
11 |
+
from collections import Counter, defaultdict
|
12 |
+
from pathlib import Path
|
13 |
+
|
14 |
+
# from dacy.download import download_model, DEFAULT_CACHE_DIR
|
15 |
+
from typing import List, Optional, Tuple
|
16 |
+
|
17 |
+
import spacy
|
18 |
+
|
19 |
+
# model = "da_dacy_large_tft-0.0.0"
|
20 |
+
word_freq_path = "/data/DAGW/word_freqs"
|
21 |
+
dagw_sektioner = "/data/DAGW/dagw-master/sektioner"
|
22 |
+
|
23 |
+
# download_model(model, DEFAULT_CACHE_DIR)
|
24 |
+
# path = os.path.join(DEFAULT_CACHE_DIR, model)
|
25 |
+
|
26 |
+
nlp = spacy.load("da_core_news_lg", exclude=["parser", "ner"])
|
27 |
+
# nlp.get_pipe("transformer").model.attrs["flush_cache_chance"] = 0.1
|
28 |
+
|
29 |
+
|
30 |
+
Path(word_freq_path).mkdir(parents=True, exist_ok=True)
|
31 |
+
|
32 |
+
sections = os.listdir(dagw_sektioner)
|
33 |
+
filepaths = {}
|
34 |
+
for p in sections:
|
35 |
+
subpath = os.path.join(dagw_sektioner, p)
|
36 |
+
filepaths[p] = [
|
37 |
+
os.path.join(subpath, p)
|
38 |
+
for p in os.listdir(subpath)
|
39 |
+
if p != "LICENSE" and not p.endswith(".jsonl")
|
40 |
+
]
|
41 |
+
|
42 |
+
|
43 |
+
def wordpiece_group_text(text, size=500):
|
44 |
+
from transformers import AutoTokenizer
|
45 |
+
|
46 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
47 |
+
"Maltehb/-l-ctra-danish-electra-small-uncased", strip_accents=False
|
48 |
+
)
|
49 |
+
out = tokenizer.encode(text, add_special_tokens=False)
|
50 |
+
|
51 |
+
prv = 0
|
52 |
+
for i in range(size, len(out), size):
|
53 |
+
yield tokenizer.decode(out[prv:i])
|
54 |
+
prv = i
|
55 |
+
if prv < len(out):
|
56 |
+
yield tokenizer.decode(out[prv : len(out)])
|
57 |
+
|
58 |
+
|
59 |
+
def group_text(text, size=2400):
|
60 |
+
length = len(text)
|
61 |
+
prv = 0
|
62 |
+
for i in range(size, length, size):
|
63 |
+
yield text[prv:i]
|
64 |
+
prv = i
|
65 |
+
if prv < length:
|
66 |
+
yield text[prv:length]
|
67 |
+
|
68 |
+
|
69 |
+
def text_gen(filepaths):
|
70 |
+
for i, file in enumerate(filepaths):
|
71 |
+
if i % 10000 == 0:
|
72 |
+
print("\t", i, "/", len(filepaths))
|
73 |
+
with open(file, "r") as f:
|
74 |
+
text = f.read()
|
75 |
+
for t in group_text(text):
|
76 |
+
yield t
|
77 |
+
|
78 |
+
|
79 |
+
class WordCounter:
|
80 |
+
def __init__(self, l: Optional[List] = None):
|
81 |
+
self.dict = defaultdict(lambda: defaultdict(int))
|
82 |
+
if l is not None:
|
83 |
+
self.add(l)
|
84 |
+
|
85 |
+
def add(self, l: list):
|
86 |
+
for token, pos in l:
|
87 |
+
self.dict[token][pos] += 1
|
88 |
+
|
89 |
+
def __add__(self, other):
|
90 |
+
for k_tok in other.dict:
|
91 |
+
if k_tok in self.dict:
|
92 |
+
for pos, count in other.dict[k_tok].items():
|
93 |
+
self.dict[k_tok][pos] += count
|
94 |
+
else:
|
95 |
+
self.dict[k_tok] = other.dict[k_tok]
|
96 |
+
return self
|
97 |
+
|
98 |
+
|
99 |
+
for sec in filepaths:
|
100 |
+
print("Starting Section:", sec)
|
101 |
+
docs = nlp.pipe(texts=text_gen(filepaths[sec]), n_process=10, batch_size=8)
|
102 |
+
|
103 |
+
n = 0
|
104 |
+
word_counts = WordCounter()
|
105 |
+
for i, doc in enumerate(docs, start=1):
|
106 |
+
word_counts += WordCounter([(t.text, t.tag_) for t in doc])
|
107 |
+
|
108 |
+
if i % 10000 == 0:
|
109 |
+
with open(
|
110 |
+
os.path.join(word_freq_path, f"wordfreq_{sec}_{n}.json"), "w"
|
111 |
+
) as f:
|
112 |
+
json_str = json.dumps(word_counts.dict)
|
113 |
+
f.write(json_str)
|
114 |
+
word_counts = WordCounter()
|
115 |
+
n += 1
|
116 |
+
|
117 |
+
with open(os.path.join(word_freq_path, f"wordfreq_{sec}_{n}.json"), "w") as f:
|
118 |
+
json_str = json.dumps(word_counts.dict)
|
119 |
+
f.write(json_str)
|