/ /文字データを扱うニューラルネットワーク - r、ニューラルネットワーク

文字データを扱うニューラルネットワーク - r、ニューラルネットワーク

私はニューラルネットワークのパッケージライブラリ(ニューラルネット)を使ってセンチメント分析の基礎実験をしています。

the structure of my data is as follows:
"data.frame":   4442 obs. of  2 variables:
$ comment_text: chr  "really briliant apptit"s intuitive and informative giving all the information you could need and seemingly very accurate." "will not connect to gpstapp does not connect to gps no matter how long i have it on. i have gps set on high ac"| __truncated__ "wish this would interest more with google now to provide weekly or monthly summaries." "uselesstdoes not talk to gps on the phone. 20 minute run no data." ...
$ rating      : int  5 1 5 1 4 5 4 3 4 5 ...

私はこのデータを訓練とテストの部分にダイビングし、このようにニューラルネットワーク予測を実行しています:

senti_train <- nnsenti[1:3499, ]
senti_test <- nnsenti[3500:4443, ]
library(neuralnet)
neuralmodel <- neuralnet(rating ~ comment_text, data=senti_train)
plot(neuralmodel)

これを実行すると、このエラーが表示されます

Error in neurons[[i]] %*% weights[[i]] :
requires numeric/complex matrix/vector arguments

これをテキストとして解決する方法は重要な部分です

テキストデータをトークン化し、tmパッケージを使用してテキストを消去し、次のようにコードを更新しました:

nnsenti$comment_text <- VCorpus(VectorSource(nnsenti$comment_text))


#Text Cleaning
nnsenti$comment_text <- tm_map(nnsenti$comment_text,content_transformer(tolower))
nnsenti$comment_text <- tm_map(nnsenti$comment_text, removeNumbers)
nnsenti$comment_text <- tm_map(nnsenti$comment_text, removePunctuation)
nnsenti$comment_text <- tm_map(nnsenti$comment_text, removeWords,stopwords("english"))
nnsenti$comment_text <- tm_map(nnsenti$comment_text, removeWords,c("please","sad")) #Additional words
nnsenti$comment_text <- tm_map(nnsenti$comment_text, stripWhitespace)
senti_train <- nnsenti[1:3499, ]
senti_test <- nnsenti[3500:4443, ]

library(neuralnet)
neuralmodel <- neuralnet(rating ~ comment_text, data=senti_train)

今私はこのエラーを取得する

Error in model.frame.default(formula.reverse, data) :
invalid type (list) for variable "comment_text"

回答:

回答№1は0

あなたのデータを標準化していないようです。あなたのデータは、少なくともニューラルネットワークに数値的に供給されるべきです。 -1,1 または 0,1)。

テキストを正規化するには ワンホットエンコーディング。値をいくつかの最大値で割って格付けのように正規化する。最大評価= 10なので、すべての評価を10で割ります。