{ "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", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
wordposfreqdomaindomain_shorttop_level_domain
0tederNOUN1Hestenettet (Danish debate forum)hestSocial Media
1iADP81002Hestenettet (Danish debate forum)hestSocial Media
2iADV708Hestenettet (Danish debate forum)hestSocial Media
3iCCONJ1Hestenettet (Danish debate forum)hestSocial Media
4iPRON5Hestenettet (Danish debate forum)hestSocial Media
.....................
51035982LeverandørerNOUN1Archive for Danish LiteratureadlWiki & Books
51035983halvléNOUN1Archive for Danish LiteratureadlWiki & Books
51035984SpejlruderNOUN1Archive for Danish LiteratureadlWiki & Books
51035985RestavrationssalenPROPN1Archive for Danish LiteratureadlWiki & Books
51035986KølereNOUN1Archive for Danish LiteratureadlWiki & Books
\n", "

51035987 rows × 6 columns

\n", "
" ], "text/plain": [ " word pos freq domain \\\n", "0 teder NOUN 1 Hestenettet (Danish debate forum) \n", "1 i ADP 81002 Hestenettet (Danish debate forum) \n", "2 i ADV 708 Hestenettet (Danish debate forum) \n", "3 i CCONJ 1 Hestenettet (Danish debate forum) \n", "4 i PRON 5 Hestenettet (Danish debate forum) \n", "... ... ... ... ... \n", "51035982 Leverandører NOUN 1 Archive for Danish Literature \n", "51035983 halvlé NOUN 1 Archive for Danish Literature \n", "51035984 Spejlruder NOUN 1 Archive for Danish Literature \n", "51035985 Restavrationssalen PROPN 1 Archive for Danish Literature \n", "51035986 Kølere NOUN 1 Archive for Danish Literature \n", "\n", " domain_short top_level_domain \n", "0 hest Social Media \n", "1 hest Social Media \n", "2 hest Social Media \n", "3 hest Social Media \n", "4 hest Social Media \n", "... ... ... \n", "51035982 adl Wiki & Books \n", "51035983 adl Wiki & Books \n", "51035984 adl Wiki & Books \n", "51035985 adl Wiki & Books \n", "51035986 adl Wiki & Books \n", "\n", "[51035987 rows x 6 columns]" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/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", " df = df.groupby([\"word\"]).sum().reset_index()\n" ] } ], "source": [ "df = df.groupby([\"word\"]).sum().reset_index()\n", "\n", "# recalculate log prob\n", "total_freq = df[\"freq\"].sum()\n", "df[\"log_prob\"] = np.log(df[\"freq\"] / total_freq)\n", "df[\"log_prob_smoothed\"] = np.log((df[\"freq\"] + 1) / (total_freq + len(df)))" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
wordfreqlog_problog_prob_smoothed
0\u000111523-11.557025-11.566130
1\u0001generalforsamling1-20.909125-20.225169
2\u000225873-10.748170-10.757323
3\u000332510-10.519822-10.528983
4\u0003\u00037-18.963215-18.838875
...............
11120014󱤆Passer3-19.810513-19.532022
11120015󱤈Rygning10-18.606540-18.520421
11120016󾌵󾟛󾟛1-20.909125-20.225169
11120017􀁸24-17.731071-17.699441
11120018􀍴3-19.810513-19.532022
\n", "

11120019 rows × 4 columns

\n", "
" ], "text/plain": [ " word freq log_prob log_prob_smoothed\n", "0 \u0001 11523 -11.557025 -11.566130\n", "1 \u0001generalforsamling 1 -20.909125 -20.225169\n", "2 \u0002 25873 -10.748170 -10.757323\n", "3 \u0003 32510 -10.519822 -10.528983\n", "4 \u0003\u0003 7 -18.963215 -18.838875\n", "... ... ... ... ...\n", "11120014 󱤆Passer 3 -19.810513 -19.532022\n", "11120015 󱤈Rygning 10 -18.606540 -18.520421\n", "11120016 󾌵󾟛󾟛 1 -20.909125 -20.225169\n", "11120017 􀁸 24 -17.731071 -17.699441\n", "11120018 􀍴 3 -19.810513 -19.532022\n", "\n", "[11120019 rows x 4 columns]" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df # inspect" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Using custom data configuration default-db8b733866850efe\n", "/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", " warnings.warn(\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Downloading and preparing dataset csv/default to /home/kenneth/.cache/huggingface/datasets/csv/default-db8b733866850efe/0.0.0...\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Downloading data files: 100%|██████████| 1/1 [00:00<00:00, 1030.29it/s]\n", "Extracting data files: 100%|██████████| 1/1 [00:00<00:00, 839.70it/s]\n", "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", " return pd.read_csv(xopen(filepath_or_buffer, \"rb\", use_auth_token=use_auth_token), **kwargs)\n", " \r" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Dataset csv downloaded and prepared to /home/kenneth/.cache/huggingface/datasets/csv/default-db8b733866850efe/0.0.0. Subsequent calls will reuse this data.\n" ] } ], "source": [ "# save to csv\n", "df.to_csv(\"danish_word_freqs.csv\", index=False)\n", "\n", "# load using huggingface datasets\n", "word_frequencies = Dataset.from_csv(\"danish_word_freqs.csv\")" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### Create the by_domain dataset\n" ] }, { "cell_type": "code", "execution_count": 49, "metadata": {}, "outputs": [], "source": [ "df = dataset.to_pandas()" ] }, { "cell_type": "code", "execution_count": 50, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
wordposfreqdomaindomain_shorttop_level_domain
0tederNOUN1Hestenettet (Danish debate forum)hestSocial Media
1iADP81002Hestenettet (Danish debate forum)hestSocial Media
2iADV708Hestenettet (Danish debate forum)hestSocial Media
3iCCONJ1Hestenettet (Danish debate forum)hestSocial Media
4iPRON5Hestenettet (Danish debate forum)hestSocial Media
.....................
51035982LeverandørerNOUN1Archive for Danish LiteratureadlWiki & Books
51035983halvléNOUN1Archive for Danish LiteratureadlWiki & Books
51035984SpejlruderNOUN1Archive for Danish LiteratureadlWiki & Books
51035985RestavrationssalenPROPN1Archive for Danish LiteratureadlWiki & Books
51035986KølereNOUN1Archive for Danish LiteratureadlWiki & Books
\n", "

51035987 rows × 6 columns

\n", "
" ], "text/plain": [ " word pos freq domain \\\n", "0 teder NOUN 1 Hestenettet (Danish debate forum) \n", "1 i ADP 81002 Hestenettet (Danish debate forum) \n", "2 i ADV 708 Hestenettet (Danish debate forum) \n", "3 i CCONJ 1 Hestenettet (Danish debate forum) \n", "4 i PRON 5 Hestenettet (Danish debate forum) \n", "... ... ... ... ... \n", "51035982 Leverandører NOUN 1 Archive for Danish Literature \n", "51035983 halvlé NOUN 1 Archive for Danish Literature \n", "51035984 Spejlruder NOUN 1 Archive for Danish Literature \n", "51035985 Restavrationssalen PROPN 1 Archive for Danish Literature \n", "51035986 Kølere NOUN 1 Archive for Danish Literature \n", "\n", " domain_short top_level_domain \n", "0 hest Social Media \n", "1 hest Social Media \n", "2 hest Social Media \n", "3 hest Social Media \n", "4 hest Social Media \n", "... ... ... \n", "51035982 adl Wiki & Books \n", "51035983 adl Wiki & Books \n", "51035984 adl Wiki & Books \n", "51035985 adl Wiki & Books \n", "51035986 adl Wiki & Books \n", "\n", "[51035987 rows x 6 columns]" ] }, "execution_count": 50, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df" ] }, { "cell_type": "code", "execution_count": 51, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/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", " df = df.groupby([\"word\", \"domain\", \"domain_short\"]).sum().reset_index()\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "dannet\n", "adl\n", "hest\n", "wiki\n", "relig\n", "botxt\n", "synne\n", "depbank\n", "cc\n", "tv2r\n", "opensub\n", "twfv19\n", "retsinformationdk\n", "wikibooks\n", "jvj\n", "ft\n", "gutenberg\n", "retspraksis\n", "ep\n", "skat\n", "spont\n", "wikisource\n", "naat\n" ] } ], "source": [ "# hide pandas warnings\n", "pd.options.mode.chained_assignment = None\n", "\n", "df = df.groupby([\"word\", \"domain\", \"domain_short\"]).sum().reset_index()\n", "\n", "# recalculate log prob\n", "def calc_log_prob_pr_domain(df, domains):\n", " dfs = []\n", " for domain in domains:\n", " print(domain)\n", " df_domains = df.loc[df[\"domain_short\"] == domain]\n", " total_freq = df_domains[\"freq\"].sum()\n", " df_domains[\"log_prob\"] = np.log(df_domains[\"freq\"] / total_freq)\n", " df_domains[\"log_prob_smoothed\"] = np.log((df_domains[\"freq\"] + 1) / (total_freq + len(df_domains)))\n", " dfs.append(df_domains)\n", " \n", " return pd.concat(dfs)\n", "\n", "df = calc_log_prob_pr_domain(df, domains)" ] }, { "cell_type": "code", "execution_count": 52, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
worddomaindomain_shortfreqlog_problog_prob_smoothed
4486DanNet (Danish WordNet)dannet38-9.948003-10.034464
14344!DanNet (Danish WordNet)dannet686-7.054711-7.165691
15182$DanNet (Danish WordNet)dannet2-12.892442-12.599413
15231%DanNet (Danish WordNet)dannet104-8.941198-9.044065
15272&DanNet (Danish WordNet)dannet49-9.693769-9.786003
.....................
15308188NAATnaat123-7.307371-7.369814
15309280NAATnaat47-8.269408-8.318895
15309314NAATnaat139-7.185082-7.248453
15309694NAATnaat5-10.510118-10.398336
15310402NAATnaat11-9.721660-9.705189
\n", "

15326084 rows × 6 columns

\n", "
" ], "text/plain": [ " word domain domain_short freq log_prob \\\n", "4486 DanNet (Danish WordNet) dannet 38 -9.948003 \n", "14344 ! DanNet (Danish WordNet) dannet 686 -7.054711 \n", "15182 $ DanNet (Danish WordNet) dannet 2 -12.892442 \n", "15231 % DanNet (Danish WordNet) dannet 104 -8.941198 \n", "15272 & DanNet (Danish WordNet) dannet 49 -9.693769 \n", "... ... ... ... ... ... \n", "15308188 ’ NAAT naat 123 -7.307371 \n", "15309280 “ NAAT naat 47 -8.269408 \n", "15309314 ” NAAT naat 139 -7.185082 \n", "15309694 • NAAT naat 5 -10.510118 \n", "15310402 … NAAT naat 11 -9.721660 \n", "\n", " log_prob_smoothed \n", "4486 -10.034464 \n", "14344 -7.165691 \n", "15182 -12.599413 \n", "15231 -9.044065 \n", "15272 -9.786003 \n", "... ... \n", "15308188 -7.369814 \n", "15309280 -8.318895 \n", "15309314 -7.248453 \n", "15309694 -10.398336 \n", "15310402 -9.705189 \n", "\n", "[15326084 rows x 6 columns]" ] }, "execution_count": 52, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df" ] }, { "cell_type": "code", "execution_count": 55, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Using custom data configuration default-bcdefdf7aa1acd36\n", "/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", " warnings.warn(\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Downloading and preparing dataset csv/default to /home/kenneth/.cache/huggingface/datasets/csv/default-bcdefdf7aa1acd36/0.0.0...\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Downloading data files: 100%|██████████| 1/1 [00:00<00:00, 1062.39it/s]\n", "Extracting data files: 100%|██████████| 1/1 [00:00<00:00, 565.04it/s]\n", "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", " return pd.read_csv(xopen(filepath_or_buffer, \"rb\", use_auth_token=use_auth_token), **kwargs)\n", " \r" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Dataset csv downloaded and prepared to /home/kenneth/.cache/huggingface/datasets/csv/default-bcdefdf7aa1acd36/0.0.0. Subsequent calls will reuse this data.\n" ] } ], "source": [ "# save to csv\n", "df.to_csv(\"danish_word_freqs_by_domain.csv\", index=False)\n", "\n", "# load using huggingface datasets\n", "by_domain = Dataset.from_csv(\"danish_word_freqs_by_domain.csv\")" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### Create the with_pos dataset" ] }, { "cell_type": "code", "execution_count": 56, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/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", " df = df.groupby([\"word\", \"domain\", \"domain_short\"]).sum().reset_index()\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "dannet\n", "adl\n", "hest\n", "wiki\n", "relig\n", "botxt\n", "synne\n", "depbank\n", "cc\n", "tv2r\n", "opensub\n", "twfv19\n", "retsinformationdk\n", "wikibooks\n", "jvj\n", "ft\n", "gutenberg\n", "retspraksis\n", "ep\n", "skat\n", "spont\n", "wikisource\n", "naat\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
worddomaindomain_shortfreqlog_problog_prob_smoothed
4486DanNet (Danish WordNet)dannet38-9.948003-10.034464
14344!DanNet (Danish WordNet)dannet686-7.054711-7.165691
15182$DanNet (Danish WordNet)dannet2-12.892442-12.599413
15231%DanNet (Danish WordNet)dannet104-8.941198-9.044065
15272&DanNet (Danish WordNet)dannet49-9.693769-9.786003
.....................
15308188NAATnaat123-7.307371-7.369814
15309280NAATnaat47-8.269408-8.318895
15309314NAATnaat139-7.185082-7.248453
15309694NAATnaat5-10.510118-10.398336
15310402NAATnaat11-9.721660-9.705189
\n", "

15326084 rows × 6 columns

\n", "
" ], "text/plain": [ " word domain domain_short freq log_prob \\\n", "4486 DanNet (Danish WordNet) dannet 38 -9.948003 \n", "14344 ! DanNet (Danish WordNet) dannet 686 -7.054711 \n", "15182 $ DanNet (Danish WordNet) dannet 2 -12.892442 \n", "15231 % DanNet (Danish WordNet) dannet 104 -8.941198 \n", "15272 & DanNet (Danish WordNet) dannet 49 -9.693769 \n", "... ... ... ... ... ... \n", "15308188 ’ NAAT naat 123 -7.307371 \n", "15309280 “ NAAT naat 47 -8.269408 \n", "15309314 ” NAAT naat 139 -7.185082 \n", "15309694 • NAAT naat 5 -10.510118 \n", "15310402 … NAAT naat 11 -9.721660 \n", "\n", " log_prob_smoothed \n", "4486 -10.034464 \n", "14344 -7.165691 \n", "15182 -12.599413 \n", "15231 -9.044065 \n", "15272 -9.786003 \n", "... ... \n", "15308188 -7.369814 \n", "15309280 -8.318895 \n", "15309314 -7.248453 \n", "15309694 -10.398336 \n", "15310402 -9.705189 \n", "\n", "[15326084 rows x 6 columns]" ] }, "execution_count": 56, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = dataset.to_pandas()\n", "df = df.groupby([\"word\", \"domain\", \"domain_short\"]).sum().reset_index()\n", "\n", "# calculate without domains log prob\n", "df = calc_log_prob_pr_domain(df, domains)\n", "\n", "# inspect\n", "df" ] }, { "cell_type": "code", "execution_count": 57, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Using custom data configuration default-21900efb838e4bd8\n", "/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", " warnings.warn(\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Downloading and preparing dataset csv/default to /home/kenneth/.cache/huggingface/datasets/csv/default-21900efb838e4bd8/0.0.0...\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Downloading data files: 100%|██████████| 1/1 [00:00<00:00, 1636.48it/s]\n", "Extracting data files: 100%|██████████| 1/1 [00:00<00:00, 455.46it/s]\n", "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", " return pd.read_csv(xopen(filepath_or_buffer, \"rb\", use_auth_token=use_auth_token), **kwargs)\n", " \r" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Dataset csv downloaded and prepared to /home/kenneth/.cache/huggingface/datasets/csv/default-21900efb838e4bd8/0.0.0. Subsequent calls will reuse this data.\n" ] } ], "source": [ "# with_pos = Dataset.from_pandas(df, info=info)\n", "\n", "# save to csv\n", "df.to_csv(\"danish_word_freqs_with_pos.csv\", index=False)\n", "with_pos = Dataset.from_csv(\"danish_word_freqs_with_pos.csv\")" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### Create the normalized dataset\n" ] }, { "cell_type": "code", "execution_count": 59, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/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", " df = df.groupby([\"word\", \"top_level_domain\"]).sum().reset_index()\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Social Media\n", "dannet\n", "Web\n", "News\n", "Legal\n", "Wiki & Books\n", "Conversation\n", "Other\n", "top_level_domain\n", "Conversation 150531583.5\n", "Legal 150531583.5\n", "News 150531583.5\n", "Other 150531583.5\n", "Social Media 150531583.5\n", "Web 150531583.5\n", "Wiki & Books 150531583.5\n", "dannet 150531583.5\n", "Name: freq, dtype: float64\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
wordtop_level_domainfreqlog_problog_prob_smoothed
297\\nSocial Media1.721349e+06-6.550506-6.561969
359\\n\\nSocial Media1.643463e+03-13.504564-13.515419
370\\n\\n\\n\\nSocial Media1.148070e+00-20.771043-20.156018
507\\n\\n\\n\\n \\n \\n\\n\\n \\n \\n\\n\\n \\n \\n\\n\\n \\n \\n\\n...Social Media5.740351e-01-21.464190-20.466946
508\\n\\n\\n\\n \\n \\n \\n \\n \\n \\n\\n\\n \\n \\n \\n \\n \\n ...Social Media5.740351e-01-21.464190-20.466946
..................
13869006Other1.269625e+04-11.460063-11.471448
13869011……Other6.925227e+02-14.368784-14.378804
13871529⟨hanj⟩Other4.616818e+02-14.774249-14.783549
13871552⟩GångaOther2.308409e+02-15.467396-15.474537
13882710GoaOther2.308409e+02-15.467396-15.474537
\n", "

13884033 rows × 5 columns

\n", "
" ], "text/plain": [ " word top_level_domain \\\n", "297 \\n Social Media \n", "359 \\n\\n Social Media \n", "370 \\n\\n\\n\\n Social Media \n", "507 \\n\\n\\n\\n \\n \\n\\n\\n \\n \\n\\n\\n \\n \\n\\n\\n \\n \\n\\n... Social Media \n", "508 \\n\\n\\n\\n \\n \\n \\n \\n \\n \\n\\n\\n \\n \\n \\n \\n \\n ... Social Media \n", "... ... ... \n", "13869006 … Other \n", "13869011 …… Other \n", "13871529 ⟨hanj⟩ Other \n", "13871552 ⟩Gånga Other \n", "13882710 Goa Other \n", "\n", " freq log_prob log_prob_smoothed \n", "297 1.721349e+06 -6.550506 -6.561969 \n", "359 1.643463e+03 -13.504564 -13.515419 \n", "370 1.148070e+00 -20.771043 -20.156018 \n", "507 5.740351e-01 -21.464190 -20.466946 \n", "508 5.740351e-01 -21.464190 -20.466946 \n", "... ... ... ... \n", "13869006 1.269625e+04 -11.460063 -11.471448 \n", "13869011 6.925227e+02 -14.368784 -14.378804 \n", "13871529 4.616818e+02 -14.774249 -14.783549 \n", "13871552 2.308409e+02 -15.467396 -15.474537 \n", "13882710 2.308409e+02 -15.467396 -15.474537 \n", "\n", "[13884033 rows x 5 columns]" ] }, "execution_count": 59, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = dataset.to_pandas()\n", "total_freq = df[\"freq\"].sum()\n", "tl_domains = set(df[\"top_level_domain\"])\n", "words_pr_domain = total_freq / len(tl_domains)\n", "\n", "df = df.groupby([\"word\", \"top_level_domain\"]).sum().reset_index()\n", "\n", "dfs = []\n", "for dom in tl_domains:\n", " print(dom)\n", " # break\n", " dom_df = df[df[\"top_level_domain\"] == dom]\n", " dom_total_freq = dom_df[\"freq\"].sum()\n", " dom_df[\"freq\"] = dom_df[\"freq\"] * words_pr_domain / dom_total_freq\n", " assert dom_df[\"freq\"].sum() - words_pr_domain < 1e-5\n", " dfs.append(dom_df)\n", "\n", "df = pd.concat(dfs)\n", "df[\"log_prob\"] = np.log(df[\"freq\"] / total_freq)\n", "df[\"log_prob_smoothed\"] = np.log((df[\"freq\"] + 1) / (total_freq + len(df)))\n", "\n", "# check that the total freq is the same\n", "assert df[\"freq\"].sum() - total_freq < 1e-5\n", "# check that the total freq is the same pr domain\n", "print(df.groupby(\"top_level_domain\")[\"freq\"].sum())\n", "\n", "# inspect\n", "df" ] }, { "cell_type": "code", "execution_count": 60, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Using custom data configuration default-dde703a9c875a737\n", "/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", " warnings.warn(\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Downloading and preparing dataset csv/default to /home/kenneth/.cache/huggingface/datasets/csv/default-dde703a9c875a737/0.0.0...\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Downloading data files: 100%|██████████| 1/1 [00:00<00:00, 2280.75it/s]\n", "Extracting data files: 100%|██████████| 1/1 [00:00<00:00, 569.72it/s]\n", "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", " return pd.read_csv(xopen(filepath_or_buffer, \"rb\", use_auth_token=use_auth_token), **kwargs)\n", " \r" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Dataset csv downloaded and prepared to /home/kenneth/.cache/huggingface/datasets/csv/default-dde703a9c875a737/0.0.0. Subsequent calls will reuse this data.\n" ] } ], "source": [ "# normalized = Dataset.from_pandas(df, info=info)\n", "\n", "# save to csv\n", "df.to_csv(\"danish_word_freqs_normalized.csv\", index=False)\n", "normalized = Dataset.from_csv(\"danish_word_freqs_normalized.csv\")" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Upload to Huggingface Hub" ] }, { "cell_type": "code", "execution_count": 61, "metadata": {}, "outputs": [], "source": [ "ds_dict = DatasetDict({\n", " \"word_frequencies\": word_frequencies,\n", " \"by_domain\": by_domain,\n", " \"with_pos\": with_pos,\n", " \"normalized\": normalized,\n", "})" ] }, { "cell_type": "code", "execution_count": 64, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Pushing dataset shards to the dataset hub: 100%|██████████| 1/1 [00:18<00:00, 18.75s/it]\n" ] } ], "source": [ "word_frequencies.push_to_hub(\"chcaa/dagw-word-frequencies\")" ] }, { "cell_type": "code", "execution_count": 65, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Pushing dataset shards to the dataset hub: 100%|██████████| 3/3 [00:36<00:00, 12.04s/it]\n" ] } ], "source": [ "by_domain.push_to_hub(\"chcaa/dagw-word-frequencies-by-domain\")" ] }, { "cell_type": "code", "execution_count": 66, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Pushing dataset shards to the dataset hub: 100%|██████████| 3/3 [00:38<00:00, 12.80s/it]\n" ] } ], "source": [ "with_pos.push_to_hub(\"chcaa/dagw-word-frequencies-by-domain-with-pos-tags\")" ] }, { "cell_type": "code", "execution_count": 67, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Pushing dataset shards to the dataset hub: 100%|██████████| 2/2 [00:27<00:00, 13.59s/it]\n" ] } ], "source": [ "normalized.push_to_hub(\"chcaa/dagw-word-frequencies-normalized-by-domain\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "word_freq", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.13" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "c10b2b53a6cd3acf03ed810a769e61720ca332994d31c08dc7197a28d260da6e" } } }, "nbformat": 4, "nbformat_minor": 2 }