Hello everyone!
I'am using BigDL with Python for the language modeling. I'am trying to do word prediction using LSTM with GloVe.
I preprocessed sentences using Spark and know I have for the training set:
For example a sentence in the training set like "hi how are" + "you" becomes in Python a tuple like this: ([vector1,vector2,vector3],[vector_out])
From this tuples, which are stored in an RDD, I would like to create Samples in order to train LSTM.
The problem is that I don't know how to create a Sample RDD where training labels are vectors. I think I'am quite confused about Sample class.
I filled Sample.features with a matrix where each row is the vector representing a word. It should be ok, the LSTM layer will do the recurrence taking a row for each step.
What about Sample.labels? How can I train an LSTM in BigDL in order to get a model for tasks other than classification?
Sorry, I'am really new with the BigDL and Spark world. Thank you!
([vector1,vector2,vector3],[vector_out]) -> Sample(tensor, tensor) and a sample set can be represented as an RDD[Sample] for training or validation.
There’s a similar notebook example for this which is also base on LSTM and GloVe: https://github.com/intel-analytics/BigDL/tree/v0.1.1/pyspark/bigdl/models/textclassifier.
Thanks,
Zhichao
From: bigdl-us...@googlegroups.com [mailto:bigdl-us...@googlegroups.com]
On Behalf Of Mario Ruggieri
Sent: Thursday, June 22, 2017 8:13 PM
To: BigDL User Group <bigdl-us...@googlegroups.com>
Subject: [bigdl-user-group] Language modeling using LSTM in BigDL
Hello everyone!
I'am using BigDL with Python for the language modeling. I'am trying to do word prediction using LSTM with GloVe.
I preprocessed sentences using Spark and know I have for the training set:
For example a sentence in the training set like "hi how are" + "you" becomes in Python a tuple like this: ([vector1,vector2,vector3],[vector_out])
From this tuples, which are store in an RDD, I would like to create Samples in order to train LSTM.
The problem is that I don't know how to create a Sample RDD where training labels are vectors. I think I'am quite confused about Sample class.
I filled Sample.features with a matrix where each row is the vector representing a word. It should be ok, the LSTM layer will be the recurrence taking a row for each step.
What about Sample.labels? How can I train an LSTM in BigDL in order to get a model for tasks other than classification?
Sorry, I'am really new with the BigDL and Spark world. Thank you!
--
You received this message because you are subscribed to the Google Groups "BigDL User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
bigdl-user-gro...@googlegroups.com.
To post to this group, send email to
bigdl-us...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/bigdl-user-group/5146bfaf-8100-4554-8ba5-7347acd4087a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
2017-06-27 12:04:09 ERROR ThreadPool$:115 - Error: java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 4800
at java.util.Arrays.rangeCheck(Arrays.java:120)
at java.util.Arrays.fill(Arrays.java:3114)
at com.intel.analytics.bigdl.tensor.ArrayStorage.fill(ArrayStorage.scala:61)
at com.intel.analytics.bigdl.tensor.ArrayStorage.fill(ArrayStorage.scala:23)
at com.intel.analytics.bigdl.tensor.DenseTensor.fill(DenseTensor.scala:230)
at com.intel.analytics.bigdl.tensor.DenseTensor.zero(DenseTensor.scala:243)
at com.intel.analytics.bigdl.nn.TimeDistributedCriterion.updateGradInput(TimeDistributedCriterion.scala:115)
at com.intel.analytics.bigdl.nn.TimeDistributedCriterion.updateGradInput(TimeDistributedCriterion.scala:36)
at com.intel.analytics.bigdl.nn.abstractnn.AbstractCriterion.backward(AbstractCriterion.scala:81)
at com.intel.analytics.bigdl.optim.DistriOptimizer$$anonfun$4$$anonfun$5$$anonfun$apply$2.apply$mcI$sp(DistriOptimizer.scala:200)
at com.intel.analytics.bigdl.optim.DistriOptimizer$$anonfun$4$$anonfun$5$$anonfun$apply$2.apply(DistriOptimizer.scala:191)
at com.intel.analytics.bigdl.optim.DistriOptimizer$$anonfun$4$$anonfun$5$$anonfun$apply$2.apply(DistriOptimizer.scala:191)
at com.intel.analytics.bigdl.utils.ThreadPool$$anonfun$1$$anon$4.call(ThreadPool.scala:112)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
What's wrong? Can you help me?
Thank you!
([vector1,vector2,vector3],[vector_out]) -> Sample(tensor, tensor) and a sample set can be represented as an RDD[Sample] for training or validation.
There’s a similar notebook example for this which is also base on LSTM and GloVe: https://github.com/intel-analytics/BigDL/tree/v0.1.1/pyspark/bigdl/models/textclassifier.
Thanks,
Zhichao
From: bigdl-us...@googlegroups.com [mailto:bigdl-us...@googlegroups.com] On Behalf Of Mario Ruggieri
Sent: Thursday, June 22, 2017 8:13 PM
To: BigDL User Group <bigdl-us...@googlegroups.com>
Subject: [bigdl-user-group] Language modeling using LSTM in BigDL
Hello everyone!
I'am using BigDL with Python for the language modeling. I'am trying to do word prediction using LSTM with GloVe.
I preprocessed sentences using Spark and know I have for the training set:
- For each sentence a list of vectors, one for each word
- For each sentence the vector representing the last word which is the output
For example a sentence in the training set like "hi how are" + "you" becomes in Python a tuple like this: ([vector1,vector2,vector3],[vector_out])
From this tuples, which are store in an RDD, I would like to create Samples in order to train LSTM.
The problem is that I don't know how to create a Sample RDD where training labels are vectors. I think I'am quite confused about Sample class.
I filled Sample.features with a matrix where each row is the vector representing a word. It should be ok, the LSTM layer will be the recurrence taking a row for each step.
What about Sample.labels? How can I train an LSTM in BigDL in order to get a model for tasks other than classification?
Sorry, I'am really new with the BigDL and Spark world. Thank you!
--
You received this message because you are subscribed to the Google Groups "BigDL User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bigdl-user-gro...@googlegroups.com.
To post to this group, send email to bigdl-u...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to bigdl-user-group+unsubscribe@googlegroups.com.
To post to this group, send email to bigdl-user-group@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bigdl-user-group/b0191178-164f-43e2-a612-8789fd8f9114%40googlegroups.com.
${SPARK_HOME}/bin/spark-submit \
--py-files ${PYTHON_API_ZIP_PATH}, [PATH TO lstm_word_prediction.py] \
--jars ${BigDL_JAR_PATH} \
--conf spark.driver.extraClassPath=${BigDL_JAR_PATH} \
--conf spark.executor.extraClassPath=bigdl-0.2.0-SNAPSHOT-jar-with-dependencies.jar \
--conf spark.executorEnv.PYTHONHASHSEED=${PYTHONHASHSEED} \
lstm_word_prediction.py
and this is for testing:
${SPARK_HOME}/bin/spark-submit \
--py-files ${PYTHON_API_ZIP_PATH}, [PATH TO lstm_word_prediction.py] \
--jars ${BigDL_JAR_PATH} \
--conf spark.driver.extraClassPath=${BigDL_JAR_PATH} \
--conf spark.executor.extraClassPath=bigdl-0.2.0-SNAPSHOT-jar-with-dependencies.jar \
--conf spark.executorEnv.PYTHONHASHSEED=${PYTHONHASHSEED} \
lstm_word_prediction.py \
--action test \
--modelPath [PATH TO MODEL]
Sorry for the code quality, it is in the experimental phase.
I hope you will help me, thank you so much!
To post to this group, send email to bigdl-us...@googlegroups.com.
Hi,
The Error throws at
at com.intel.analytics.bigdl.nn.TimeDistributedCriterion.updateGradInput(TimeDistributedCriterion.scala:115)
In the source code, it is gradInput.resizeAs(input).zero
If the input is an empty Tensor, the .zero operation will throw an error.
Could you please check the input size and share the example?
Bests,
Yan
To post to this group, send email to bigdl-us...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bigdl-user-group/b0191178-164f-43e2-a612-8789fd8f9114%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "BigDL User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
bigdl-user-gro...@googlegroups.com.
To post to this group, send email to
bigdl-us...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/bigdl-user-group/CAHvkTeHHzNENwezanzYZYZ68BCLdGBTu2myhFk_4WczURgqfog%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bigdl-user-group/b0191178-164f-43e2-a612-8789fd8f9114%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "BigDL User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bigdl-user-gro...@googlegroups.com.
To post to this group, send email to bigdl-u...@googlegroups.com.
| require(input.size(timeDim) == target.size(timeDim), | |
| s"target should have as many elements as input") | |
| gradInput.resizeAs(input).zero() | |
| val nstep = input.size(timeDim)
|
To view this discussion on the web visit https://groups.google.com/d/msgid/bigdl-user-group/b0191178-164f-43e2-a612-8789fd8f9114%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "BigDL User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bigdl-user-gro...@googlegroups.com.
To post to this group, send email to bigdl-u...@googlegroups.com.
Hi,
The input should be a 3D tensor. If there is only one utterance, please still add 1 additional dimension ahead to represent 1 batch size.
The target should be a 2D tensor. The first dimension should be the batch size.
Previously, You mentioned
“For example a sentence in the training set like "hi how are" + "you" becomes in Python a tuple like this: ([vector1,vector2,vector3],[vector_out])”
Do you mean the input is “hi how are” and the target is “you” ?
In this way, it is not a particular language model. The criterion should be a distance function?
If the input of the Recurrent layer is three words, the output will also be a three words predicting the next three words. Please add a Select(2, -1) layer to let model select the last output as the predicted word, and use some Distance function as criterion to measure the closeness of the predicted word and target word?
To post to this group, send email to
bigdl-us...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/bigdl-user-group/1aec6d21-626a-487a-aa7f-bc9abd51cee6%40googlegroups.com.
Hi,
The CosineEmbeddingCriterion can be used to evaluate the distance between the continuous output and target.
To view this discussion on the web visit https://groups.google.com/d/msgid/bigdl-user-group/23f9e0df-7006-41f2-aa3d-566f9e1fc90c%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to bigdl-user-group+unsubscribe@googlegroups.com.
To post to this group, send email to bigdl-user-group@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bigdl-user-group/5abe1acc-c8e5-44d2-a073-85f41054ebed%40googlegroups.com.
:from bigdl.nn.layer import *
from bigdl.nn.criterion import *
from bigdl.optim.optimizer import *
from bigdl.util.common import *
input = np.random.uniform(0, 1, (3, 5)).astype("float32")
target = np.random.uniform(0, 1, (3)).astype("float32")
sample = Sample.from_ndarray(input, target)
> sample
<bigdl.util.common.Sample at 0x7f7bf497ad50>
> input
array([[ 0.9237712 , 0.68297315, 0.49127841, 0.33461636, 0.74126232],
[ 0.87127173, 0.75266618, 0.02735208, 0.58697593, 0.98401189],
[ 0.46674389, 0.54515141, 0.31183699, 0.80972594, 0.70999968]], dtype=float32)
> target
array([ 0.83898467, 0.45599914, 0.49628651], dtype=float32)