{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Create HF Dataset\n", "Create a huggingface dataset from the word frequencies from Danish Gigaword \n", "(collected before 2022-22-01).\n", "These word frequencies are from the Danish Gigaword Corpus which are tokenized using\n", "the spacy pipeline for Danish `\"da_core_news_lg\"` using `spacy>=3.0.0,<3.4.0`.\n", "See the script \"word_freq.py\" for more details.\n", "\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Setup" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# !pip install datasets==2.8.0" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/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", " from .autonotebook import tqdm as notebook_tqdm\n" ] } ], "source": [ "import json\n", "import os\n", "from pathlib import Path\n", "import pandas as pd\n", "from datasets import Dataset, DatasetInfo, DatasetDict\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# mapping from domain to top-level domain\n", "domain_mapping_dict = {\n", " \"retsinformationdk\": \"Legal\",\n", " \"skat\": \"Legal\",\n", " \"retspraksis\": \"Legal\",\n", " \"hest\": \"Social Media\",\n", " \"cc\": \"Web\",\n", " \"adl\": \"Wiki & Books\",\n", " \"botxt\": \"Other\",\n", " \"danavis\": \"News\",\n", " \"dannet\": \"dannet\",\n", " \"depbank\": \"Other\",\n", " \"ep\": \"Conversation\",\n", " \"ft\": \"Conversation\",\n", " \"gutenberg\": \"Wiki & Books\",\n", " \"jvj\": \"Wiki & Books\",\n", " \"naat\": \"Conversation\",\n", " \"opensub\": \"Conversation\",\n", " \"relig\": \"Wiki & Books\",\n", " \"spont\": \"Conversation\",\n", " \"synne\": \"Other\",\n", " \"tv2r\": \"News\",\n", " \"wiki\": \"Wiki & Books\",\n", " \"wikibooks\": \"Wiki & Books\",\n", " \"wikisource\": \"Wiki & Books\",\n", " \"twfv19\": \"Social Media\",\n", "}\n", "\n", "# mapping from domain to its long name format\n", "longname_mapping_dict = {\n", " \"retsinformationdk\": \"retsinformation.dk (Danish legal information)\",\n", " \"skat\": \"Skat (Danish tax authority)\",\n", " \"retspraksis\": \"retspraksis (Danish legal information)\",\n", " \"hest\": \"Hestenettet (Danish debate forum)\",\n", " \"cc\": \"Common Crawl\",\n", " \"adl\": \" Archive for Danish Literature\",\n", " \"botxt\": \"Bornholmsk (Danish dialect)\",\n", " \"danavis\": \"Danish daily newspapers\",\n", " \"dannet\": \"DanNet (Danish WordNet)\",\n", " \"depbank\": \"Danish Dependency Treebank\",\n", " \"ep\": \"European Parliament\",\n", " \"ft\": \"Folketinget (Danish Parliament)\",\n", " \"gutenberg\": \"Gutenberg\",\n", " \"jvj\": \"Johannes V. Jensen (Danish poet)\",\n", " \"naat\": \"NAAT\",\n", " \"opensub\": \"Open Subtitles\",\n", " \"relig\": \"Religious texts\",\n", " \"spont\": \"Spontaneous speech\",\n", " \"synne\": \"Synderjysk (Danish dialect)\",\n", " \"tv2r\": \"TV 2 Radio (Danish news)\",\n", " \"wiki\": \"Wikipedia\",\n", " \"wikibooks\": \"Wikibooks\",\n", " \"wikisource\": \"Wikisource\",\n", " \"twfv19\": \"Twitter Folketingsvalget 2019 (Danish election tweets)\",\n", "}\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## The Data" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "teder {'NOUN': 1}\n", "i {'ADP': 81002, 'ADV': 708, 'CCONJ': 1, 'PRON': 5, 'X': 2}\n", "Marbæk {'PROPN': 3}\n", "? {'PUNCT': 31558}\n", "ville {'AUX': 9184, 'VERB': 177}\n", "jo {'ADV': 15825, 'SCONJ': 227, 'INTJ': 88}\n", "være {'AUX': 12805, 'VERB': 3773, 'X': 1, 'ADJ': 3, 'NOUN': 1, 'PRON': 1}\n" ] } ], "source": [ "path = Path(\"/data/DAGW/word_freqs\")\n", "json_files = [str(path / f) for f in os.listdir(path) if f.endswith(\".json\")]\n", "\n", "\n", "with open(json_files[0]) as f:\n", " data = json.load(f)\n", "\n", "# inspect\n", "for i, (k, v) in enumerate(data.items()):\n", " print(k, v)\n", " if i > 5:\n", " break" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'dannet', 'adl', 'hest', 'wiki', 'relig', 'botxt', 'synne', 'depbank', 'cc', 'tv2r', 'opensub', 'twfv19', 'retsinformationdk', 'wikibooks', 'jvj', 'ft', 'gutenberg', 'retspraksis', 'ep', 'skat', 'spont', 'wikisource', 'naat'}\n" ] } ], "source": [ "def get_subdomain(json_file):\n", " return json_file.split(\"/\")[-1].split(\".\")[0].split(\"_\")[1]\n", "\n", "\n", "domains = set([get_subdomain(json_file) for json_file in json_files])\n", "print(domains)\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Create the Datasets\n", "We will here create 4 different datasets:\n", "\n", "- `word_frequencies` - Danish word frequencies from Danish Gigaword.\n", "- `by_domain` - word frequencies pr. domain.\n", "- `with_pos ` - word frequencies pr. domain with their part-of-speech tags derived from the spacy pipeline for Danish `\"da_core_news_lg\"`.\n", "- `normalized` - word frequencies pr. domain normalized by the top-level domain.\n", "\n", "> Note: This notebook is not very efficient, it is mainly here for documentation of the process.\n" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "def convert_to_dataset_format(json_file):\n", " with open(json_file) as f:\n", " data = json.load(f)\n", "\n", " domain_origin = get_subdomain(json_file)\n", " domain = domain_mapping_dict[domain_origin]\n", "\n", " return [\n", " {\n", " \"word\": word,\n", " \"pos\": pos,\n", " \"freq\": freq,\n", " \"domain\": longname_mapping_dict[domain_origin],\n", " \"domain_short\": domain_origin,\n", " \"top_level_domain\": domain,\n", " }\n", " for word, posdict in data.items()\n", " for pos, freq in posdict.items()\n", " ]\n", "\n", "\n", "# load and convert all dataset\n", "def load_and_convert_gen(n=None):\n", " for i, json_file in enumerate(json_files[:n]):\n", " print(f\"Loading {json_file} ({i+1}/{len(json_files)})\")\n", " samples = convert_to_dataset_format(json_file)\n", " for sample in samples:\n", " yield sample\n" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "# add dataset info for each of the datasets\n", "info = DatasetInfo(\n", " description=\"Danish word frequencies\",\n", " 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", " homepage=\"https://huggingface.co/datasets/DDSC/partial-danish-gigaword-no-twitter\",\n", " version=\"1.0.0\",\n", " license=\"\",\n", ")" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Loading /data/DAGW/word_freqs/wordfreq_hest_11.json (1/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_ep_12.json (2/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_skat_1.json (3/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_wiki_12.json (4/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_adl_2.json (5/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_46.json (6/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_cc_24.json (7/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_20.json (8/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_18.json (9/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_relig_0.json (10/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_12.json (11/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_59.json (12/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_42.json (13/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_22.json (14/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_cc_2.json (15/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_ft_11.json (16/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_28.json (17/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_adl_3.json (18/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_33.json (19/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_ft_7.json (20/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_48.json (21/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_4.json (22/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_13.json (23/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_4.json (24/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_46.json (25/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_28.json (26/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_cc_22.json (27/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_ep_2.json (28/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_53.json (29/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_cc_7.json (30/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_skat_12.json (31/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_tv2r_4.json (32/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_10.json (33/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_tv2r_2.json (34/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_40.json (35/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_adl_6.json (36/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_ft_10.json (37/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_27.json (38/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_dannet_2.json (39/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_wiki_26.json (40/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_30.json (41/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_wiki_11.json (42/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_2.json (43/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_21.json (44/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_16.json (45/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_37.json (46/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_wiki_0.json (47/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_29.json (48/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_33.json (49/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_49.json (50/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_47.json (51/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_wiki_18.json (52/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_wiki_20.json (53/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_wiki_13.json (54/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_39.json (55/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_cc_4.json (56/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_adl_0.json (57/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_3.json (58/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_ft_9.json (59/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_cc_17.json (60/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_ft_4.json (61/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_wiki_5.json (62/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retspraksis_7.json (63/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_47.json (64/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_wiki_22.json (65/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_cc_29.json (66/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_55.json (67/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_ft_6.json (68/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_skat_8.json (69/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_ep_7.json (70/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_41.json (71/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_9.json (72/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_15.json (73/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retspraksis_4.json (74/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_cc_26.json (75/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_skat_14.json (76/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_2.json (77/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_cc_0.json (78/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_cc_20.json (79/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_4.json (80/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retspraksis_5.json (81/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_24.json (82/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_cc_10.json (83/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_9.json (84/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_skat_11.json (85/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_6.json (86/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_19.json (87/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_6.json (88/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_5.json (89/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retspraksis_8.json (90/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_26.json (91/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_ft_12.json (92/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_21.json (93/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_ep_13.json (94/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_cc_13.json (95/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retspraksis_2.json (96/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_skat_6.json (97/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_1.json (98/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_5.json (99/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_wiki_2.json (100/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_17.json (101/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_54.json (102/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_34.json (103/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_jvj_0.json (104/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_cc_1.json (105/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_29.json (106/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_18.json (107/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_13.json (108/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_wiki_4.json (109/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_dannet_4.json (110/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_17.json (111/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_7.json (112/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_6.json (113/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retspraksis_0.json (114/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_5.json (115/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_skat_13.json (116/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_24.json (117/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_32.json (118/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_cc_14.json (119/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_skat_15.json (120/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_ft_0.json (121/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_ft_8.json (122/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_ep_1.json (123/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_13.json (124/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_21.json (125/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_ep_11.json (126/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_wiki_25.json (127/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_wiki_28.json (128/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_dannet_3.json (129/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_cc_28.json (130/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_wiki_21.json (131/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_60.json (132/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_wiki_8.json (133/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_22.json (134/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_skat_0.json (135/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_19.json (136/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_11.json (137/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_cc_12.json (138/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_32.json (139/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_cc_23.json (140/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_52.json (141/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_17.json (142/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_botxt_0.json (143/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_2.json (144/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_35.json (145/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_27.json (146/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_23.json (147/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_wiki_10.json (148/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_cc_9.json (149/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_20.json (150/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_wiki_14.json (151/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_15.json (152/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_skat_4.json (153/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_0.json (154/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_cc_19.json (155/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_tv2r_1.json (156/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_37.json (157/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_58.json (158/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_31.json (159/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_skat_9.json (160/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_43.json (161/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_wiki_17.json (162/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_22.json (163/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_34.json (164/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_depbank_0.json (165/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_23.json (166/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retspraksis_1.json (167/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_wiki_1.json (168/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_ep_5.json (169/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_skat_7.json (170/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_40.json (171/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_tv2r_5.json (172/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_0.json (173/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_gutenberg_0.json (174/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_wiki_6.json (175/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_adl_4.json (176/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_44.json (177/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_cc_11.json (178/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_16.json (179/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_26.json (180/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_30.json (181/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_wiki_7.json (182/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_36.json (183/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_1.json (184/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_23.json (185/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_cc_25.json (186/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_cc_18.json (187/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_ep_10.json (188/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_15.json (189/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_28.json (190/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_wiki_27.json (191/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_wiki_3.json (192/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_ft_3.json (193/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_wikibooks_0.json (194/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_cc_6.json (195/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_8.json (196/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_cc_16.json (197/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_cc_15.json (198/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_ep_6.json (199/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_cc_8.json (200/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_11.json (201/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_34.json (202/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_36.json (203/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_twfv19_0.json (204/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_12.json (205/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_50.json (206/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_cc_21.json (207/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_ep_4.json (208/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_25.json (209/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_spont_0.json (210/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_wiki_23.json (211/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_50.json (212/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_ep_3.json (213/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_naat_0.json (214/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_10.json (215/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_35.json (216/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_wikisource_0.json (217/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_30.json (218/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_12.json (219/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_27.json (220/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_ep_9.json (221/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_31.json (222/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_twfv19_2.json (223/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_8.json (224/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_38.json (225/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_wiki_24.json (226/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_3.json (227/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_ep_0.json (228/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_tv2r_0.json (229/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_62.json (230/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_25.json (231/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_dannet_1.json (232/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_wiki_9.json (233/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_26.json (234/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_45.json (235/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_14.json (236/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_42.json (237/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_18.json (238/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_cc_5.json (239/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_wiki_16.json (240/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_wiki_15.json (241/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_skat_10.json (242/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_44.json (243/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_41.json (244/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_7.json (245/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_cc_3.json (246/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_24.json (247/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_tv2r_3.json (248/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_skat_3.json (249/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_56.json (250/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_8.json (251/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_16.json (252/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_adl_5.json (253/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_cc_27.json (254/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_dannet_0.json (255/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_1.json (256/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_19.json (257/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_14.json (258/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_20.json (259/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_29.json (260/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_skat_5.json (261/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_10.json (262/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_ep_8.json (263/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_synne_0.json (264/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_57.json (265/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_ft_2.json (266/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_51.json (267/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_61.json (268/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_twfv19_1.json (269/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_ft_1.json (270/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_36.json (271/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_skat_2.json (272/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_25.json (273/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retspraksis_3.json (274/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_48.json (275/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_49.json (276/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_ft_5.json (277/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_35.json (278/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_43.json (279/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_0.json (280/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retspraksis_6.json (281/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_45.json (282/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_37.json (283/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_9.json (284/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_7.json (285/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_opensub_31.json (286/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_39.json (287/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_14.json (288/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_3.json (289/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_38.json (290/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_retsinformationdk_33.json (291/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_wiki_19.json (292/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_hest_32.json (293/294)\n", "Loading /data/DAGW/word_freqs/wordfreq_adl_1.json (294/294)\n" ] } ], "source": [ "# convert to huggingface dataset\n", "dataset = Dataset.from_list(list(load_and_convert_gen()), info=info)\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### Create the word_frequencies dataset" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [], "source": [ "df = dataset.to_pandas()\n" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | word | \n", "pos | \n", "freq | \n", "domain | \n", "domain_short | \n", "top_level_domain | \n", "
---|---|---|---|---|---|---|
0 | \n", "teder | \n", "NOUN | \n", "1 | \n", "Hestenettet (Danish debate forum) | \n", "hest | \n", "Social Media | \n", "
1 | \n", "i | \n", "ADP | \n", "81002 | \n", "Hestenettet (Danish debate forum) | \n", "hest | \n", "Social Media | \n", "
2 | \n", "i | \n", "ADV | \n", "708 | \n", "Hestenettet (Danish debate forum) | \n", "hest | \n", "Social Media | \n", "
3 | \n", "i | \n", "CCONJ | \n", "1 | \n", "Hestenettet (Danish debate forum) | \n", "hest | \n", "Social Media | \n", "
4 | \n", "i | \n", "PRON | \n", "5 | \n", "Hestenettet (Danish debate forum) | \n", "hest | \n", "Social Media | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
51035982 | \n", "Leverandører | \n", "NOUN | \n", "1 | \n", "Archive for Danish Literature | \n", "adl | \n", "Wiki & Books | \n", "
51035983 | \n", "halvlé | \n", "NOUN | \n", "1 | \n", "Archive for Danish Literature | \n", "adl | \n", "Wiki & Books | \n", "
51035984 | \n", "Spejlruder | \n", "NOUN | \n", "1 | \n", "Archive for Danish Literature | \n", "adl | \n", "Wiki & Books | \n", "
51035985 | \n", "Restavrationssalen | \n", "PROPN | \n", "1 | \n", "Archive for Danish Literature | \n", "adl | \n", "Wiki & Books | \n", "
51035986 | \n", "Kølere | \n", "NOUN | \n", "1 | \n", "Archive for Danish Literature | \n", "adl | \n", "Wiki & Books | \n", "
51035987 rows × 6 columns
\n", "\n", " | word | \n", "freq | \n", "log_prob | \n", "log_prob_smoothed | \n", "
---|---|---|---|---|
0 | \n", "\u0001 | \n", "11523 | \n", "-11.557025 | \n", "-11.566130 | \n", "
1 | \n", "\u0001generalforsamling | \n", "1 | \n", "-20.909125 | \n", "-20.225169 | \n", "
2 | \n", "\u0002 | \n", "25873 | \n", "-10.748170 | \n", "-10.757323 | \n", "
3 | \n", "\u0003 | \n", "32510 | \n", "-10.519822 | \n", "-10.528983 | \n", "
4 | \n", "\u0003\u0003 | \n", "7 | \n", "-18.963215 | \n", "-18.838875 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
11120014 | \n", "Passer | \n", "3 | \n", "-19.810513 | \n", "-19.532022 | \n", "
11120015 | \n", "Rygning | \n", "10 | \n", "-18.606540 | \n", "-18.520421 | \n", "
11120016 | \n", " | \n", "1 | \n", "-20.909125 | \n", "-20.225169 | \n", "
11120017 | \n", " | \n", "24 | \n", "-17.731071 | \n", "-17.699441 | \n", "
11120018 | \n", " | \n", "3 | \n", "-19.810513 | \n", "-19.532022 | \n", "
11120019 rows × 4 columns
\n", "\n", " | word | \n", "pos | \n", "freq | \n", "domain | \n", "domain_short | \n", "top_level_domain | \n", "
---|---|---|---|---|---|---|
0 | \n", "teder | \n", "NOUN | \n", "1 | \n", "Hestenettet (Danish debate forum) | \n", "hest | \n", "Social Media | \n", "
1 | \n", "i | \n", "ADP | \n", "81002 | \n", "Hestenettet (Danish debate forum) | \n", "hest | \n", "Social Media | \n", "
2 | \n", "i | \n", "ADV | \n", "708 | \n", "Hestenettet (Danish debate forum) | \n", "hest | \n", "Social Media | \n", "
3 | \n", "i | \n", "CCONJ | \n", "1 | \n", "Hestenettet (Danish debate forum) | \n", "hest | \n", "Social Media | \n", "
4 | \n", "i | \n", "PRON | \n", "5 | \n", "Hestenettet (Danish debate forum) | \n", "hest | \n", "Social Media | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
51035982 | \n", "Leverandører | \n", "NOUN | \n", "1 | \n", "Archive for Danish Literature | \n", "adl | \n", "Wiki & Books | \n", "
51035983 | \n", "halvlé | \n", "NOUN | \n", "1 | \n", "Archive for Danish Literature | \n", "adl | \n", "Wiki & Books | \n", "
51035984 | \n", "Spejlruder | \n", "NOUN | \n", "1 | \n", "Archive for Danish Literature | \n", "adl | \n", "Wiki & Books | \n", "
51035985 | \n", "Restavrationssalen | \n", "PROPN | \n", "1 | \n", "Archive for Danish Literature | \n", "adl | \n", "Wiki & Books | \n", "
51035986 | \n", "Kølere | \n", "NOUN | \n", "1 | \n", "Archive for Danish Literature | \n", "adl | \n", "Wiki & Books | \n", "
51035987 rows × 6 columns
\n", "\n", " | word | \n", "domain | \n", "domain_short | \n", "freq | \n", "log_prob | \n", "log_prob_smoothed | \n", "
---|---|---|---|---|---|---|
4486 | \n", "\n", " | DanNet (Danish WordNet) | \n", "dannet | \n", "38 | \n", "-9.948003 | \n", "-10.034464 | \n", "
14344 | \n", "! | \n", "DanNet (Danish WordNet) | \n", "dannet | \n", "686 | \n", "-7.054711 | \n", "-7.165691 | \n", "
15182 | \n", "$ | \n", "DanNet (Danish WordNet) | \n", "dannet | \n", "2 | \n", "-12.892442 | \n", "-12.599413 | \n", "
15231 | \n", "% | \n", "DanNet (Danish WordNet) | \n", "dannet | \n", "104 | \n", "-8.941198 | \n", "-9.044065 | \n", "
15272 | \n", "& | \n", "DanNet (Danish WordNet) | \n", "dannet | \n", "49 | \n", "-9.693769 | \n", "-9.786003 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
15308188 | \n", "’ | \n", "NAAT | \n", "naat | \n", "123 | \n", "-7.307371 | \n", "-7.369814 | \n", "
15309280 | \n", "“ | \n", "NAAT | \n", "naat | \n", "47 | \n", "-8.269408 | \n", "-8.318895 | \n", "
15309314 | \n", "” | \n", "NAAT | \n", "naat | \n", "139 | \n", "-7.185082 | \n", "-7.248453 | \n", "
15309694 | \n", "• | \n", "NAAT | \n", "naat | \n", "5 | \n", "-10.510118 | \n", "-10.398336 | \n", "
15310402 | \n", "… | \n", "NAAT | \n", "naat | \n", "11 | \n", "-9.721660 | \n", "-9.705189 | \n", "
15326084 rows × 6 columns
\n", "\n", " | word | \n", "domain | \n", "domain_short | \n", "freq | \n", "log_prob | \n", "log_prob_smoothed | \n", "
---|---|---|---|---|---|---|
4486 | \n", "\n", " | DanNet (Danish WordNet) | \n", "dannet | \n", "38 | \n", "-9.948003 | \n", "-10.034464 | \n", "
14344 | \n", "! | \n", "DanNet (Danish WordNet) | \n", "dannet | \n", "686 | \n", "-7.054711 | \n", "-7.165691 | \n", "
15182 | \n", "$ | \n", "DanNet (Danish WordNet) | \n", "dannet | \n", "2 | \n", "-12.892442 | \n", "-12.599413 | \n", "
15231 | \n", "% | \n", "DanNet (Danish WordNet) | \n", "dannet | \n", "104 | \n", "-8.941198 | \n", "-9.044065 | \n", "
15272 | \n", "& | \n", "DanNet (Danish WordNet) | \n", "dannet | \n", "49 | \n", "-9.693769 | \n", "-9.786003 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
15308188 | \n", "’ | \n", "NAAT | \n", "naat | \n", "123 | \n", "-7.307371 | \n", "-7.369814 | \n", "
15309280 | \n", "“ | \n", "NAAT | \n", "naat | \n", "47 | \n", "-8.269408 | \n", "-8.318895 | \n", "
15309314 | \n", "” | \n", "NAAT | \n", "naat | \n", "139 | \n", "-7.185082 | \n", "-7.248453 | \n", "
15309694 | \n", "• | \n", "NAAT | \n", "naat | \n", "5 | \n", "-10.510118 | \n", "-10.398336 | \n", "
15310402 | \n", "… | \n", "NAAT | \n", "naat | \n", "11 | \n", "-9.721660 | \n", "-9.705189 | \n", "
15326084 rows × 6 columns
\n", "\n", " | word | \n", "top_level_domain | \n", "freq | \n", "log_prob | \n", "log_prob_smoothed | \n", "
---|---|---|---|---|---|
297 | \n", "\\n | \n", "Social Media | \n", "1.721349e+06 | \n", "-6.550506 | \n", "-6.561969 | \n", "
359 | \n", "\\n\\n | \n", "Social Media | \n", "1.643463e+03 | \n", "-13.504564 | \n", "-13.515419 | \n", "
370 | \n", "\\n\\n\\n\\n | \n", "Social Media | \n", "1.148070e+00 | \n", "-20.771043 | \n", "-20.156018 | \n", "
507 | \n", "\\n\\n\\n\\n \\n \\n\\n\\n \\n \\n\\n\\n \\n \\n\\n\\n \\n \\n\\n... | \n", "Social Media | \n", "5.740351e-01 | \n", "-21.464190 | \n", "-20.466946 | \n", "
508 | \n", "\\n\\n\\n\\n \\n \\n \\n \\n \\n \\n\\n\\n \\n \\n \\n \\n \\n ... | \n", "Social Media | \n", "5.740351e-01 | \n", "-21.464190 | \n", "-20.466946 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
13869006 | \n", "… | \n", "Other | \n", "1.269625e+04 | \n", "-11.460063 | \n", "-11.471448 | \n", "
13869011 | \n", "…… | \n", "Other | \n", "6.925227e+02 | \n", "-14.368784 | \n", "-14.378804 | \n", "
13871529 | \n", "⟨hanj⟩ | \n", "Other | \n", "4.616818e+02 | \n", "-14.774249 | \n", "-14.783549 | \n", "
13871552 | \n", "⟩Gånga | \n", "Other | \n", "2.308409e+02 | \n", "-15.467396 | \n", "-15.474537 | \n", "
13882710 | \n", "Goa | \n", "Other | \n", "2.308409e+02 | \n", "-15.467396 | \n", "-15.474537 | \n", "
13884033 rows × 5 columns
\n", "