I am trying to train a FastText model.
from gensim.test.utils import datapath
from gensim.models.fasttext import FastText
from gensim.test.utils import get_tmpfile
embedding_size = 300
window_size = 10
min_word = 5
down_sampling = 1e-2
corpus_file = datapath('data.cor')
model = FastText(size=embedding_size,
window=window_size,
min_count=min_word,
sample=down_sampling,
sg=1,
iter=100)
model.build_vocab(corpus_file=corpus_file)
total_words = model.corpus_total_words
model.train(corpus_file=corpus_file, total_words=total_words, epochs=5)
fname = get_tmpfile("fasttext.model")
model.save(fname)
However, the following error appears:
Traceback (most recent call last):
File "C:ProgramDataAnaconda3libsite-packagesgensimutils.py", line 692, 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 "E:/untitled1/dfgd.py", line 21, in <module>
model.save(fname)
File "C:ProgramDataAnaconda3libsite-packagesgensimmodelsfasttext.py", line 1017, in save
super(FastText, self).save(*args, **kwargs)
File "C:ProgramDataAnaconda3libsite-packagesgensimmodelsase_any2vec.py", line 621, in save
super(BaseAny2VecModel, self).save(fname_or_handle, **kwargs)
File "C:ProgramDataAnaconda3libsite-packagesgensimutils.py", line 695, in save
self._smart_save(fname_or_handle, separately, sep_limit, ignore, pickle_protocol=pickle_protocol)
File "C:ProgramDataAnaconda3libsite-packagesgensimutils.py", line 547, in _smart_save
compress, subname)
File "C:ProgramDataAnaconda3libsite-packagesgensimutils.py", line 609, in _save_specials
restores.extend(val._save_specials(cfname, None, sep_limit, ignore, pickle_protocol, compress, subname))
File "C:ProgramDataAnaconda3libsite-packagesgensimutils.py", line 621, in _save_specials
np.save(subname(fname, attrib), np.ascontiguousarray(val))
File "C:ProgramDataAnaconda3libsite-packages
umpylib
pyio.py", line 536, in save
pickle_kwargs=pickle_kwargs)
File "C:ProgramDataAnaconda3libsite-packages
umpylibformat.py", line 644, in write_array
array.tofile(fp)
OSError: 418859700 requested and 0 written
I have previously trained the model with the window size set to be 9 and less. There was no problem at that time and no error appeared.
How can I fix this error?
question from:
https://stackoverflow.com/questions/65924072/typeerror-file-must-have-a-write-attribute