Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically download GloVe embeddings #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions dataHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import pickle
from utils import log_time_delta
from tqdm import tqdm
from dataloader import Dataset
from dataloader import Dataset, Glove
import torch
from torch.autograd import Variable
from codecs import open
Expand Down Expand Up @@ -129,7 +129,7 @@ def load_text_vec(alphabet,filename="",embedding_size=-1):
def getEmbeddingFile(name):
#"glove" "w2v"

return os.path.join( ".vector_cache","glove.6B.300d.txt")
return os.path.join( ".vector_cache", "6b", "glove.6B.300d.txt")

def getDataSet(opt):

Expand Down Expand Up @@ -177,6 +177,7 @@ def loadData(opt):
# from functools import reduce
# word_set=set(reduce(lambda x,y :x+y,df["text"]))

Glove(corpus="6b", dim=300).process()
glove_file = getEmbeddingFile(opt.__dict__.get("embedding","glove_6b_300"))
loaded_vectors,embedding_size = load_text_vec(word_set,glove_file)
word_set = word_set & set(loaded_vectors.keys())
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
if "CUDA_VISIBLE_DEVICES" not in os.environ.keys():
os.environ["CUDA_VISIBLE_DEVICES"] =opt.gpu
#opt.model ='lstm'
opt.model ='capsule'
#opt.model ='capsule'

if from_torchtext:
train_iter, test_iter = utils.loadData(opt)
Expand Down