0

Here is what I performed:

Installed pip3 install glove_py ok. In Jupyter Python, import glove works ok.

from glove import *

Problem:

When I try a basic setup code to ensure all the modules are loaded and working. I have this code, which errors on message: "NameError: name 'glove' is not defined". Now since module glove import works ok, I have tried function 'glove' and 'Glove', both with NameError not defined.

I did find libraries like 'git clone http://github.com/stanfordnlp/glove' and did download and build the code with make. This code ran ok in the console for a sample.

pip3 install glove_py

Pip install for glove_py installed ok.

pip3 install glove_python

But pip install for glove_python failed to install with "Error Command errored out with exit status 1:".

glove && make
mkdir -p build

glove 'git clone http://github.com/stanfordnlp/glove' download ok and build with make ok. But even with this make'd version, I was not able to get the Python import glove to find this c code make realized inside the Jupyter Python environment.

I suspect that I am missing something simple, I would appreciate any insight.

Python code, test run. Here is my Python code test run which failed on module not found.

model = glove(df, vocab_size=3, d=50, alpha=0.75, x_max=100.0)
model.train(df)
model.to_txt()
words = model.most_similary("one", 10)
NameError                                 Traceback (most recent call last)
<ipython-input-11-517b339bba36> in <module>
----> 1 model = glove(df, vocab_size=3, d=50, alpha=0.75, x_max=100.0)
      2 model.train(df)
      3 model.to_txt()
      4 words = model.most_similary("one", 10)
      5 print(words)

NameError: name 'glove' is not defined

Directory function to see the functions inside 'gl' module, imported from glove package, no module function names showed. So this clearly shows that the import of glove as gl, had some issues.

dir(gl)
['__doc__',
 '__file__',
 '__loader__',
 '__name__',
 '__package__',
 '__path__',
 '__spec__']
manager_matt
  • 395
  • 4
  • 19

1 Answers1

0

What you want is the Glove class inside the module; note the capital letter.

I think this line

glove(df, vocab_size=3, d=50, alpha=0.75, x_max=100.0)

should be

Glove(df, vocab_size=3, d=50, alpha=0.75, x_max=100.0)

Peritract
  • 761
  • 5
  • 13
  • Thanks. To be honest, I think I tried both 'glove' and 'Glove'; let me check back on my Python code for that. Since that time, I have successfully implemented GloVe in R for results outcome. – manager_matt Mar 25 '20 at 22:46
  • Yeah, just run Python. import glove as gl worked fine. model = Glove(input_file=df, vocab_size=3, d=50, alpha=0.75, x_max=100.0) FAILED again: NameError: name 'Glove' is not defined. – manager_matt Mar 25 '20 at 22:47
  • If you import glove as gl, then you'll need to use gl.Glove; it's only when you from glove import * that you can skip the module name and just use Glove. – Peritract Mar 25 '20 at 23:24
  • import glove as gl; model = gl.Glove(input_file=df, vocab_size=3, d=50, alpha=0.75, x_max=100.0). AttributeError: module 'glove' has no attribute 'Glove' – manager_matt Mar 25 '20 at 23:37
  • Try the example code from the readme: from glove import * model = Glove(epoch=2) – Peritract Mar 26 '20 at 00:39