File size: 14,568 Bytes
38f47f6
 
 
 
46c14a5
38f47f6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b879b12
 
38f47f6
 
b879b12
38f47f6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4cbbb88
38f47f6
 
4cbbb88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38f47f6
 
 
 
 
b879b12
 
 
38f47f6
 
 
 
 
 
46c14a5
b879b12
4cbbb88
38f47f6
4cbbb88
 
 
 
 
 
 
 
38f47f6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "056aa255-fda1-4cde-be24-459f6ad2c8b9",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/usr/local/anaconda3/lib/python3.8/site-packages/IPython/core/interactiveshell.py:3165: DtypeWarning: Columns (4) have mixed types.Specify dtype option on import or set low_memory=False.\n",
      "  has_raised = await self.run_ast_nodes(code_ast.body, cell_name,\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "df = pd.read_csv('raw/bq-results-20211206-133858-irtkgx60el7i.csv').drop(['ParentUrl', 'ParentAuthor', 'ParentTime', 'ParentScore'], axis=1)\n",
    "\n",
    "# There's a mix of HTML, sanitized links and raw Unicode that we'd like to clean up\n",
    "df.text = df.text.str.replace('<p>', '\\n')\n",
    "strings_to_remove = ['rel=\"nofollow\"', '<pre>', '</pre>', '<i>', '</i>', '<code>', '</code>', '&gt;']\n",
    "email_regex = '[a-zA-Z0-9._-]{0,30}@[a-zA-Z0-9._-]{0,20}\\.[a-zA-Z0-9_-]{2,3}' # for redacting emails\n",
    "munged_url_regex = 'http(s)?:\\&\\#.*?\\<\\/a>'\n",
    "\n",
    "for string in strings_to_remove:\n",
    "    df.text = df.text.str.replace(string, '')\n",
    "\n",
    "\n",
    "df.text = df.text.replace(email_regex, 'REDACTED_EMAIL', regex=True)\n",
    "df.text = df.text.replace(munged_url_regex, '', regex=True)\n",
    "\n",
    "    # fix some unicode issues\n",
    "df.text = df.text.str.replace('&#x27;', \"'\")\n",
    "df.text = df.text.str.replace('&#x2F;', \"/\")\n",
    "df.text = df.text.str.replace(\"&quot;\", '\"')\n",
    "\n",
    "hiring_df = df[df.ParentTitle.str.lower().str.contains('who is hiring')]\n",
    "wants_to_be_hired_df = df[df.ParentTitle.str.lower().str.contains('wants to be hired')]\n",
    "freelancer_df = df[df.ParentTitle.str.lower().str.contains('freelancer')]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "57ca7c96-d94c-4e65-8113-da7729558247",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/dan.becker/Desktop/hackernews_hiring_dataset/. is already a clone of https://huggingface.co/datasets/dansbecker/hackernews_hiring_posts. Make sure you pull the latest changes with `repo.git_pull()`.\n",
      "Several commits (5) will be pushed upstream.\n",
      "The progress bars may be unreliable.\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "63ddc30f9ba5420faf6e34f6fa7144fc",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Upload file data/hiring/dataset.arrow:   0%|          | 32.0k/78.2M [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "be96819a155b4f17933d3ff82a2fb70d",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Upload file data/wants_to_be_hired/dataset.arrow:   0%|          | 32.0k/10.8M [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "3ef183014a04462e97153ca6673c5f11",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Upload file data/freelancer/dataset.arrow:   0%|          | 32.0k/10.6M [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "remote: ----------------------------------------------------------\u001b[33m        \n",
      "remote: Your push was accepted, but with warnings:        \n",
      "remote: - warning : empty or missing yaml metadata in card (dansbecker/hackernews_hiring_posts)        \n",
      "remote: help: please find help at https://huggingface.co/docs/hub/model-repos\u001b[32m        \n",
      "remote: ----------------------------------------------------------        \n",
      "remote: Please find the documentation at:        \n",
      "remote: https://huggingface.co/docs/hub/model-repos\u001b(B\u001b[m        \n",
      "remote: ----------------------------------------------------------        \n",
      "remote: -------------------------------------------------------------------------\u001b[31m        \n",
      "remote: Your push was rejected because it contains files larger than 10M.        \n",
      "remote: Please use https://git-lfs.github.com/ to store larger files.\u001b(B\u001b[m        \n",
      "remote: -------------------------------------------------------------------------        \n",
      "remote: Offending files:        \n",
      "remote:  - raw/bq-results-20211206-133858-irtkgx60el7i.csv (ref: refs/heads/main)        \n",
      "To https://huggingface.co/datasets/dansbecker/hackernews_hiring_posts\n",
      " ! [remote rejected] main -> main (pre-receive hook declined)\n",
      "error: failed to push some refs to 'https://huggingface.co/datasets/dansbecker/hackernews_hiring_posts'\n",
      "\n"
     ]
    },
    {
     "ename": "OSError",
     "evalue": "remote: ----------------------------------------------------------\u001b[33m        \nremote: Your push was accepted, but with warnings:        \nremote: - warning : empty or missing yaml metadata in card (dansbecker/hackernews_hiring_posts)        \nremote: help: please find help at https://huggingface.co/docs/hub/model-repos\u001b[32m        \nremote: ----------------------------------------------------------        \nremote: Please find the documentation at:        \nremote: https://huggingface.co/docs/hub/model-repos\u001b(B\u001b[m        \nremote: ----------------------------------------------------------        \nremote: -------------------------------------------------------------------------\u001b[31m        \nremote: Your push was rejected because it contains files larger than 10M.        \nremote: Please use https://git-lfs.github.com/ to store larger files.\u001b(B\u001b[m        \nremote: -------------------------------------------------------------------------        \nremote: Offending files:        \nremote:  - raw/bq-results-20211206-133858-irtkgx60el7i.csv (ref: refs/heads/main)        \nTo https://huggingface.co/datasets/dansbecker/hackernews_hiring_posts\n ! [remote rejected] main -> main (pre-receive hook declined)\nerror: failed to push some refs to 'https://huggingface.co/datasets/dansbecker/hackernews_hiring_posts'\n",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mCalledProcessError\u001b[0m                        Traceback (most recent call last)",
      "\u001b[0;32m/usr/local/anaconda3/lib/python3.8/site-packages/huggingface_hub/repository.py\u001b[0m in \u001b[0;36mgit_push\u001b[0;34m(self, upstream, blocking, auto_lfs_prune)\u001b[0m\n\u001b[1;32m    998\u001b[0m                     \u001b[0;32mif\u001b[0m \u001b[0mreturn_code\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 999\u001b[0;31m                         raise subprocess.CalledProcessError(\n\u001b[0m\u001b[1;32m   1000\u001b[0m                             \u001b[0mreturn_code\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mprocess\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moutput\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mstdout\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstderr\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mstderr\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mCalledProcessError\u001b[0m: Command '['git', 'push', '--set-upstream', 'origin', 'main']' returned non-zero exit status 1.",
      "\nDuring handling of the above exception, another exception occurred:\n",
      "\u001b[0;31mOSError\u001b[0m                                   Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-2-38e9608c0524>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m     14\u001b[0m \u001b[0mrepo\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgit_add\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'*.ipynb'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     15\u001b[0m \u001b[0mrepo\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgit_add\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'README.md'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 16\u001b[0;31m \u001b[0mrepo\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpush_to_hub\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcommit_message\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'Regular update'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mblocking\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mclean_ok\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;32m/usr/local/anaconda3/lib/python3.8/site-packages/huggingface_hub/repository.py\u001b[0m in \u001b[0;36mpush_to_hub\u001b[0;34m(self, commit_message, blocking, clean_ok, auto_lfs_prune)\u001b[0m\n\u001b[1;32m   1230\u001b[0m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgit_add\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mauto_lfs_track\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1231\u001b[0m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgit_commit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcommit_message\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1232\u001b[0;31m         return self.git_push(\n\u001b[0m\u001b[1;32m   1233\u001b[0m             \u001b[0mupstream\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34mf\"origin {self.current_branch}\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1234\u001b[0m             \u001b[0mblocking\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mblocking\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/anaconda3/lib/python3.8/site-packages/huggingface_hub/repository.py\u001b[0m in \u001b[0;36mgit_push\u001b[0;34m(self, upstream, blocking, auto_lfs_prune)\u001b[0m\n\u001b[1;32m   1002\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1003\u001b[0m         \u001b[0;32mexcept\u001b[0m \u001b[0msubprocess\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mCalledProcessError\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mexc\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1004\u001b[0;31m             \u001b[0;32mraise\u001b[0m \u001b[0mEnvironmentError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mexc\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstderr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1005\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1006\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mblocking\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mOSError\u001b[0m: remote: ----------------------------------------------------------\u001b[33m        \nremote: Your push was accepted, but with warnings:        \nremote: - warning : empty or missing yaml metadata in card (dansbecker/hackernews_hiring_posts)        \nremote: help: please find help at https://huggingface.co/docs/hub/model-repos\u001b[32m        \nremote: ----------------------------------------------------------        \nremote: Please find the documentation at:        \nremote: https://huggingface.co/docs/hub/model-repos\u001b(B\u001b[m        \nremote: ----------------------------------------------------------        \nremote: -------------------------------------------------------------------------\u001b[31m        \nremote: Your push was rejected because it contains files larger than 10M.        \nremote: Please use https://git-lfs.github.com/ to store larger files.\u001b(B\u001b[m        \nremote: -------------------------------------------------------------------------        \nremote: Offending files:        \nremote:  - raw/bq-results-20211206-133858-irtkgx60el7i.csv (ref: refs/heads/main)        \nTo https://huggingface.co/datasets/dansbecker/hackernews_hiring_posts\n ! [remote rejected] main -> main (pre-receive hook declined)\nerror: failed to push some refs to 'https://huggingface.co/datasets/dansbecker/hackernews_hiring_posts'\n"
     ]
    }
   ],
   "source": [
    "import datasets\n",
    "from huggingface_hub import create_repo\n",
    "from huggingface_hub import Repository\n",
    "\n",
    "all_datasets = datasets.dataset_dict.DatasetDict({'hiring': datasets.Dataset.from_pandas(hiring_df).remove_columns('__index_level_0__'),\n",
    "                                                  'wants_to_be_hired': datasets.Dataset.from_pandas(wants_to_be_hired_df).remove_columns('__index_level_0__'),\n",
    "                                                  'freelancer': datasets.Dataset.from_pandas(freelancer_df).remove_columns('__index_level_0__')})\n",
    "data_path = './data'\n",
    "all_datasets.save_to_disk(data_path)\n",
    "\n",
    "repo_url = 'https://huggingface.co/datasets/dansbecker/hackernews_hiring_posts'\n",
    "repo = Repository(local_dir=\".\", clone_from=repo_url)\n",
    "repo.git_add(data_path)\n",
    "repo.git_add('*.ipynb')\n",
    "repo.git_add('README.md')\n",
    "repo.push_to_hub(commit_message='Regular update', blocking=True, clean_ok=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "960641f2-7844-44d7-a8bd-acc3c12ced07",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}