第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何將 tokenizer.fit_on_texts() 應(yīng)用于包含兩列我需要訓(xùn)練的對(duì)象/字符串的

如何將 tokenizer.fit_on_texts() 應(yīng)用于包含兩列我需要訓(xùn)練的對(duì)象/字符串的

皈依舞 2023-06-20 13:43:24
我需要將兩組數(shù)據(jù)傳遞給tokenizer.fit_on_texts(),但遇到無(wú)法識(shí)別文本的問(wèn)題。tokenizer.word_index()返回的是數(shù)字 2。我懷疑問(wèn)題發(fā)生在tokenizer.fit_on_texts()我向它傳遞一個(gè)帶有 (33481, 2) 字符串的數(shù)據(jù)幀時(shí)。我看過(guò)的大多數(shù)示例都使用了 IMBD 數(shù)據(jù)集。附加信息:我目前正在試驗(yàn)多分類問(wèn)題,其中有帶有標(biāo)簽的標(biāo)題-文章對(duì)(同意、不同意、討論、不相關(guān))。我計(jì)劃使用 LSTM 和預(yù)訓(xùn)練的 Glove 創(chuàng)建映射到已知嵌入的單詞索引。資料:f_data -數(shù)據(jù)框 (33481, 2)列 = ['標(biāo)題','articleBody']。從另外兩個(gè) df [ x_train(26784, 2), val_train(6697, 2)]創(chuàng)建f_data[0]回報(bào)['kim yo jong 接替了 kim jong un role north ko...', 'san francisco marketwatch north korean leader...']這是創(chuàng)作的片段f_data:# This df will be fed into the fit_on_texts()# Creating df to contain the train and validation setf_data = pd.DataFrame(columns = ['Headline', 'articleBody'])# Adding data from x_train to f_dataf_data['Headline'] = x_train['Headline']f_data['articleBody'] = x_train['articleBody']# Appending x_val headline and article body columnsf_data = f_data.append(x_val[['Headline', 'articleBody']])f_dataKeras/TF 代碼問(wèn)題問(wèn)題:我遇到的問(wèn)題是,當(dāng)我打印出 word_index 的長(zhǎng)度時(shí),它返回 2:tokenizer.fit_on_texts(f_data[['Headline', 'articleBody']]sequences = tokenizer.texts_to_sequences(f_data[['Headline', 'articleBody']])word_index = tokenizer.word_indexprint('Vocab size:', len(word_index))>> Vocab size: 2data = pad_sequences(sequences, padding = 'post', maxlen = MAX_SEQ_LEN)print('Shape of data tensor:', data.shape)print('Shape of label tensor:', y_train_cat.shape)我試過(guò)變成f_datandarray 但得到一個(gè)屬性錯(cuò)誤。f_data_2 = np.array(f_data[['Headline', 'articleBody']]) # ndarraysequences = tokenizer.texts_to_sequences(apple)AttributeError: 'numpy.ndarray' object has no attribute 'lower'有什么建議么?我看過(guò)其他一些問(wèn)題,但他們正在處理一個(gè)字符串列表解決方案: 我想我終于有了一些工作,但我不完全確定這是正確的。f_data = np.c_[(np.array(f_data['Headline']), np.array(f_data['articleBody']))]f_data= f_data.tolist()....
查看完整描述

1 回答

?
狐的傳說(shuō)

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超3個(gè)贊

您可以分別對(duì)兩列進(jìn)行標(biāo)記,然后將它們輸入到兩個(gè)不同的輸入層,將它們連接起來(lái)并將它們輸入到 LSTM 層,對(duì)嗎?如果這種方法適合您,我可以解釋如何操作。


編輯:如果您習(xí)慣使用 Functional API,請(qǐng)生成對(duì)應(yīng)于 2 列的 2 個(gè)填充序列輸入,如下所示:


tokenizer.fit_on_texts(f_data['Headline'])

vocab_size = len(tokenizer.word_index) + 1


headline_sequences_train = tokenizer.texts_to_sequences(f_data['Headline'])

#headline_seq_validation = tokenizer.texts_to_sequences(val_data['Headline'])


headline_padded_train = pad_sequences(headline_sequences_train, padding='post', maxlen = MAX_SEQ_LEN)

#headline_padded_validation = pad_sequences(headline_seq_validation,padding = 'post',maxlen = MAX_SEQ_LEN)

同樣對(duì)于文章正文:


tokenizer.fit_on_texts(f_data['articleBody'])

vocab_size = len(tokenizer.word_index) + 1


art_body_seq_train = tokenizer.texts_to_sequences(f_data['articleBody'])

#art_body_seq_validation = tokenizer.texts_to_sequences(val_data['articleBody'])


art_body_padded_train = pad_sequences(art_body_seq_train, padding='post', maxlen = MAX_SEQ_LEN)

#art_body_padded_validation = pad_sequences(art_body_seq_validation, padding='post', maxlen = MAX_SEQ_LEN)

注意:對(duì)于兩個(gè)不同的列,MAX_SEQ_LEN 可能不同。取決于您的喜好。我建議你分別分析Headline和Article Body欄的字長(zhǎng),并選擇不同的看起來(lái)合適的最大序列長(zhǎng)度。


headline_padded_train并且art_body_padded_train是你的兩個(gè)輸入對(duì)應(yīng)于你的神經(jīng)網(wǎng)絡(luò)中的兩個(gè)輸入層。


查看完整回答
反對(duì) 回復(fù) 2023-06-20
  • 1 回答
  • 0 關(guān)注
  • 165 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)