【问题标题】:Can not train from text file in fasttext. Getting ValueError: Empty vocabulary无法从 fasttext 中的文本文件进行训练。获取 ValueError:空词汇表
【发布时间】:2019-11-24 05:19:30
【问题描述】:

我正在尝试使用以下代码创建 fasttext word embedding

import fasttext
from os import path
txt_path = path.join("/home/ccse/FastText_embeddings", "train.txt")
model = fasttext.train_unsupervised(txt_path, model='cbow')

这里 train.txt 包含一行 - “祝你有美好的一天。”

运行代码后出现如下错误:

Read 0M words
Number of words:  0
Number of labels: 0
Traceback (most recent call last):
  File "ft_embedding.py", line 4, in <module>
    model = fasttext.train_unsupervised(txt, model='cbow')
  File "/home/ccse/.local/lib/python3.6/site-packages/fasttext/FastText.py", line 455, in train_unsupervised
    fasttext.train(ft.f, a)
ValueError: Empty vocabulary. Try a smaller -minCount value.

我不明白它的原因以及如何解决它。

附加信息: 我在跑步- Ubuntu 18.04, 蟒蛇3.6.8, 快速文本 0.9.1

【问题讨论】:

    标签: python-3.x word-embedding fasttext


    【解决方案1】:

    我得到了解决方案。我犯了一个愚蠢的错误。把解决方案留在这里,以防有人犯了和我一样的愚蠢错误。

    minCount 的默认值设置为 5。由于我的火车文件仅包含 1 行,每个单词仅出现一次,因此我遇到了该错误。 要修复它,我只需要更改参数值。

    model = fasttext.train_unsupervised(txt_path, model='cbow', minCount = 1)
    

    在现实生活中创建嵌入时(不是为了测试功能),我们将使用大型语料库。在那种情况下,我们不应该面对这个问题。

    【讨论】:

      猜你喜欢
      • 2018-05-21
      • 2018-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-19
      • 1970-01-01
      • 2020-09-11
      • 2019-06-23
      相关资源
      最近更新 更多