Code Monkey home page Code Monkey logo

Comments (19)

galuhsahid avatar galuhsahid commented on September 1, 2024 29

I came across the same error as well. I changed:

word_vectors = KeyedVectors.load_word2vec_format(path, binary=True)

into

word_vectors = KeyedVectors.load(path)

It turns out that load_word2vec_format is used when we're trying to load word vectors that are trained using the original implementation of word2vec (in C). Since these pre-trained word vectors are trained using Python (gensim), we can use load instead.

from wordvectors.

hinanmu avatar hinanmu commented on September 1, 2024 18

I have come across the same error. I changed gensim.models.KeyedVectors.load_word2vec_format()
into gensim.models.Word2Vec.load() .Then it works

from wordvectors.

anavaldi avatar anavaldi commented on September 1, 2024 10

I have tried to read the files as you pointed, but I got the next error:

 File "C:\ProgramData\Anaconda2\lib\site-packages\gensim\models\base_any2vec.py", line 380, in syn1neg
    self.trainables.syn1neg = value

AttributeError: 'Word2Vec' object has no attribute 'trainables'

:(

from wordvectors.

anavaldi avatar anavaldi commented on September 1, 2024 2

I solve this error by executing on my own word embeddings with the .sh file.

from wordvectors.

changhyub avatar changhyub commented on September 1, 2024 1

@hinamu it works, Thanks

from wordvectors.

gilgtc avatar gilgtc commented on September 1, 2024 1

@anavaldi

I solve this error by executing on my own word embeddings with the .sh file.

What do you mean?

from wordvectors.

caitaozhan avatar caitaozhan commented on September 1, 2024 1

I have tried to read the files as you pointed, but I got the next error:

 File "C:\ProgramData\Anaconda2\lib\site-packages\gensim\models\base_any2vec.py", line 380, in syn1neg
    self.trainables.syn1neg = value

AttributeError: 'Word2Vec' object has no attribute 'trainables'

:(

I solved this issue by degrading my gensim version from 3.6 to 3.0

from wordvectors.

ashutoshsoni891 avatar ashutoshsoni891 commented on September 1, 2024 1

I came across the same error as well. I changed:

word_vectors = KeyedVectors.load_word2vec_format(path, binary=True)

into

word_vectors = KeyedVectors.load(path)

It turns out that load_word2vec_format is used when we're trying to load word vectors that are trained using the original implementation of word2vec (in C). Since these pre-trained word vectors are trained using Python (gensim), we can use load instead.

When I tried this , I am getting : UnpicklingError: unpickling stack underflow

from wordvectors.

wiwengweng avatar wiwengweng commented on September 1, 2024

of cause the vector should be trained using the proper codec, it seems the model is trained in other coding environment. Can you check that.

from wordvectors.

lxw0109 avatar lxw0109 commented on September 1, 2024

I have come across the same error, anybody help? Thank you ~

from wordvectors.

lxw0109 avatar lxw0109 commented on September 1, 2024

@galuhsahid Thank you so much, it works now. : )

from wordvectors.

Priya22 avatar Priya22 commented on September 1, 2024

Same error as @anavaldi . Any solution?

from wordvectors.

kusumlata123 avatar kusumlata123 commented on September 1, 2024

UnpicklingError Traceback (most recent call last)
in ()
3 #model=gensim.models.Word2Vec.load_word2vec_format('model_file', binary=True) Word2Vec.load_word2vec_format
4 #model_bin = KeyedVectors.load_word2vec_format(model_file,binary=True)
----> 5 model=gensim.models.Word2Vec.load(model_file)
6 #model=gensim.Word2Vec.load_word2vec_format('model_file',binary=True) word_vectors = KeyedVectors.load(path)
why is it giving

from wordvectors.

Koteswara-ML avatar Koteswara-ML commented on September 1, 2024

@kusumlata123 even i am getting that Unpickling Error

from wordvectors.

bright1993ff66 avatar bright1993ff66 commented on September 1, 2024

I am also getting the unpickling error...
Any ideas? My code is:

chinese_model = gensim.models.Word2Vec.load(os.path.join(desktop, 'cc.zh.300.bin.gz')) 

from wordvectors.

bright1993ff66 avatar bright1993ff66 commented on September 1, 2024

I also tried to save the text file and load it via the function provided by the fasttext official site. I first change the file extension from gz to txt and use the following functions:

import io

def load_vectors(fname):
    fin = io.open(fname, 'r', encoding='utf-8', newline='\n', errors='ignore')
    n, d = map(int, fin.readline().split())
    data = {}
    for line in fin:
        tokens = line.rstrip().split(' ')
        data[tokens[0]] = map(float, tokens[1:])
    return data

model = load_vectors(os.path.join(desktop, 'cc.zh.300.vec.txt'))

However, I got the following errors:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-4-d67f52bde947> in <module>
----> 1 model = load_vectors(os.path.join(desktop, 'cc.zh.300.vec.txt'))

<ipython-input-3-0f69b5ce62b8> in load_vectors(fname)
      1 def load_vectors(fname):
      2     fin = io.open(fname, 'r', encoding='utf-8', newline='\n', errors='ignore')
----> 3     n, d = map(int, fin.readline().split())
      4     data = {}
      5     for line in fin:

ValueError: invalid literal for int() with base 10: '\x08\x08p[\x00\x03cc.zh.300.vec\x00\\ͮfMr7?W3ۀ0|Szдl\x14I\x132'

from wordvectors.

thejastr avatar thejastr commented on September 1, 2024

I tried the above solution but I am getting error as:
UnpicklingError: invalid load key, '\x1f'
My code:
from gensim import models

word2vec_path = 'GoogleNews-vectors-negative300.bin.gz.2' word2vec = models.KeyedVectors.load(word2vec_path)

from wordvectors.

trungluu91 avatar trungluu91 commented on September 1, 2024

I came across the same error as well. I changed:
word_vectors = KeyedVectors.load_word2vec_format(path, binary=True)
into
word_vectors = KeyedVectors.load(path)
It turns out that load_word2vec_format is used when we're trying to load word vectors that are trained using the original implementation of word2vec (in C). Since these pre-trained word vectors are trained using Python (gensim), we can use load instead.

When I tried this , I am getting : UnpicklingError: unpickling stack underflow

For Korean language, i got this error:
'AttributeError: Can't get attribute 'Vocab' on <module 'gensim.models.word2vec' from 'C:\Users\ductr\Python\lib\site-packages\gensim\models\word2vec.py'>'
Would you mind letting me know what the error is?

from wordvectors.

Louislazarus avatar Louislazarus commented on September 1, 2024

I tried the above solution but I am getting error as: UnpicklingError: invalid load key, '\x1f' My code: from gensim import models

word2vec_path = 'GoogleNews-vectors-negative300.bin.gz.2' word2vec = models.KeyedVectors.load(word2vec_path)

I get the same error after using:

from gensim.models import Word2Vec
from gensim.models.keyedvectors import KeyedVectors
model = Word2Vec.load(model_path)

What am I doing wrong?

from wordvectors.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.