Keras 和深度學習非常新,但我正在遵循在線指南,我正在嘗試標記我的文本,以便在我為神經網絡創建層時可以訪問“形狀”以用作“input_shape”。到目前為止,這是我的代碼: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 setX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=21) # Create tokenizertokenizer = 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 binaryencoder = 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任何人都可以發現我的錯誤并可能為此提供解決方案嗎?我對此很陌生,無法解決此問題。我希望能夠調用“X_train.shape”,以便在創建網絡層時將其輸入到 input_shape 中。任何幫助都會很棒!
嘗試在 Keras 中標記文本時出錯?
慕婉清6462132
2021-09-25 14:34:19