0
在深度學習中,如果我們具有不同長度的要素,則需要填充和遮罩。我正在開發一個使用RNN算法的情感分析程序。 在我的程序中,我正在嘗試添加值來屏蔽我創建的數組。但它給出了以下錯誤。Deeplearning:嘗試將值添加到掩碼數組時出錯
java.lang.IllegalArgumentException: Indexes, shape, and stride must be the same length
at org.nd4j.linalg.api.shape.Shape.getOffset(Shape.java:480)
at org.nd4j.linalg.api.ndarray.BaseNDArray.putScalar(BaseNDArray.java:1071)
at MovieReviewClassifierModel.predict(MovieReviewClassifierModel.java:80)
at org.apache.spark.ml.PredictionModel$$anonfun$1.apply(Predictor.scala:182)
at org.apache.spark.ml.PredictionModel$$anonfun$1.apply(Predictor.scala:181)
at org.apache.spark.sql.catalyst.expressions.ScalaUDF$$anonfun$2.apply(ScalaUDF.scala:75)
at org.apache.spark.sql.catalyst.expressions.ScalaUDF$$anonfun$2.apply(ScalaUDF.scala:74)
at org.apache.spark.sql.catalyst.expressions.ScalaUDF.eval(ScalaUDF.scala:964)
at org.apache.spark.sql.catalyst.expressions.GeneratedClass$SpecificMutableProjection.apply(Unknown Source)
at org.apache.spark.sql.execution.Project$$anonfun$1$$anonfun$apply$2.apply(basicOperators.scala:55)
at org.apache.spark.sql.execution.Project$$anonfun$1$$anonfun$apply$2.apply(basicOperators.scala:53)
at scala.collection.Iterator$$anon$11.next(Iterator.scala:328)
at scala.collection.Iterator$$anon$14.hasNext(Iterator.scala:389)
at scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:327)
at scala.collection.Iterator$$anon$10.hasNext(Iterator.scala:308)
at scala.collection.Iterator$class.foreach(Iterator.scala:727)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
at scala.collection.generic.Growable$class.$plus$plus$eq(Growable.scala:48)
at scala.collection.mutable.ArrayBuffer.$plus$plus$eq(ArrayBuffer.scala:103)
at scala.collection.mutable.ArrayBuffer.$plus$plus$eq(ArrayBuffer.scala:47)
at scala.collection.TraversableOnce$class.to(TraversableOnce.scala:273)
at scala.collection.AbstractIterator.to(Iterator.scala:1157)
at scala.collection.TraversableOnce$class.toBuffer(TraversableOnce.scala:265)
at scala.collection.AbstractIterator.toBuffer(Iterator.scala:1157)
at scala.collection.TraversableOnce$class.toArray(TraversableOnce.scala:252)
at scala.collection.AbstractIterator.toArray(Iterator.scala:1157)
at org.apache.spark.sql.execution.SparkPlan$$anonfun$5.apply(SparkPlan.scala:215)
at org.apache.spark.sql.execution.SparkPlan$$anonfun$5.apply(SparkPlan.scala:215)
at org.apache.spark.SparkContext$$anonfun$runJob$5.apply(SparkContext.scala:1858)
at org.apache.spark.SparkContext$$anonfun$runJob$5.apply(SparkContext.scala:1858)
at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:66)
at org.apache.spark.scheduler.Task.run(Task.scala:89)
at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:213)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
我想通過使用以下for循環來將值添加到掩碼數組。你能否向我解釋錯誤的原因以及如何解決這個問題。
int lengthOfFeatureArray=featureArray.length;
INDArray arr=Nd4j.create(featureArray);
INDArray featureMaskArray=Nd4j.zeros(maxLength);
int[] temp = new int[1];
for(int i=0;i<lengthOfFeatureArray;i++){
temp[0]=i;
featureMaskArray.putScalar(temp,1.0);
}
感謝您的快速響應。 –