简体   繁体   English

在 word tokenizer 中出现错误“AttributeError: 'numpy.ndarray' object has no attribute 'lower'”

[英]Getting error "AttributeError: 'numpy.ndarray' object has no attribute 'lower' " in word tokenizer

I am trying to train a model to classify multi-label data set by referring this article.我正在尝试通过参考这篇文章来训练一个模型来对多标签数据集进行分类。 I am entirely new to this field and I am getting this error "AttributeError: 'numpy.ndarray' object has no attribute 'lower'"我对这个领域完全陌生,我收到了这个错误“AttributeError: 'numpy.ndarray' object has no attribute 'lower'”

Here is my code这是我的代码

reviews = pd.read_csv("/content/drive/My Drive/Interim Project Data/score.csv")

Review_labels = reviews[["natral score", "man-made score", "sport score", "special event score"]]
Review_labels.head()

def preprocess_text(sen):
    # Remove punctuations and numbers
    sentence = re.sub('[^a-zA-Z]', ' ', sen)
    sentence = re.sub(r"\s+[a-zA-Z]\s+", ' ', sentence)
    sentence = re.sub(r'\s+', ' ', sentence)
    return sentence

X = []
sentences = list(reviews["User Review"])
for sen in sentences:
    X.append(preprocess_text(sen))

y = Review_labels.values

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.1, random_state=123)
print(len(X_train))
print(len(X_test))

from numpy import array
from keras.preprocessing.sequence import pad_sequences
from keras.preprocessing.text import Tokenizer


tokenizer = Tokenizer(num_words=5000)
tokenizer.fit_on_texts(X)

X_train = tokenizer.texts_to_sequences(X_train)
X_test = tokenizer.texts_to_sequences(X_test)

The error is here错误在这里

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-128-ff374d8c5eb4> in <module>()
      7 tokenizer.fit_on_texts(X)
      8 
----> 9 X_train = tokenizer.texts_to_sequences(X_train)
     10 X_test = tokenizer.texts_to_sequences(X_test)
     11 

2 frames
/usr/local/lib/python3.6/dist-packages/keras_preprocessing/text.py in text_to_word_sequence(text, filters, lower, split)
     41     """
     42     if lower:
---> 43         text = text.lower()
     44 
     45     if sys.version_info < (3,):

AttributeError: 'numpy.ndarray' object has no attribute 'lower'

here is the data set that I used in the code 这是我在代码中使用的数据集

It will be really helpful if someone can help with this issue.如果有人可以帮助解决这个问题,那将非常有帮助。

Is text a str variable? text是 str 变量吗? If it's not maybe you could do如果不是,也许你可以做

text = str(text).lower()

as long as it's value is something that can be turned into a string只要它的值是可以变成字符串的东西

How about trying试试怎么样

tokenizer = Tokenizer(num_words=5000, lower = False) tokenizer = Tokenizer(num_words=5000,lower = False)

instead of代替

tokenizer = Tokenizer(num_words=5000) tokenizer = Tokenizer(num_words=5000)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CountVectorizer: AttributeError: 'numpy.ndarray' object 没有属性 'lower' - CountVectorizer: AttributeError: 'numpy.ndarray' object has no attribute 'lower' 如何解决“AttributeError:&#39;numpy.ndarray&#39;对象没有属性&#39;lower&#39;”? - How solved "AttributeError: 'numpy.ndarray' object has no attribute 'lower'"? AttributeError: 'numpy.ndarray' object 没有属性 'lower' - AttributeError: 'numpy.ndarray' object has no attribute 'lower' 我如何通过消除错误来训练管道中的GaussianNB [AttributeError:&#39;numpy.ndarray&#39;对象没有属性&#39;lower&#39;] - How can i train GaussianNB in pipeline by removing error[AttributeError: 'numpy.ndarray' object has no attribute 'lower'] 'numpy.ndarray' 对象没有属性 'lower' - 'numpy.ndarray' object has no attribute 'lower' AttributeError:“ numpy.ndarray”对象没有属性“ A” - AttributeError: 'numpy.ndarray' object has no attribute 'A' AttributeError: 'numpy.ndarray' object has no attribute 'score' 错误 - AttributeError: 'numpy.ndarray' object has no attribute 'score' error AttributeError: 'numpy.ndarray' object 没有属性 'append' 错误 - AttributeError: 'numpy.ndarray' object has no attribute 'append' error AttributeError: &#39;numpy.ndarray&#39; 对象没有属性 &#39;lower&#39; 拟合逻辑模型数据 - AttributeError: 'numpy.ndarray' object has no attribute 'lower' fitting logistic model data AttributeError:“ numpy.ndarray”对象在tockenizer_left.texts_to_sequences(x_left)中没有属性“ lower” - AttributeError: 'numpy.ndarray' object has no attribute 'lower' in tockenizer_left.texts_to_sequences(x_left)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM