-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
83 lines (63 loc) · 2.5 KB
/
setup.py
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
import nltk
from pathlib import Path
import requests
import zipfile
FILEPATH = Path(__file__).parent.absolute()
def download(url, zippath):
r = requests.get(url, stream=True)
with open(zippath, "wb") as file:
for chunk in r.iter_content(chunk_size=1024):
if chunk:
file.write(chunk)
def extract(zippath, embeddings_path):
with zipfile.ZipFile(zippath, 'r') as zip_ref:
zip_ref.extractall(embeddings_path)
def download_glove():
glove_url = 'https://nlp.stanford.edu/data/glove.6B.zip'
glove_zip = FILEPATH/'src'/'data'/'glove.6B.zip'
glove_folder = FILEPATH/'src'/'data'/'glove.6B'
glove_file = FILEPATH/'src'/'data'/'glove.6B.300d.txt'
if not glove_file.exists(): # if the file does not exist
if not glove_folder.exists():
if not glove_zip.exists(): # if zip file is not downloaded
print("Downloading GloVe...")
download(glove_url, glove_zip)
print("GloVe downloaded!")
print("Extracting GloVe...")
extract(glove_zip, glove_folder)
(glove_folder/'glove.6B.300d.txt').rename(glove_file)
print("GloVe extracted!")
if glove_folder.exists():
for child in glove_folder.glob("**/*"):
child.unlink()
glove_folder.rmdir()
if glove_zip.exists():
glove_zip.unlink()
def download_fasttext():
fasttext_url = 'https://dl.fbaipublicfiles.com/fasttext/vectors-english/crawl-300d-2M-subword.zip'
fasttext_zip = FILEPATH/'src'/'data'/'crawl-300d-2M-subword.zip'
fasttext_folder = FILEPATH/'src'/'data'/'crawl-300d-2M-subword'
fasttext_file = FILEPATH/'src'/'data'/'crawl-300d-2M-subword.vec'
if not fasttext_file.exists():
if not fasttext_folder.exists():
if not fasttext_zip.exists():
print("Downloading fastText...")
download(fasttext_url, fasttext_zip)
print("fastText downloaded!")
print("Extracting fastText...")
extract(fasttext_zip, fasttext_folder)
(fasttext_folder/'crawl-300d-2M-subword.vec').rename(fasttext_file)
print("fastText extracted!")
if fasttext_folder.exists():
for child in fasttext_folder.glob("**/*"):
child.unlink()
fasttext_folder.rmdir()
if fasttext_zip.exists():
fasttext_zip.unlink()
def setup():
nltk.download('punkt')
nltk.download('stopwords')
download_glove()
download_fasttext()
if __name__ == '__main__':
setup()