2017-03-16 83 views
1

我使用Keras刚刚起步。试图导入base_filter进行文本预处理。我所做的:错误:从keras.preprocessing.text进口base_filter

from keras.preprocessing.text import base_filter 

我得到错误:

ImportError: cannot import name 'Base_filter' 

奇怪的是,我做了谷歌搜索,但没有找到该任何答案。任何人都知道哪里出了错?其中base_filter位于keras

非常感谢。

+0

请注明您的环境,keras,后端等版本。 :) –

+0

keras版本2.0.0我正在使用jupyter笔记本。后端是tensorflow。 – zesla

+0

答案有帮助吗? :-)如果你还没有看到它,请看下面的内容 –

回答

4

我想这是从Keras的新版本(2.0)即将到来的错误。更改是最近的,并且教程/文档可能不是最新的。

我们收到(like in the doc),对文本预处理功能filter=参数的默认值是一个函数“base_filter()”此功能将包含特殊字符的列表中删除。

在新版本中,你可以在源代码中看到,默认筛选器是不是base_filter()功能了,但直接的列表:

def text_to_word_sequence(text, 
          filters='!"#$%&()*+,-./:;<=>[email protected][\\]^_`{|}~\t\n', 
          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. 
    """ 

看到full code here

所以总结一下,该文档是不是最新的,功能base_filter()不会再在Keras 2.0存在。由base_filter过滤字符简单地通过人物的名单代替:'!"#$%&()*+,-./:;<=>[email protected][\\]^_ {|}〜\ t \ n'`

我希望这有助于。

+1

非常感谢!很好的帮助! @纳西姆本 – zesla