亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

嘗試在 Keras 中標記文本時出錯?

嘗試在 Keras 中標記文本時出錯?

慕婉清6462132 2021-09-25 14:34:19
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 中。任何幫助都會很棒!
查看完整描述

1 回答

?
UYOU

TA貢獻1878條經驗 獲得超4個贊

您正在嘗試將 numpy 數組轉換為 python 整數,這當然是不可能的,并且會給您錯誤(該錯誤與 Keras 無關)。您真正想要做的是dtype將該 numpy 數組的更改為int. 請嘗試以下操作:

X_train.astype(np.int32)

代替 int(X_train)


查看完整回答
反對 回復 2021-09-25
  • 1 回答
  • 0 關注
  • 148 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號