update
Browse files- data/UTS_Text_v1.txt +0 -0
- generate_dataset.py +48 -0
data/UTS_Text_v1.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
generate_dataset.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from os.path import join, dirname
|
| 2 |
+
from underthesea.file_utils import DATASETS_FOLDER
|
| 3 |
+
import random
|
| 4 |
+
|
| 5 |
+
random.seed(10)
|
| 6 |
+
# sampling data
|
| 7 |
+
text_file = join(DATASETS_FOLDER, "VNESES", "VNESEScorpus.txt")
|
| 8 |
+
with open(text_file) as f:
|
| 9 |
+
lines = f.read().splitlines()
|
| 10 |
+
NUM_LONG_TOKENS = 50
|
| 11 |
+
NUM_SHORT_TOKENS = 20
|
| 12 |
+
long_lines = [
|
| 13 |
+
line
|
| 14 |
+
for line in lines
|
| 15 |
+
if len(line) >= NUM_LONG_TOKENS and line[0].isupper() and line[-1] == "."
|
| 16 |
+
]
|
| 17 |
+
# get random 1000 lines
|
| 18 |
+
random_long_lines = random.sample(long_lines, 5000)
|
| 19 |
+
for line in random_long_lines[:20]:
|
| 20 |
+
print(line)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def shortline_conditions(line):
|
| 24 |
+
if len(line) < NUM_SHORT_TOKENS:
|
| 25 |
+
return False
|
| 26 |
+
if len(line) > NUM_LONG_TOKENS:
|
| 27 |
+
return False
|
| 28 |
+
if not line[0].isupper():
|
| 29 |
+
return False
|
| 30 |
+
return True
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
short_lines = [line for line in lines if shortline_conditions(line)]
|
| 34 |
+
random_short_lines = random.sample(short_lines, 5000)
|
| 35 |
+
for line in random_short_lines[:20]:
|
| 36 |
+
print(line)
|
| 37 |
+
|
| 38 |
+
print("Long lines", len(random_long_lines))
|
| 39 |
+
print("Short lines", len(random_short_lines))
|
| 40 |
+
|
| 41 |
+
pwd = dirname(__file__)
|
| 42 |
+
tmp = join(pwd, "data")
|
| 43 |
+
corpus_file = join(tmp, "UTS_Text_v1.txt")
|
| 44 |
+
|
| 45 |
+
with open(corpus_file, "w") as f:
|
| 46 |
+
lines = random_long_lines + random_short_lines
|
| 47 |
+
content = "\n".join(lines)
|
| 48 |
+
f.write(content)
|