【问题标题】:Text preprocessing for fasttext pretrained modelsfasttext 预训练模型的文本预处理
【发布时间】:2021-12-19 10:41:10
【问题描述】:

我想使用预处理的 fastext 模型进行语言检测:https://fasttext.cc/docs/en/language-identification.html。在哪里可以找到用于训练此特定模型的文本预处理的确切的 Python 代码?我对我们应该如何为使用模型准备文本的一般答案不感兴趣 - 我正在寻找与用于训练的转换相同的转换。

【问题讨论】:

    标签: nlp text-processing text-classification fasttext


    【解决方案1】:

    当 Facebook 工程师在他们的 Github 存储库问题中被问到类似问题时,他们通常会在他们的公共代码中指出 one 或 the 中的其他两个 shell 脚本(尤其是其中的“normalize_text”函数) .

    https://github.com/facebookresearch/fastText/blob/master/tests/fetch_test_data.sh#L20

    normalize_text() {
      tr '[:upper:]' '[:lower:]' | sed -e 's/^/__label__/g' | \
        sed -e "s/'/ ' /g" -e 's/"//g' -e 's/\./ \. /g' -e 's/<br \/>/ /g' \
            -e 's/,/ , /g' -e 's/(/ ( /g' -e 's/)/ ) /g' -e 's/\!/ \! /g' \
            -e 's/\?/ \? /g' -e 's/\;/ /g' -e 's/\:/ /g' | tr -s " " | myshuf
    }
    

    https://github.com/facebookresearch/fastText/blob/master/get-wikimedia.sh#L12

    normalize_text() {
        sed -e "s/’/'/g" -e "s/′/'/g" -e "s/''/ /g" -e "s/'/ ' /g" -e "s/“/\"/g" -e "s/”/\"/g" \
            -e 's/"/ " /g' -e 's/\./ \. /g' -e 's/<br \/>/ /g' -e 's/, / , /g' -e 's/(/ ( /g' -e 's/)/ ) /g' -e 's/\!/ \! /g' \
            -e 's/\?/ \? /g' -e 's/\;/ /g' -e 's/\:/ /g' -e 's/-/ - /g' -e 's/=/ /g' -e 's/=/ /g' -e 's/*/ /g' -e 's/|/ /g' \
            -e 's/«/ /g' | tr 0-9 " "
    }
    

    他们还引用了this page's section on 'Tokenization'(它命名了一些库)和academic paper which describes the earlier work making individual language vectors。

    这些都不能保证与用于创建预训练分类模型的模型完全匹配,而且这些模型的每个版本都不包含要重现的确切代码,这有点令人沮丧。但是,这些来源似乎已经提供了尽可能多的详细信息,而没有从创建它们的团队那里得到直接的答案/帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-29
      • 1970-01-01
      • 2017-08-19
      • 2019-07-23
      • 2020-03-29
      • 1970-01-01
      相关资源
      最近更新 更多