Keras和deep learning非常陌生,但我正在遵循在线指南,我正在尝试标记我的文本,以便在创建神经网络层时,可以访问“形状”作为“输入形状”。以下是我目前的代码:
df = pd.read_csv(pathname, encoding = "ISO-8859-1")
df = df[['content_cleaned', 'meaningful']]
df = df.sample(frac=1)
#Transposed columns into numpy arrays
X = np.asarray(df[['content_cleaned']])
y = np.asarray(df[['meaningful']])
#Split into training and testing set
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=21)
# Create tokenizer
tokenizer = Tokenizer(num_words=100) #No row has more than 100 words.
#Tokenize the predictors (text)
X_train = np.concatenate(tokenizer.sequences_to_matrix(int(X_train), mode="binary"))
X_test = np.concatenate(tokenizer.sequences_to_matrix(int(X_test), mode="binary"))
#Convert the labels to the binary
encoder = LabelBinarizer()
encoder.fit(y_train)
y_train = encoder.transform(y_train)
y_test = encoder.transform(y_test)
错误是突出显示:
X_train = tokenizer.sequences_to_matrix(int(X_train), mode="binary")
错误消息是:
TypeError: only length-1 arrays can be converted to Python scalars
谁能抓住我的错误,并可能提供解决方案?我对这一点还很陌生,还没能解决这个问题。
任何帮助都会很好!