facebookresearch / fastText

Library for fast text representation and classification.
https://fasttext.cc/
MIT License
25.83k stars 4.71k forks source link

RuntimeError: Encountered NaN in train_unsupervised mode #1278

Open ptynecki opened 2 years ago

ptynecki commented 2 years ago

Hello,

During the training unsupervised fastText model I received the exception RuntimeError: Encountered NaN.. It has happened a few minutes after it started the training. I am using fastText packge v0.9.2 on Ubuntu 20.04 x64 with Python 3.8.10.

Verbose log:

Read 1856M words
Number of words:  4097
Number of labels: 0
Progress:   7.0% words/sec/thread:   11799 lr:  0.023248 avg.loss:  7.232708 ETA:   6h21m 0s

The code:

input_data = CORPUS_FILE
model = "cbow"
lr = 0.025
dim = 100
ws = 5
epoch = 10
min_count = 5
neg = 10
wordNgrams = 3
loss = "ns"
thread = mp.cpu_count()
t = 1e-3

embedding_model = fasttext.train_unsupervised(
    input=input_data,
    model=model,
    dim=dim,
    epoch=epoch,
    lr=lr,
    thread=thread,
    loss=loss,
    minCount=min_count,
    ws=ws,
    t=t,
    neg=neg,
    verbose=2
)

The output:

File ~/env/lib/python3.8/site-packages/fasttext/FastText.py:559, in train_unsupervised(*kargs, **kwargs)
    557 a = _build_args(args, manually_set_args)
    558 ft = _FastText(args=a)
--> 559 fasttext.train(ft.f, a)
    560 ft.set_args(ft.f.getArgs())
    561 return ft

RuntimeError: Encountered NaN.

The problem was not possible to reproduce with other CORPUS_FILES or with the same CORPUS_FILE as in above example but with "skipgram".

What can cause it?

Thanks for your help.

ucas010 commented 1 year ago

hello , I got the same problem , how to solve it ? model ="skipgram"

ucas010 commented 1 year ago

this could be the answer, https://github.com/facebookresearch/fastText/issues/638#issuecomment-440605929