ola13 commited on
Commit
d0b26e9
1 Parent(s): c92549e
Files changed (3) hide show
  1. .gitignore +2 -1
  2. app.py +44 -15
  3. test.ipynb +65 -40
.gitignore CHANGED
@@ -1,2 +1,3 @@
1
  .ipynb_checkpoints/
2
- report.jsonl
 
 
1
  .ipynb_checkpoints/
2
+ report.jsonl
3
+ data/commoncrawl_en_dedup_all_features/
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import math
2
  import os
3
  import random
@@ -83,6 +84,8 @@ def send_report(sample, dataset, reason, annotator, campaign):
83
  text_col = "content"
84
  text = sample[text_col]
85
  sample.pop(text_col)
 
 
86
 
87
  sample_id = ""
88
  if "id" not in sample:
@@ -97,7 +100,7 @@ def send_report(sample, dataset, reason, annotator, campaign):
97
  "dataset": dataset,
98
  "docid": sample_id,
99
  "text": text,
100
- "metadata": sample,
101
  "reason": reason,
102
  "annotator": annotator,
103
  "campaign": campaign,
@@ -115,9 +118,30 @@ def send_report(sample, dataset, reason, annotator, campaign):
115
  )
116
 
117
 
118
- description = """
119
- GecLM annotations. All annotations are recorded in the [data_feedback](https://huggingface.co/datasets/HuggingFaceGECLM/data_feedback) dataset.
120
- """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
 
122
 
123
  if __name__ == "__main__":
@@ -126,7 +150,10 @@ if __name__ == "__main__":
126
  with demo:
127
  current_sample_state = gr.State(dict())
128
 
129
- description = gr.Markdown(value=description)
 
 
 
130
  with gr.Row():
131
  annotator = gr.Textbox(
132
  lines=1,
@@ -161,15 +188,16 @@ if __name__ == "__main__":
161
  def get_next_line(dataset):
162
  try:
163
  next_line = next(line_generators_s3[dataset])
164
- text_col = "text"
165
- if text_col not in next_line:
166
- text_col = "content"
167
- text = next_line[text_col]
168
  except StopIteration:
169
  text = LABELLING_COMPLETE_TEXT.format(dataset)
170
  next_line = text
171
  return [
172
- gr.update(value=text, visible=True),
 
 
 
 
173
  next_line,
174
  gr.update(visible=True),
175
  gr.update(visible=True),
@@ -182,15 +210,16 @@ if __name__ == "__main__":
182
 
183
  try:
184
  next_line = next(line_generators_s3[dataset])
185
- text_col = "text"
186
- if text_col not in next_line:
187
- text_col = "content"
188
- text = next_line[text_col]
189
  except StopIteration:
190
  text = LABELLING_COMPLETE_TEXT.format(dataset)
191
  next_line = text
192
  return [
193
- text,
 
 
 
 
194
  gr.update(
195
  value="",
196
  placeholder="Provide the reason for flagging if you think the sample is bad.",
 
1
+ import json
2
  import math
3
  import os
4
  import random
 
84
  text_col = "content"
85
  text = sample[text_col]
86
  sample.pop(text_col)
87
+ if "record_timestamp" in sample:
88
+ sample.pop("record_timestamp")
89
 
90
  sample_id = ""
91
  if "id" not in sample:
 
100
  "dataset": dataset,
101
  "docid": sample_id,
102
  "text": text,
103
+ "metadata": json.dumps(sample),
104
  "reason": reason,
105
  "annotator": annotator,
106
  "campaign": campaign,
 
118
  )
119
 
120
 
121
+ def get_title_and_text_for_line(next_line):
122
+ text_col = "text"
123
+ if text_col not in next_line:
124
+ text_col = "content"
125
+ text = next_line[text_col]
126
+
127
+ label = ""
128
+ if "title" in next_line:
129
+ label = next_line["title"]
130
+ if "url" in next_line:
131
+ label += " | " + next_line["url"]
132
+ elif "metadata" in next_line:
133
+ if next_line["metadata"] is not None:
134
+ print(next_line["metadata"])
135
+ if isinstance(next_line["metadata"], list) and len(next_line["metadata"]) > 0:
136
+ label = next_line["metadata"][0]
137
+ elif isinstance(next_line["metadata"], str):
138
+ metadata = json.loads(next_line["metadata"])
139
+ if "document_url" in metadata:
140
+ label = metadata["document_url"]
141
+ elif "url" in next_line:
142
+ label = next_line["url"]
143
+
144
+ return text, label
145
 
146
 
147
  if __name__ == "__main__":
 
150
  with demo:
151
  current_sample_state = gr.State(dict())
152
 
153
+ description = gr.Markdown(
154
+ value="""GecLM annotations. All annotations are recorded in the [data_feedback](https://huggingface.co/datasets/HuggingFaceGECLM/data_feedback) dataset.
155
+ """,
156
+ )
157
  with gr.Row():
158
  annotator = gr.Textbox(
159
  lines=1,
 
188
  def get_next_line(dataset):
189
  try:
190
  next_line = next(line_generators_s3[dataset])
191
+ text, label = get_title_and_text_for_line(next_line)
 
 
 
192
  except StopIteration:
193
  text = LABELLING_COMPLETE_TEXT.format(dataset)
194
  next_line = text
195
  return [
196
+ gr.update(
197
+ value=text,
198
+ visible=True,
199
+ label=label,
200
+ ),
201
  next_line,
202
  gr.update(visible=True),
203
  gr.update(visible=True),
 
210
 
211
  try:
212
  next_line = next(line_generators_s3[dataset])
213
+ text, label = get_title_and_text_for_line(next_line)
 
 
 
214
  except StopIteration:
215
  text = LABELLING_COMPLETE_TEXT.format(dataset)
216
  next_line = text
217
  return [
218
+ gr.update(
219
+ value=text,
220
+ visible=True,
221
+ label=label,
222
+ ),
223
  gr.update(
224
  value="",
225
  placeholder="Provide the reason for flagging if you think the sample is bad.",
test.ipynb CHANGED
@@ -1,15 +1,5 @@
1
  {
2
  "cells": [
3
- {
4
- "cell_type": "code",
5
- "execution_count": 11,
6
- "id": "8955cb73",
7
- "metadata": {},
8
- "outputs": [],
9
- "source": [
10
- "os.environ[\"geclm_token\"] = \"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\""
11
- ]
12
- },
13
  {
14
  "cell_type": "code",
15
  "execution_count": null,
@@ -21,27 +11,27 @@
21
  "output_type": "stream",
22
  "text": [
23
  "Number of parquet files 30\n",
24
- "Reading geclm-datasets/samples/c4/20230404_102105_00007_t8w9z_5dddd9ff-0020-4e23-8621-614fe1c82cec\n",
25
  "Number of parquet files 30\n",
26
- "Reading geclm-datasets/samples/bigcode_python_code/20230404_102116_00007_ajvns_6d261b8b-12bb-4ca9-a406-1645f2e31af7\n",
27
  "Number of parquet files 30\n",
28
- "Reading geclm-datasets/samples/bigcode_python_github_issues/20230404_102127_00022_yv77i_2d0f6685-c3b8-4b16-b7bd-5b47e6938102\n",
29
  "Number of parquet files 30\n",
30
- "Reading geclm-datasets/samples/bigcode_python_jupyter_markdowned_clean_dedup/20230404_102137_00026_vwcg7_79f2fc1b-a99c-4ef2-9d73-690ee3157f7b\n",
31
  "Number of parquet files 30\n",
32
- "Reading geclm-datasets/samples/books3/20230404_102143_00027_t4kwf_326b263c-d184-42d3-a1bc-833e0c7cd8c6\n",
33
  "Number of parquet files 30\n",
34
- "Reading geclm-datasets/samples/gutenberg_raw/20230404_102215_00007_x3ntt_eb8e349d-2806-4bef-81dd-8f3b951eec1f\n",
35
  "Number of parquet files 30\n",
36
- "Reading geclm-datasets/samples/reddit_threaded/20230404_102241_00049_xj4uk_3c4761ee-2dbb-493b-ba2f-35a1da79cd45\n",
37
  "Number of parquet files 30\n",
38
- "Reading geclm-datasets/samples/enwiki_data/20230404_102246_00007_ye63c_dc22902c-9d73-426c-9091-4c93f22fee5d\n",
39
  "Number of parquet files 30\n",
40
- "Reading geclm-datasets/samples/s2orc_dedup/20230404_102252_00080_6ce5q_96d31fe2-9f5e-4632-9905-6d37a0c07ec3\n",
41
  "Number of parquet files 30\n",
42
- "Reading geclm-datasets/samples/stackexchange2/20230404_102308_00031_qvnh6_ebca5822-7684-47af-bdac-670001d5a92a\n",
43
  "Number of parquet files 30\n",
44
- "Reading geclm-datasets/samples/commoncrawl/20230404_124237_00026_sin5w_1278b6e7-4f3e-49b3-9a8e-9cea3f20eadb\n",
45
  "Running on local URL: http://127.0.0.1:7860\n",
46
  "\n",
47
  "To create a public link, set `share=True` in `launch()`.\n"
@@ -58,9 +48,17 @@
58
  },
59
  "metadata": {},
60
  "output_type": "display_data"
 
 
 
 
 
 
 
61
  }
62
  ],
63
  "source": [
 
64
  "import math\n",
65
  "import os\n",
66
  "import random\n",
@@ -96,7 +94,7 @@
96
  "]\n",
97
  "\n",
98
  "\n",
99
- "def get_parquet_lines(dataset, sample_size=10):\n",
100
  " s3_paths = S3.glob(BASE_S3_DIR + dataset + \"/*\")\n",
101
  "\n",
102
  " if len(s3_paths) == 0:\n",
@@ -141,11 +139,14 @@
141
  "\n",
142
  "\n",
143
  "def send_report(sample, dataset, reason, annotator, campaign):\n",
 
144
  " text_col = \"text\"\n",
145
  " if text_col not in sample:\n",
146
  " text_col = \"content\"\n",
147
  " text = sample[text_col]\n",
148
  " sample.pop(text_col)\n",
 
 
149
  "\n",
150
  " sample_id = \"\"\n",
151
  " if \"id\" not in sample:\n",
@@ -160,7 +161,7 @@
160
  " \"dataset\": dataset,\n",
161
  " \"docid\": sample_id,\n",
162
  " \"text\": text,\n",
163
- " \"metadata\": sample,\n",
164
  " \"reason\": reason,\n",
165
  " \"annotator\": annotator,\n",
166
  " \"campaign\": campaign,\n",
@@ -178,9 +179,30 @@
178
  " )\n",
179
  "\n",
180
  "\n",
181
- "description = \"\"\"\n",
182
- "GecLM annotations. All annotations are recorded in the [data_feedback](https://huggingface.co/datasets/HuggingFaceGECLM/data_feedback) dataset.\n",
183
- "\"\"\"\n",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
  "\n",
185
  "\n",
186
  "if __name__ == \"__main__\":\n",
@@ -189,7 +211,10 @@
189
  " with demo:\n",
190
  " current_sample_state = gr.State(dict())\n",
191
  "\n",
192
- " description = gr.Markdown(value=description)\n",
 
 
 
193
  " with gr.Row():\n",
194
  " annotator = gr.Textbox(\n",
195
  " lines=1,\n",
@@ -222,18 +247,18 @@
222
  " text = gr.Textbox(visible=False, label=\"Datapoint\", lines=500, max_lines=500)\n",
223
  "\n",
224
  " def get_next_line(dataset):\n",
225
- " text = \"\"\n",
226
  " try:\n",
227
  " next_line = next(line_generators_s3[dataset])\n",
228
- " text_col = \"text\"\n",
229
- " if text_col not in next_line:\n",
230
- " text_col = \"content\"\n",
231
- " text = next_line[text_col]\n",
232
  " except StopIteration:\n",
233
  " text = LABELLING_COMPLETE_TEXT.format(dataset)\n",
234
  " next_line = text\n",
235
  " return [\n",
236
- " gr.update(value=text, visible=True),\n",
 
 
 
 
237
  " next_line,\n",
238
  " gr.update(visible=True),\n",
239
  " gr.update(visible=True),\n",
@@ -244,23 +269,23 @@
244
  " if current_sample != LABELLING_COMPLETE_TEXT.format(dataset):\n",
245
  " send_report(current_sample, dataset, reason, annotator, campaign)\n",
246
  "\n",
247
- " text = \"\"\n",
248
  " try:\n",
249
  " next_line = next(line_generators_s3[dataset])\n",
250
- " text_col = \"text\"\n",
251
- " if text_col not in next_line:\n",
252
- " text_col = \"content\"\n",
253
- " text = next_line[text_col]\n",
254
  " except StopIteration:\n",
255
  " text = LABELLING_COMPLETE_TEXT.format(dataset)\n",
256
  " next_line = text\n",
257
  " return [\n",
258
- " text,\n",
 
 
 
 
259
  " gr.update(\n",
260
  " value=\"\",\n",
261
  " placeholder=\"Provide the reason for flagging if you think the sample is bad.\",\n",
262
  " ),\n",
263
- " text,\n",
264
  " ]\n",
265
  "\n",
266
  " good_btn.click(\n",
 
1
  {
2
  "cells": [
 
 
 
 
 
 
 
 
 
 
3
  {
4
  "cell_type": "code",
5
  "execution_count": null,
 
11
  "output_type": "stream",
12
  "text": [
13
  "Number of parquet files 30\n",
14
+ "Reading geclm-datasets/samples/c4/20230404_102105_00007_t8w9z_da4e86ed-bac9-440c-ae5e-29e551e62ec0\n",
15
  "Number of parquet files 30\n",
16
+ "Reading geclm-datasets/samples/bigcode_python_code/20230404_102116_00007_ajvns_2a7caa57-9adc-48f6-900e-f87f572f8c3b\n",
17
  "Number of parquet files 30\n",
18
+ "Reading geclm-datasets/samples/bigcode_python_github_issues/20230404_102127_00022_yv77i_4b3257ed-3e44-4961-bd02-017d135e96f0\n",
19
  "Number of parquet files 30\n",
20
+ "Reading geclm-datasets/samples/bigcode_python_jupyter_markdowned_clean_dedup/20230404_102137_00026_vwcg7_8778ba21-a464-4949-8d71-aa1414a45d3c\n",
21
  "Number of parquet files 30\n",
22
+ "Reading geclm-datasets/samples/books3/20230404_102143_00027_t4kwf_b39fa726-6484-4103-a9a3-fd8774796e75\n",
23
  "Number of parquet files 30\n",
24
+ "Reading geclm-datasets/samples/gutenberg_raw/20230404_102215_00007_x3ntt_ddbaef74-459c-40a0-8b8f-d2f17af55991\n",
25
  "Number of parquet files 30\n",
26
+ "Reading geclm-datasets/samples/reddit_threaded/20230404_102241_00049_xj4uk_61f1e105-1765-4c37-a659-5895ca3398e2\n",
27
  "Number of parquet files 30\n",
28
+ "Reading geclm-datasets/samples/enwiki_data/20230404_102246_00007_ye63c_c3bd1037-1438-4ab3-97cd-24fd8ede501a\n",
29
  "Number of parquet files 30\n",
30
+ "Reading geclm-datasets/samples/s2orc_dedup/20230404_102252_00080_6ce5q_c45e4ff8-83fe-4b65-b5ae-f52e2b27e96c\n",
31
  "Number of parquet files 30\n",
32
+ "Reading geclm-datasets/samples/stackexchange2/20230404_102308_00031_qvnh6_fc1b4f61-9b84-481f-95bc-d7e0b8542030\n",
33
  "Number of parquet files 30\n",
34
+ "Reading geclm-datasets/samples/commoncrawl/20230404_124237_00026_sin5w_96df9c84-d8b3-454c-a3ce-ad9550da36bc\n",
35
  "Running on local URL: http://127.0.0.1:7860\n",
36
  "\n",
37
  "To create a public link, set `share=True` in `launch()`.\n"
 
48
  },
49
  "metadata": {},
50
  "output_type": "display_data"
51
+ },
52
+ {
53
+ "name": "stdout",
54
+ "output_type": "stream",
55
+ "text": [
56
+ "{'record_id': 'd80741ab-54df-4bb9-b566-0855bb1c7e87', 'crawl': 'CC-MAIN-2022-05', 'date': '20220121', 'segment': '1642320302715.38', 'warc_path': 'crawl-data/CC-MAIN-2022-05/segments/1642320302715.38/warc/CC-MAIN-20220121010736-20220121040736-00393.warc.gz', 'record_timestamp': Timestamp('2022-01-21 03:09:58'), 'title': \"CYLQ Speed Skating Shoes for Adult Professional Performance Japan's largest assortment High\", 'text': \"Speed,$162,Shoes,Skating,/heptarchy1466806.html,Performance,CYLQ,High,contgraf.com.br,Professional,Sports Outdoors , Outdoor Recreation,Adult,for Speed,$162,Shoes,Skating,/heptarchy1466806.html,Performance,CYLQ,High,contgraf.com.br,Professional,Sports Outdoors , Outdoor Recreation,Adult,for CYLQ Speed Skating Shoes for Adult Professional Performance Japan's largest assortment High $162 CYLQ Speed Skating Shoes for Adult Professional High Performance Sports Outdoors Outdoor Recreation CYLQ Speed Skating Shoes for Adult Professional Performance Japan's largest assortment High $162 CYLQ Speed Skating Shoes for Adult Professional High Performance Sports Outdoors Outdoor Recreation\\n\\nCYLQ Speed Skating Shoes for Adult Professional High Performance\\n\\n$162\\n\\nCYLQ Speed Skating Shoes for Adult Professional High Performance\\n\\n * Make sure this fits by entering your model number.\\n * ã\\x80\\x90Inline Speed Skatesã\\x80\\x91: Adults Buy According To The Size Of The Usual Sports Shoes, If Your Feet Are Fat Or Novice, It Is Recommended To Buy Shoes That Are 1 Size Larger!\\n * ã\\x80\\x90Performanceã\\x80\\x91: High-Elastic And Wear-Resistant Pu Wheelï¼\\x8cPrecision Bearing, One-Piece Bracket, One-Piece Molding, So That You Can Enjoy The Smooth, Quick And Comfortable Ride\\n * ã\\x80\\x90High-Elastic Wear-Resistant Pu Wheelsã\\x80\\x91: 85a High-Elastic Wear-Resistant Wheels, Eu30-Eu33: 4 * 90mm, Eu34-Eu37: 4 * 100mm, Eu38-Eu45: 4 * 110mm For Better Wear And Moderate Speed\\n * ã\\x80\\x90Perfect Giftsã\\x80\\x91: Inline Skates Are Popular With Children And Adults, You Can Give It To Your Friends And Family As A Gift On Major Holidays Or Birthdays, They Will All Like It Very Much\\n * ã\\x80\\x90Enjoy Skatingã\\x80\\x91: The Perfect Fit, A High Degree Of Comfort, And Smooth Handling Make The Inline Roller Skates Ideal For All Sports-Loving Children, Beginners And Skaters.\\n\\n|||\\n\\nCYLQ Speed Skating Shoes for Adult Professional High Performance\\n\\nDonate to help us beat cancer\\n\\nGet involved and support cancer research\\n\\nCancer is relentless. But so are we.\\u200b Whether you fundraise, volunteer, pledge to leave a Gift in your Will or donate, everyone has a part to play. And every part supports life-saving research. Play your part and together we will beat cancer.\\u200b\\n\\nIf you've been diagnosed with cancer, or know someone who has, we provide practical advice on everything from symptoms and screening, to coping after treatment.\\n\\nIt’s a worrying time for many people and we want to be there for you whenever - and wherever - you need us. Cancer Chat is our fully moderated forum where you can talk to others affected by cancer, share experiences, and get support. Cancer Chat is free to join and available 24 hours a day.\", 'tokens': ['speed', '162', 'shoes', 'skating', 'heptarchy1466806', 'html', 'performance', 'cylq', 'high', 'contgraf', 'com', 'br', 'professional', 'sports', 'outdoors', 'outdoor', 'recreation', 'adult', 'for', 'speed', '162', 'shoes', 'skating', 'heptarchy1466806', 'html', 'performance', 'cylq', 'high', 'contgraf', 'com', 'br', 'professional', 'sports', 'outdoors', 'outdoor', 'recreation', 'adult', 'for', 'cylq', 'speed', 'skating', 'shoes', 'for', 'adult', 'professional', 'performance', 'japan', 's', 'largest', 'assortment', 'high', '162', 'cylq', 'speed', 'skating', 'shoes', 'for', 'adult', 'professional', 'high', 'performance', 'sports', 'outdoors', 'outdoor', 'recreation', 'cylq', 'speed', 'skating', 'shoes', 'for', 'adult', 'professional', 'performance', 'japan', 's', 'largest', 'assortment', 'high', '162', 'cylq', 'speed', 'skating', 'shoes', 'for', 'adult', 'professional', 'high', 'performance', 'sports', 'outdoors', 'outdoor', 'recreation', 'cylq', 'speed', 'skating', 'shoes', 'for', 'adult', 'professional', 'high', 'performance', '162', 'cylq', 'speed', 'skating', 'shoes', 'for', 'adult', 'professional', 'high', 'performance', 'make', 'sure', 'this', 'fits', 'by', 'entering', 'your', 'model', 'number', 'ã', 'inline', 'speed', 'skatesã', 'adults', 'buy', 'according', 'to', 'the', 'size', 'of', 'the', 'usual', 'sports', 'shoes', 'if', 'your', 'feet', 'are', 'fat', 'or', 'novice', 'it', 'is', 'recommended', 'to', 'buy', 'shoes', 'that', 'are', '1', 'size', 'larger', 'ã', 'performanceã', 'high', 'elastic', 'and', 'wear', 'resistant', 'pu', 'wheelï¼', 'precision', 'bearing', 'one', 'piece', 'bracket', 'one', 'piece', 'molding', 'so', 'that', 'you', 'can', 'enjoy', 'the', 'smooth', 'quick', 'and', 'comfortable', 'ride', 'ã', 'high', 'elastic', 'wear', 'resistant', 'pu', 'wheelsã', '85a', 'high', 'elastic', 'wear', 'resistant', 'wheels', 'eu30', 'eu33', '4', '90mm', 'eu34', 'eu37', '4', '100mm', 'eu38', 'eu45', '4', '110mm', 'for', 'better', 'wear', 'and', 'moderate', 'speed', 'ã', 'perfect', 'giftsã', 'inline', 'skates', 'are', 'popular', 'with', 'children', 'and', 'adults', 'you', 'can', 'give', 'it', 'to', 'your', 'friends', 'and', 'family', 'as', 'a', 'gift', 'on', 'major', 'holidays', 'or', 'birthdays', 'they', 'will', 'all', 'like', 'it', 'very', 'much', 'ã', 'enjoy', 'skatingã', 'the', 'perfect', 'fit', 'a', 'high', 'degree', 'of', 'comfort', 'and', 'smooth', 'handling', 'make', 'the', 'inline', 'roller', 'skates', 'ideal', 'for', 'all', 'sports', 'loving', 'children', 'beginners', 'and', 'skaters', 'cylq', 'speed', 'skating', 'shoes', 'for', 'adult', 'professional', 'high', 'performance', 'donate', 'to', 'help', 'us', 'beat', 'cancer', 'get', 'involved', 'and', 'support', 'cancer', 'research', 'cancer', 'is', 'relentless', 'but', 'so', 'are', 'we', 'whether', 'you', 'fundraise', 'volunteer', 'pledge', 'to', 'leave', 'a', 'gift', 'in', 'your', 'will', 'or', 'donate', 'everyone', 'has', 'a', 'part', 'to', 'play', 'and', 'every', 'part', 'supports', 'life', 'saving', 'research', 'play', 'your', 'part', 'and', 'together', 'we', 'will', 'beat', 'cancer', 'if', 'you', 've', 'been', 'diagnosed', 'with', 'cancer', 'or', 'know', 'someone', 'who', 'has', 'we', 'provide', 'practical', 'advice', 'on', 'everything', 'from', 'symptoms', 'and', 'screening', 'to', 'coping', 'after', 'treatment', 'it', 's', 'a', 'worrying', 'time', 'for', 'many', 'people', 'and', 'we', 'want', 'to', 'be', 'there', 'for', 'you', 'whenever', 'and', 'wherever', 'you', 'need', 'us', 'cancer', 'chat', 'is', 'our', 'fully', 'moderated', 'forum', 'where', 'you', 'can', 'talk', 'to', 'others', 'affected', 'by', 'cancer', 'share', 'experiences', 'and', 'get', 'support', 'cancer', 'chat', 'is', 'free', 'to', 'join', 'and', 'available', '24', 'hours', 'a', 'day'], 'num_tokens': 420, 'language': 'en', 'lang_prob': 0.8244870901107788, 'warc_headers': [('WARC-Warcinfo-ID', '<urn:uuid:a976e930-019b-408f-adf8-425b0ee64b69>'), ('WARC-Payload-Digest', 'sha1:I3KVL3FTWZFX2Q4EXW5KTHT6H2KKVPGW'), ('WARC-IP-Address', '191.6.209.164'), ('WARC-Block-Digest', 'sha1:YAOSZBUDDYZAWSOA6C3Q7MQ2RGX7A32L'), ('WARC-Date', '2022-01-21T03:09:58Z'), ('Content-Type', 'application/http; msgtype=response'), ('WARC-Type', 'response'), ('WARC-Concurrent-To', '<urn:uuid:65bd6506-f28a-4ceb-9f6f-84243063aaaa>'), ('WARC-Identified-Payload-Type', 'text/html'), ('WARC-Record-ID', '<urn:uuid:d80741ab-54df-4bb9-b566-0855bb1c7e87>'), ('Content-Length', '60568'), ('WARC-Target-URI', 'http://contgraf.com.br/heptarchy1466806.html')], 'http_headers': [('Connection', 'Keep-Alive'), ('Keep-Alive', 'timeout=5, max=500'), ('Content-Type', 'text/html'), ('X-Crawler-Transfer-Encoding', 'chunked'), ('Date', 'Fri, 21 Jan 2022 03:09:57 GMT'), ('Vary', 'Accept-Encoding'), ('Server', 'Apache'), ('X-Crawler-Content-Encoding', 'gzip'), ('Content-Length', '60297')], 'mime_type': 'text/html', 'charset': 'UTF-8', 'url_surtkey': 'br,com,contgraf)/heptarchy1466806.html', 'url': 'http://contgraf.com.br/heptarchy1466806.html', 'url_host': 'contgraf.com.br', 'url_scheme': 'http', 'url_path': '/heptarchy1466806.html', 'text_len': 2646, 'avg_line_len': 154.05882263183594, 'avg_paragraph_len': 218.6666717529297, 'num_words': 420, 'bullet_lines_frac': 0.0, 'ellipsis_lines_frac': 0.0, 'avg_word_len': 5.019047737121582, 'hash_word_ratio': 0.0, 'ellipsis_word_ratio': 0.0, 'alpha_words_frac': 0.976190447807312, 'num_stopwords': 7, 'dupe_line_frac': 0.125, 'dupe_line_char_frac': 0.05065294727683067, 'dupe_par_frac': 0.1818181872367859, 'dupe_par_char_frac': 0.05065294727683067, 'top_dupe_2gram_char_frac': 0.02770083025097847, 'top_dupe_3gram_char_frac': 0.049861494451761246, 'top_dupe_4gram_char_frac': 0.06648199260234833, 'top_dupe_5gram_char_frac': 0.07756232470273972, 'top_dupe_6gram_char_frac': 0.0941828265786171, 'all_dupe_4gram_char_frac': 0.20419469475746155, 'all_dupe_5gram_char_frac': 0.17491096258163452, 'all_dupe_6gram_char_frac': 0.17609813809394836, 'all_dupe_7gram_char_frac': 0.17055797576904297, 'all_dupe_8gram_char_frac': 0.17530669271945953, 'all_dupe_9gram_char_frac': 0.2030075192451477, 'all_dupe_10gram_char_frac': 0.14087851345539093, 'q_logit': -3.212052583694458, 'q_probability': 0.03871467337012291}\n"
57
+ ]
58
  }
59
  ],
60
  "source": [
61
+ "import json\n",
62
  "import math\n",
63
  "import os\n",
64
  "import random\n",
 
94
  "]\n",
95
  "\n",
96
  "\n",
97
+ "def get_parquet_lines(dataset, sample_size=1000):\n",
98
  " s3_paths = S3.glob(BASE_S3_DIR + dataset + \"/*\")\n",
99
  "\n",
100
  " if len(s3_paths) == 0:\n",
 
139
  "\n",
140
  "\n",
141
  "def send_report(sample, dataset, reason, annotator, campaign):\n",
142
+ " print(sample)\n",
143
  " text_col = \"text\"\n",
144
  " if text_col not in sample:\n",
145
  " text_col = \"content\"\n",
146
  " text = sample[text_col]\n",
147
  " sample.pop(text_col)\n",
148
+ " if \"record_timestamp\" in sample:\n",
149
+ " sample.pop(\"record_timestamp\")\n",
150
  "\n",
151
  " sample_id = \"\"\n",
152
  " if \"id\" not in sample:\n",
 
161
  " \"dataset\": dataset,\n",
162
  " \"docid\": sample_id,\n",
163
  " \"text\": text,\n",
164
+ " \"metadata\": json.dumps(sample),\n",
165
  " \"reason\": reason,\n",
166
  " \"annotator\": annotator,\n",
167
  " \"campaign\": campaign,\n",
 
179
  " )\n",
180
  "\n",
181
  "\n",
182
+ "def get_title_and_text_for_line(next_line):\n",
183
+ " text_col = \"text\"\n",
184
+ " if text_col not in next_line:\n",
185
+ " text_col = \"content\"\n",
186
+ " text = next_line[text_col]\n",
187
+ "\n",
188
+ " label = \"\"\n",
189
+ " if \"title\" in next_line:\n",
190
+ " label = next_line[\"title\"]\n",
191
+ " if \"url\" in next_line:\n",
192
+ " label += \" | \" + next_line[\"url\"]\n",
193
+ " elif \"metadata\" in next_line:\n",
194
+ " if next_line[\"metadata\"] is not None:\n",
195
+ " print(next_line[\"metadata\"])\n",
196
+ " if isinstance(next_line[\"metadata\"], list) and len(next_line[\"metadata\"]) > 0:\n",
197
+ " label = next_line[\"metadata\"][0]\n",
198
+ " elif isinstance(next_line[\"metadata\"], str):\n",
199
+ " metadata = json.loads(next_line[\"metadata\"])\n",
200
+ " if \"document_url\" in metadata:\n",
201
+ " label = metadata[\"document_url\"]\n",
202
+ " elif \"url\" in next_line:\n",
203
+ " label = next_line[\"url\"]\n",
204
+ "\n",
205
+ " return text, label\n",
206
  "\n",
207
  "\n",
208
  "if __name__ == \"__main__\":\n",
 
211
  " with demo:\n",
212
  " current_sample_state = gr.State(dict())\n",
213
  "\n",
214
+ " description = gr.Markdown(\n",
215
+ " value=\"\"\"GecLM annotations. All annotations are recorded in the [data_feedback](https://huggingface.co/datasets/HuggingFaceGECLM/data_feedback) dataset.\n",
216
+ "\"\"\",\n",
217
+ " )\n",
218
  " with gr.Row():\n",
219
  " annotator = gr.Textbox(\n",
220
  " lines=1,\n",
 
247
  " text = gr.Textbox(visible=False, label=\"Datapoint\", lines=500, max_lines=500)\n",
248
  "\n",
249
  " def get_next_line(dataset):\n",
 
250
  " try:\n",
251
  " next_line = next(line_generators_s3[dataset])\n",
252
+ " text, label = get_title_and_text_for_line(next_line)\n",
 
 
 
253
  " except StopIteration:\n",
254
  " text = LABELLING_COMPLETE_TEXT.format(dataset)\n",
255
  " next_line = text\n",
256
  " return [\n",
257
+ " gr.update(\n",
258
+ " value=text,\n",
259
+ " visible=True,\n",
260
+ " label=label,\n",
261
+ " ),\n",
262
  " next_line,\n",
263
  " gr.update(visible=True),\n",
264
  " gr.update(visible=True),\n",
 
269
  " if current_sample != LABELLING_COMPLETE_TEXT.format(dataset):\n",
270
  " send_report(current_sample, dataset, reason, annotator, campaign)\n",
271
  "\n",
 
272
  " try:\n",
273
  " next_line = next(line_generators_s3[dataset])\n",
274
+ " text, label = get_title_and_text_for_line(next_line)\n",
 
 
 
275
  " except StopIteration:\n",
276
  " text = LABELLING_COMPLETE_TEXT.format(dataset)\n",
277
  " next_line = text\n",
278
  " return [\n",
279
+ " gr.update(\n",
280
+ " value=text,\n",
281
+ " visible=True,\n",
282
+ " label=label,\n",
283
+ " ),\n",
284
  " gr.update(\n",
285
  " value=\"\",\n",
286
  " placeholder=\"Provide the reason for flagging if you think the sample is bad.\",\n",
287
  " ),\n",
288
+ " next_line,\n",
289
  " ]\n",
290
  "\n",
291
  " good_btn.click(\n",