0x22almostEvil commited on
Commit
b04e418
1 Parent(s): 6e08cbd

WARNING: Cringe Code

Files changed (1) hide show
  1. source/create_dataset.py +47 -34
source/create_dataset.py CHANGED
@@ -3,15 +3,27 @@ from urllib.parse import unquote
3
 
4
  import io
5
  import csv
6
- import random
7
 
8
- lang = "de"
9
- n = 1100
10
 
11
- # removing duplicates
12
- def cleandata():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  input_file = f'data_{lang}.csv'
14
- output_file = f'{lang}-wikihow-qa-dataset-1k.csv'
15
 
16
  unique_urls = {}
17
 
@@ -24,40 +36,41 @@ def cleandata():
24
  csv_output.writerow(header)
25
 
26
  for row in csv_input:
27
- url = row[3]
28
- if url not in unique_urls:
29
- row[3] = f'{{"url": "{url}", "language": "{lang}"}}'
30
- csv_output.writerow(row)
31
- unique_urls[url] = True
32
- else:
33
- print(f"Duplicate row found, url: {url}")
34
- print("Done!")
35
-
36
- # getting a random article
 
37
  def getrandom():
38
  how_to = RandomHowTo(lang)
39
  wkhowto_url = how_to.url
40
 
41
  theme = unquote(how_to.title.encode('utf-8'))
42
 
43
- # randomization
44
- templates = [
45
- "Wie mache ich {theme}?",
46
- "Schreibe wie ich folgendes tun kann: {theme}"
47
- ]
48
-
49
- wkhowto_q = random.choice(templates).format(theme=theme)
50
  wkhowto_a = how_to.print(extended=True)
51
  return wkhowto_q, wkhowto_a, wkhowto_url
52
 
53
- # saving .csv
54
- with open(f'data_{lang}.csv', mode='w', newline='') as file:
55
- writer = csv.writer(file)
56
- writer.writerow(['INSTRUCTION', 'RESPONSE', 'SOURCE', 'URL'])
57
- for i in range(n):
58
- wkhowto_q, wkhowto_a, wkhowto_url = getrandom()
59
- data = [wkhowto_q, wkhowto_a, f'{lang}.wikihow.com', wkhowto_url]
60
- writer.writerow(data)
61
- print(f"{i+1} out of {n}")
62
-
63
- cleandata()
 
 
 
 
 
 
 
3
 
4
  import io
5
  import csv
 
6
 
7
+ import time
 
8
 
9
+ langs = {
10
+ "en",
11
+ "ru",
12
+ "pt",
13
+ "it",
14
+ "es",
15
+ "fr",
16
+ "de",
17
+ "nl"
18
+ }
19
+
20
+ n = 2200
21
+ n_k = n / 1000 - n % 100
22
+
23
+
24
+ def cleandata(lang):
25
  input_file = f'data_{lang}.csv'
26
+ output_file = f'{lang}-wikihow-qa-dataset-{n_k}k.csv'
27
 
28
  unique_urls = {}
29
 
 
36
  csv_output.writerow(header)
37
 
38
  for row in csv_input:
39
+ try:
40
+ url = row[3]
41
+ if url not in unique_urls:
42
+ row[3] = f'{{"url": "{url}", "language": "{lang}"}}'
43
+ csv_output.writerow(row)
44
+ unique_urls[url] = True
45
+ else:
46
+ print(f"\033[91mDuplicate row found, url: {url}\033[0m")
47
+ except:
48
+ print(f"\033[91mBroken found, url: {row}\033[0m")
49
+
50
  def getrandom():
51
  how_to = RandomHowTo(lang)
52
  wkhowto_url = how_to.url
53
 
54
  theme = unquote(how_to.title.encode('utf-8'))
55
 
56
+ wkhowto_q = theme
 
 
 
 
 
 
57
  wkhowto_a = how_to.print(extended=True)
58
  return wkhowto_q, wkhowto_a, wkhowto_url
59
 
60
+ for lang in langs:
61
+ print(f"\33[34mGenerating {lang}...\033[0m")
62
+ with open(f'data_{lang}.csv', mode='w', newline='') as file:
63
+ writer = csv.writer(file)
64
+ writer.writerow(['INSTRUCTION', 'RESPONSE', 'SOURCE', 'URL'])
65
+ for i in range(n):
66
+ wkhowto_q, wkhowto_a, wkhowto_url = getrandom()
67
+ data = [wkhowto_q, wkhowto_a, f'{lang}.wikihow.com', wkhowto_url]
68
+ writer.writerow(data)
69
+ print(f"{i+1} out of {n}\033[0m")
70
+ time.sleep(3)
71
+ print(f"\33[92mDone for {lang}!\033[0m\n")
72
+
73
+ for lang in langs:
74
+ cleandata(lang)
75
+
76
+ print("\33[32mDone for all!\033[0m")