kzhai / InfVocLDA

Online Latent Dirichlet Allocation with Infinite Vocabulary using Variational Inference
https://github.com/kzhai/InfVocLDA
Apache License 2.0
74 stars 19 forks source link

launch don't work and index issues #4

Closed jorgecastillo2 closed 6 years ago

jorgecastillo2 commented 6 years ago

Hi,

I running the instructions on windows 10, python 3.6. After editing the "print" command inside launch (because we know that there is a change on it), I keep get the following errors after launch the command:

Traceback (most recent call last): File "C:\Users\Jorge Castillo\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 183, in _run_module_as_main mod_name, mod_spec, code = _get_module_details(mod_name, _Error) File "C:\Users\Jorge Castillo\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 153, in _get_module_details code = loader.get_code(mod_name) File "", line 781, in get_code File "", line 741, in source_to_code File "", line 219, in _call_with_frames_removed File "C:\Users\Jorge Castillo(...)\InfVocLDA-master\src\infvoc\launch.py", line 232 gamma_path = os.path.join(output_directory, "gamma.txt") ^ SyntaxError: invalid syntax

I'm launching the command (following the instruction) on cmd windows, in the source established (i.e., in InfVocLDA-master\src) and getting the error and can't installing. Also, changing "python" with "py " don't fit the error. What I'm doing wrong? Thanks for help.

kzhai commented 6 years ago

The package was originally developed with Python2.7, and the error seems to be some incompatible syntax error or tab/space conversion. Let me know if that helps.

On Sun, Sep 30, 2018 at 10:42 PM jorgecastillo2 notifications@github.com wrote:

Hi,

I running the instructions on windows 10, python 3.6. After editing the rint command (because we know that there is a change on it), I keep get the following errors after launch the command:

Traceback (most recent call last): File "C:\Users\Jorge Castillo\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 183, in _run_module_as_main mod_name, mod_spec, code = _get_module_details(mod_name, _Error) File "C:\Users\Jorge Castillo\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 153, in _get_module_details code = loader.get_code(mod_name) File "", line 781, in get_code File "", line 741, in source_to_code File "", line 219, in _call_with_frames_removed File "C:\Users\Jorge Castillo(...)\InfVocLDA-master\src\infvoc\launch.py", line 232 gamma_path = os.path.join(output_directory, "gamma.txt") ^ SyntaxError: invalid syntax

I'm launching the command (following the instruction) on cmd windows, in the source established (i.e., in InfVocLDA-master\src) and getting the error and can't installing. Also, changing "python" with "py " don't fit the error. What I'm doing wrong? Thanks for help.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/kzhai/InfVocLDA/issues/4, or mute the thread https://github.com/notifications/unsubscribe-auth/AAklRpUjbcNrc82UzXrpIxJOQ7RT7SO1ks5ugatHgaJpZM4XBaWF .

jorgecastillo2 commented 6 years ago

Hi kzhai, thanks for answering FInally i launch with python 2.7 and fixed the tab/space conversion via untabify spaces but I keep getting another error type:

Traceback (most recent call last):
  File "C:\Python27\lib\runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "C:\Python27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\Users\Jorge Castillo\(...)l\InfVocLDA-master\src\infvoc\launch.py", line 248, in <module>
    main()
  File "C:\Users\Jorge Castillo\(...)\InfVocLDA-master\src\infvoc\launch.py", line 218, in main
    batch_gamma = olda.learning(docset);
  File "infvoc\hybrid.py", line 448, in learning
    sufficient_statistics, batch_document_topic_distribution = self.e_step(wordids);
  File "infvoc\hybrid.py", line 335, in e_step
    sufficient_statistics[k][0, id] += temp_phi[k, 0];
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices

Clearly, I must edit the lines 335 and 448 of hybrid.py in order to recognize valid indexes

Edit: now I see, for both lines, that wordids is the problem but I don't know how to fix it.

Edit 2: Curiosly, between lines 309 to 317 there is no error, specifically in 310 it's defined wordid and in 317 the sentence temp_phi[k, 0] *= exp_weights[k][0, id]; don't give error, I don't know why.

Thanks for your help and code developing.

kzhai commented 6 years ago

Hi, Jorge,

The reason is the newer version of numpy enforces the data type to be explicitly defined, even creating from an all integer list. Anyway, please try to run the code from a different repo https://github.com/kzhai/PyInfVoc. It basically contains the exact same code, but much cleaner. I have just ported this repo to python3, so you should be able to run it without any problem.

kzhai@MININT-LPGA1J7:/mnt/c/Users/kezhai/Workspace/PyInfVoc$ python3 -m launch_train --input_directory=./de-news/ --output_directory=./ --truncation_level=4000 --number_of_pics=10 --number_of_documents=9800 --training_iterations=100 --vocab_prune_interval=10 --batch_size=98 --alpha_beta=100
========== ========== ========== ========== ==========
output_directory=./de-news/18Oct03-231005-D9800-K10-T4000-P10-I10-B98-O100-t64-k0.75-at0.1-ab100/
input_directory=./de-news
corpus_name=de-news
dictionary_file=None
number_of_documents=9800
number_of_topics=10
truncation_level=4000
vocab_prune_interval=10
snapshot_interval=10
batch_size=98
training_iterations=100
tau=64.0
kappa=0.75
alpha_theta=0.1
alpha_beta=100.0
========== ========== ========== ========== ==========
successfully load all training documents...
select documents from 0 to 98
P-step, E-step and M-step take 0, 2, 0 seconds respectively...
vocabulary size = [1725, 1725, 1725, 1725, 1725, 1725, 1725, 1725, 1725, 1725]
training iteration 1 finished in 2.888820 seconds: epsilon = 0.043683
select documents from 98 to 196
P-step, E-step and M-step take 0, 2, 0 seconds respectively...
vocabulary size = [2582, 2582, 2582, 2582, 2582, 2582, 2582, 2582, 2582, 2582]
training iteration 2 finished in 3.002949 seconds: epsilon = 0.043186
select documents from 196 to 294
P-step, E-step and M-step take 0, 2, 0 seconds respectively...
vocabulary size = [3194, 3194, 3194, 3194, 3194, 3194, 3194, 3194, 3194, 3194]
training iteration 3 finished in 2.965397 seconds: epsilon = 0.042702
select documents from 294 to 392
P-step, E-step and M-step take 0, 4, 0 seconds respectively...
vocabulary size = [3654, 3654, 3654, 3654, 3654, 3654, 3654, 3654, 3654, 3654]
training iteration 4 finished in 4.734318 seconds: epsilon = 0.042230
select documents from 392 to 490
P-step, E-step and M-step take 0, 3, 0 seconds respectively...

Thanks for digging into this, and feel free to let me know for any bugs.

Best, Ke