How to set the glove path in an object torch.load ()?

I tried to load an object from a file with a torch to create an embedded word:

infersent = torch.load('InferSent/encoder/infersent1.pkl', map_location=lambda storage, loc: storage)

And then I tried to establish the Glove path as it does [Alvira Swalin in her article] 1.

infersent.set_glove_path("InferSent/dataset/GloVe/glove.840B.300d.txt")

But it gives me:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-14-1a6368709557> in <module>()
      1 infersent = torch.load('InferSent/encoder/infersent1.pkl', map_location=lambda storage, loc: storage)
----> 2 infersent.set_glove_path("InferSent/dataset/GloVe/glove.840B.300d.txt")
      3 

AttributeError: 'collections.OrderedDict' object has no attribute 'set_glove_path'
1 Like

Hi,

torch.load() just returns the object that was saved. I am not sure in this case what was the original object that was saved. But the file you read contains an OrderedDict from the collections package. This object does not have a method set_glove_path. I think you are not loading the proper .pkl file.

@albanD Thank for your answer ! Yes it was infersent.allnli.pickle before, as you can see on Alvira Swalin’s tutorial, but it is no more a pkl filed provided by Infersent, the sentence embeddings method that provides semantic representations for English sentences. They changed it for infersent1.pkl and infersent2.pkl.
Therefore … I don’t know what to do, I just wanted to do and update Alvira Swalin’s tutorial.

I am not familiar with this repo so I don’t know how to help. Sorry.

did you find solution? Im having the same issue

Hi.
I had this problem too. I tried to read the README.md from https://github.com/facebookresearch/InferSent carefully.
I found out that some changes have been made in the previous file. Therefore, you have to download all the files. Then, you should rewrite your code with respect to the explanation on the GitHub page.
As they have explained there, this the right way that you should set the path:
W2V_PATH = ‘fastText/crawl-300d-2M.vec’
infersent.set_w2v_path(W2V_PATH)

1 Like

Tnx Faeze; it was useful!