预训练的 FastText 超参数

Pre-trained FastText hyperparameters

我正在使用预训练模型:

import fasttext.util 
fasttext.util.download_model('en', if_exists='ignore') # English 
ft = fasttext.load_model('cc.en.300.bin')

在哪里可以找到用于训练模型的超参数值的详尽列表? https://fasttext.cc/docs/en/options.html list the default values, that differ from the used one: for example, the dimension of the word vectors is 300 and not 100 (citing https://fasttext.cc/docs/en/crawl-vectors.html 没有全部列出)。

从查看 Facebook 来源中的 _FastText Python 模型 class...

https://github.com/facebookresearch/fastText/blob/a20c0d27cd0ee88a25ea0433b7f03038cd728459/python/fasttext_module/fasttext/FastText.py#L99

...看起来,至少在创建模型时,所有超参数都作为属性添加到对象上。

您是否检查过您加载的模型是否属于这种情况?例如,ft.dim 是否报告 300,而 ft.minCount 等其他参数是否报告任何有趣的内容?

更新: 由于这似乎没有用,它看起来也像 _FastText 模型包装了一个 internal native (not-in-Python) FastText 模型的实例在其 .f 属性中。 (请参阅我之前指出的源代码中的几行。)

并且该本地实例由 fasttext_pybind.cc 指定的模块设置。该代码看起来像是指定了一堆读写 class 变量,与元参数相关联 - 例如参见:

https://github.com/facebookresearch/fastText/blob/a20c0d27cd0ee88a25ea0433b7f03038cd728459/python/fasttext_module/fasttext/pybind/fasttext_pybind.cc#L88

那么:ft.f.minCountft.f.dim return 加载 post 的模型 ft 有什么用处吗?

引用 https://github.com/facebookresearch/fastText/issues/887#issuecomment-649018188 中的 NVS Abhilash,正确的代码是:

args_obj = ft.f.getArgs()
for hparam in dir(args_obj):
    if not hparam.startswith('__'):
        print(f"{hparam} -> {getattr(args_obj, hparam)}")

这将打印训练模型的所有超参数!