2017-03-16 48 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