Datasets:

ArXiv:
License:
HoneyTian commited on
Commit
5779ae4
1 Parent(s): 2cb7d00
examples/load_data/plan_1.py ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/python3
2
+ # -*- coding: utf-8 -*-
3
+ import argparse
4
+ import json
5
+ import os
6
+ import sys
7
+
8
+ pwd = os.path.abspath(os.path.dirname(__file__))
9
+ sys.path.append(os.path.join(pwd, "../../"))
10
+
11
+ from datasets import load_dataset, DownloadMode
12
+
13
+ from project_settings import project_path
14
+
15
+
16
+ def get_args():
17
+ parser = argparse.ArgumentParser()
18
+ parser.add_argument(
19
+ "--dataset_cache_dir",
20
+ default=(project_path / "hub_datasets").as_posix(),
21
+ type=str
22
+ )
23
+ parser.add_argument(
24
+ "--train_subset",
25
+ default="train.jsonl",
26
+ type=str
27
+ )
28
+ parser.add_argument(
29
+ "--valid_subset",
30
+ default="valid.jsonl",
31
+ type=str
32
+ )
33
+ args = parser.parse_args()
34
+ return args
35
+
36
+
37
+ s = """
38
+ | ar | arabic | 10000 | iwslt2017 |
39
+ | bg | bulgarian | 10000 | xnli |
40
+ | bn | bengali | 10000 | open_subtitles |
41
+ | bs | bosnian | 10000 | open_subtitles |
42
+ | cs | czech | 10000 | ecb |
43
+ | da | danish | 10000 | open_subtitles |
44
+ | de | german | 10000 | ecb |
45
+ | el | modern greek | 10000 | ecb |
46
+ | en | english | 10000 | ecb |
47
+ | eo | esperanto | 10000 | tatoeba |
48
+ | es | spanish | 10000 | tatoeba |
49
+ | et | estonian | 10000 | emea |
50
+ | fi | finnish | 10000 | ecb |
51
+ | fo | faroese | 10000 | nordic_langid |
52
+ | fr | french | 10000 | iwslt2017 |
53
+ | ga | irish | 10000 | multi_para_crawl |
54
+ | gl | galician | 3096 | tatoeba |
55
+ | hi | hindi | 10000 | open_subtitles |
56
+ | hi_en | hindi | 7180 | cmu_hinglish_dog |
57
+ | hr | croatian | 10000 | hrenwac_para |
58
+ | hu | hungarian | 3801 | europa_ecdc_tm; europa_eac_tm |
59
+ | hy | armenian | 660 | open_subtitles |
60
+ | id | indonesian | 10000 | id_panl_bppt |
61
+ | is | icelandic | 2973 | europa_ecdc_tm; europa_eac_tm |
62
+ | it | italian | 10000 | iwslt2017 |
63
+ | ja | japanese | 10000 | iwslt2017 |
64
+ | ko | korean | 10000 | iwslt2017 |
65
+ | lt | lithuanian | 10000 | emea |
66
+ | lv | latvian | 4595 | europa_ecdc_tm; europa_eac_tm |
67
+ | mr | marathi | 10000 | tatoeba |
68
+ | mt | maltese | 10000 | multi_para_crawl |
69
+ | nl | dutch | 10000 | kde4 |
70
+ | no | norwegian | 10000 | multi_para_crawl |
71
+ | pl | polish | 10000 | ecb |
72
+ | pt | portuguese | 10000 | tatoeba |
73
+ | ro | romanian | 10000 | kde4 |
74
+ | ru | russian | 10000 | xnli |
75
+ | sk | slovak | 10000 | multi_para_crawl |
76
+ | sl | slovenian | 4589 | europa_ecdc_tm; europa_eac_tm |
77
+ | sw | swahili | 10000 | xnli |
78
+ | sv | swedish | 10000 | kde4 |
79
+ | th | thai | 10000 | xnli |
80
+ | tl | tagalog | 10000 | multi_para_crawl |
81
+ | tn | serpeti | 10000 | autshumato |
82
+ | tr | turkish | 10000 | xnli |
83
+ | ts | dzonga | 10000 | autshumato |
84
+ | ur | urdu | 10000 | xnli |
85
+ | vi | vietnamese | 10000 | xnli |
86
+ | yo | yoruba | 9970 | menyo20k_mt |
87
+ | zh | chinese | 10000 | xnli |
88
+ | zu | zulu, south africa | 10000 | autshumato |
89
+ """
90
+
91
+
92
+ def main():
93
+ args = get_args()
94
+
95
+ subset_dataset_dict = dict()
96
+
97
+ lines = s.strip().split("\n")
98
+
99
+ with open(args.train_subset, "w", encoding="utf-8") as ftrain, open(args.valid_subset, "w", encoding="utf-8") as fvalid:
100
+ for line in lines:
101
+ row = str(line).split("|")
102
+ row = [col.strip() for col in row if len(col) != 0]
103
+
104
+ if len(row) != 4:
105
+ raise AssertionError("not 4 item, line: {}".format(line))
106
+
107
+ abbr = row[0]
108
+ full = row[1]
109
+ total = int(row[2])
110
+ subsets = [e.strip() for e in row[3].split(";")]
111
+
112
+ train_count = 0
113
+ valid_count = 0
114
+ for subset in subsets:
115
+ if subset in subset_dataset_dict.keys():
116
+ dataset_dict = subset_dataset_dict[subset]
117
+ else:
118
+ dataset_dict = load_dataset(
119
+ "../../language_identification.py",
120
+ name=subset,
121
+ cache_dir=args.dataset_cache_dir,
122
+ # download_mode=DownloadMode.FORCE_REDOWNLOAD
123
+ )
124
+ subset_dataset_dict[subset] = dataset_dict
125
+
126
+ train_dataset = dataset_dict["train"]
127
+ for sample in train_dataset:
128
+ text = sample["text"]
129
+ language = sample["language"]
130
+ data_source = sample["data_source"]
131
+
132
+ if train_count > total:
133
+ break
134
+ if language == abbr:
135
+ row_ = {
136
+ "text": text,
137
+ "label": language,
138
+ "data_source": data_source,
139
+ "split": "train",
140
+ }
141
+ row_ = json.dumps(row_, ensure_ascii=False)
142
+ ftrain.write("{}\n".format(row_))
143
+ train_count += 1
144
+
145
+ if "validation" in dataset_dict:
146
+ valid_dataset = dataset_dict["validation"]
147
+ for sample in valid_dataset:
148
+ text = sample["text"]
149
+ language = sample["language"]
150
+ data_source = sample["data_source"]
151
+
152
+ if valid_count > total:
153
+ break
154
+ if language == abbr:
155
+ row_ = {
156
+ "text": text,
157
+ "label": language,
158
+ "data_source": data_source,
159
+ "split": "valid",
160
+ }
161
+ row_ = json.dumps(row_, ensure_ascii=False)
162
+ fvalid.write("{}\n".format(row_))
163
+ valid_count += 1
164
+
165
+ return
166
+
167
+
168
+ if __name__ == "__main__":
169
+ main()
language_identification.py CHANGED
@@ -99,7 +99,7 @@ LANGUAGE_MAP = {
99
  "sv": "swedish",
100
  "th": "thai",
101
  "tl": "tagalog",
102
- "tn": "sepedi",
103
  "tr": "turkish",
104
  "ts": "dzonga",
105
  "uk": "ukrainian",
 
99
  "sv": "swedish",
100
  "th": "thai",
101
  "tl": "tagalog",
102
+ "tn": "serpeti",
103
  "tr": "turkish",
104
  "ts": "dzonga",
105
  "uk": "ukrainian",
load_data.md ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## 加载数据
2
+
3
+ ### 方案1
4
+
5
+ 语种:
6
+
7
+ | 语种 | 语种全称 | 样本个数 | 数据来源 |
8
+ | :--- | :---: | :---: | :---: |
9
+ | ar | arabic | 10000 | iwslt2017 |
10
+ | bg | bulgarian | 10000 | xnli |
11
+ | bn | bengali | 10000 | open_subtitles |
12
+ | bs | bosnian | 10000 | open_subtitles |
13
+ | cs | czech | 10000 | ecb |
14
+ | da | danish | 10000 | open_subtitles |
15
+ | de | german | 10000 | ecb |
16
+ | el | modern greek | 10000 | ecb |
17
+ | en | english | 10000 | ecb |
18
+ | eo | esperanto | 10000 | tatoeba |
19
+ | es | spanish | 10000 | tatoeba |
20
+ | et | estonian | 10000 | emea |
21
+ | fi | finnish | 10000 | ecb |
22
+ | fo | faroese | 10000 | nordic_langid |
23
+ | fr | french | 10000 | iwslt2017 |
24
+ | ga | irish | 10000 | multi_para_crawl |
25
+ | gl | galician | 3096 | tatoeba |
26
+ | hi | hindi | 10000 | open_subtitles |
27
+ | hi_en | hindi | 7180 | cmu_hinglish_dog |
28
+ | hr | croatian | 10000 | hrenwac_para |
29
+ | hu | hungarian | 3801 | europa_ecdc_tm; europa_eac_tm |
30
+ | hy | armenian | 660 | open_subtitles |
31
+ | id | indonesian | 10000 | id_panl_bppt |
32
+ | is | icelandic | 2973 | europa_ecdc_tm; europa_eac_tm |
33
+ | it | italian | 10000 | iwslt2017 |
34
+ | ja | japanese | 10000 | iwslt2017 |
35
+ | ko | korean | 10000 | iwslt2017 |
36
+ | lt | lithuanian | 10000 | emea |
37
+ | lv | latvian | 4595 | europa_ecdc_tm; europa_eac_tm |
38
+ | mr | marathi | 10000 | tatoeba |
39
+ | mt | maltese | 10000 | multi_para_crawl |
40
+ | nl | dutch | 10000 | kde4 |
41
+ | no | norwegian | 10000 | multi_para_crawl |
42
+ | pl | polish | 10000 | ecb |
43
+ | pt | portuguese | 10000 | tatoeba |
44
+ | ro | romanian | 10000 | kde4 |
45
+ | ru | russian | 10000 | xnli |
46
+ | sk | slovak | 10000 | multi_para_crawl |
47
+ | sl | slovenian | 4589 | europa_ecdc_tm; europa_eac_tm |
48
+ | sw | swahili | 10000 | xnli |
49
+ | sv | swedish | 10000 | kde4 |
50
+ | th | thai | 10000 | xnli |
51
+ | tl | tagalog | 10000 | multi_para_crawl |
52
+ | tn | serpeti | 10000 | autshumato |
53
+ | tr | turkish | 10000 | xnli |
54
+ | ts | dzonga | 10000 | autshumato |
55
+ | ur | urdu | 10000 | xnli |
56
+ | vi | vietnamese | 10000 | xnli |
57
+ | yo | yoruba | 9970 | menyo20k_mt |
58
+ | zh | chinese | 10000 | xnli |
59
+ | zu | zulu, south africa | 10000 | autshumato |
60
+
61
+
62
+ 代码:
63
+ ```python
64
+
65
+
66
+
67
+ ```
68
+