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

Gensim functions should accept pathlib.Path objects #3599

Open
DavidNemeskey opened this issue Jan 29, 2025 · 4 comments
Open

Gensim functions should accept pathlib.Path objects #3599

DavidNemeskey opened this issue Jan 29, 2025 · 4 comments

Comments

@DavidNemeskey
Copy link
Contributor

I got this error after 2 days of training:

Traceback (most recent call last):                                                     
  File "/data/orlando/home/ndavid/miniconda3/envs/embedding/lib/python3.12/site-packages/gensim/utils.py", line 763, in save
    _pickle.dump(self, fname_or_handle, protocol=pickle_protocol)                      
TypeError: file must have a 'write' attribute                                          
                                                                                       
During handling of the above exception, another exception occurred:                    
                                                                                       
Traceback (most recent call last):                                                     
  File "/home/ndavid/code/embedding_training/scripts/subword_embedding_training.py", line 144, in <module>
    main()                                                                             
  File "/home/ndavid/code/embedding_training/scripts/subword_embedding_training.py", line 140, in main
    model.save(args.model_file)                                                        
  File "/data/orlando/home/ndavid/miniconda3/envs/embedding/lib/python3.12/site-packages/gensim/models/word2vec.py", line 1923, in save
    super(Word2Vec, self).save(*args, **kwargs)                                        
  File "/data/orlando/home/ndavid/miniconda3/envs/embedding/lib/python3.12/site-packages/gensim/utils.py", line 766, in save
    self._smart_save(fname_or_handle, separately, sep_limit, ignore, pickle_protocol=pickle_protocol)
  File "/data/orlando/home/ndavid/miniconda3/envs/embedding/lib/python3.12/site-packages/gensim/utils.py", line 604, in _smart_save
    compress, subname = SaveLoad._adapt_by_suffix(fname)                               
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                               
  File "/data/orlando/home/ndavid/miniconda3/envs/embedding/lib/python3.12/site-packages/gensim/utils.py", line 572, in _adapt_by_suffix
    compress, suffix = (True, 'npz') if fname.endswith('.gz') or fname.endswith('.bz2') else (False, 'npy') 
                                        ^^^^^^^^^^^^^^                                 
AttributeError: 'PosixPath' object has no attribute 'endswith'

pathlib has been an integral part of the Python standard library since version 3.4 (more than 10 years ago), and it makes working with file paths much easier. Please add support for it in the library.

@123Soham-bhatia
Copy link

@DavidNemeskey , can i work on this one ?

@DavidNemeskey
Copy link
Contributor Author

@123Soham-bhatia Of course, I would be happy to see this being worked on. I am not a Gensim developer, however, so I won't be able to guide you / merge the PR.

@123Soham-bhatia
Copy link

@DavidNemeskey no issues, i can work on this alone and make it work , you can assign it to me .

@DavidNemeskey
Copy link
Contributor Author

@123Soham-bhatia As I said, I am not a Gensim developer, so I don't have write access to this repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants