错误:从 keras.preprocessing.text 导入base_filter



我刚开始使用Keras。刚刚尝试导入base_filter进行文本预处理。我做了:

from keras.preprocessing.text import base_filter

我收到错误:

ImportError: cannot import name 'Base_filter'

令人惊讶的是,我做了谷歌搜索,找不到任何答案。有谁知道出了什么问题? base_filter在凯拉斯的位置

在哪里

多谢。

我想这是来自新版本 Keras (2.0( 的错误。更改是最新的,教程/文档可能不是最新的。

我们之前(就像在文档中一样(文本预处理函数中filter=参数的默认值是一个函数"base_filter()"这个函数将包含要删除的特殊字符列表。

在新版本中,正如您在源代码中看到的那样,默认过滤器不再是base_filter()功能,而是直接列表:

def text_to_word_sequence(text,
                          filters='!"#$%&()*+,-./:;<=>?@[\]^_`{|}~tn',
                          lower=True, split=" "):
    """Converts a text to a sequence of word indices.
    # Arguments
        text: Input text (string).
        filters: Sequence of characters to filter out.
        lower: Whether to convert the input to lowercase.
        split: Sentence split marker (string).
    # Returns
        A list of integer word indices.
    """

在此处查看完整代码。

总而言之,该文档不是最新的,base_filter()的功能在 Keras 2.0 中不再存在。按base_filter过滤的字符只需替换为字符列表: '!"#$%&()*+,-./:;<=>?@[\]^_ {|}~\t''

我希望这有所帮助。

相关内容

最新更新