Fasttext Fatal Python error: Floating point exception in Docker gitlab runner test

Fasttext Fatal Python error: Floating point exception in Docker gitlab runner test

我正在 docker 运行ner 中对 Fasttext 包装器进行一些测试。这是测试:

import fasttext
import tempfile

def test_fasttext_fit_save():
    x_clean = [
            "comment important one",
            "this is other comment",
            "this is other comment",
            "hi this is a comment",
        ]
    temp = tempfile.NamedTemporaryFile("w+", suffix=".txt")
    for com in x_clean:
        temp.write(com)
        temp.write("\n")
    temp.seek(0)

    model = fasttext.train_unsupervised(input=temp.name,
        dim=3,
        epoch=25,
        lr=0.1,
        minCount=1,
        word_ngrams=1,
        bucket=2000000,
    )
    # Test save
    model.save("model.bin")

但是,当 运行 在 gitlab 中 docker 运行 我得到:

test_fasttext_fit_save Fatal Python error: Floating point exception

并且没有显示更多。做这个测试的时候在我的电脑上安装了docker,这个运行好。

docker 文件有这个:

FROM python:3.8

# Upgrade pip
RUN pip install --upgrade pip
RUN pip install --upgrade setuptools wheel

# Install dependencies
RUN pip install fasttext
RUN pip install tempfile
RUN python -c "import fasttext; print(fasttext)"
RUN pip install pytest==6.0.1
RUN pip install pytest-cov==2.10.1
RUN pip install pytest-testmon
...

我的电脑有 4GB 和 运行ner 1GB,但测试没有使用 1GB 内存。

这似乎是内存问题,不是因为您 运行 的代码实际上需要它,而是因为 fasttext (facebook) 需要最少的 RAM 才能正确 运行 东西,例如,这个也发生在先知身上。

一个很好的选择是使用 gensim 的 fasttext 实现。