[WIP][HIVEMALL-118] word2vec#116
Conversation
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package hivemall.unsupervised; |
There was a problem hiding this comment.
Please move package from hivemall.unsupervised to hivemall.embedding.
| import javax.annotation.Nonnegative; | ||
| import javax.annotation.Nonnull; | ||
|
|
||
| public abstract class AbstractWord2vecModel { |
There was a problem hiding this comment.
Please rename Word2vec to Word2Vec as seen in spark.
| } | ||
| } | ||
|
|
||
| protected static float sigmoid(final float v, final int MAX_SIGMOID, |
There was a problem hiding this comment.
No need to use Constants for argument: final int MAX_SIGMOID, final int SIGMOID_TABLE_SIZE
|
|
||
| public abstract class AbstractWord2VecModel { | ||
| // cached sigmoid function parameters | ||
| protected final int MAX_SIGMOID = 6; |
| protected static final int SIGMOID_TABLE_SIZE = 1000; | ||
| protected float[] sigmoidTable; | ||
|
|
||
|
|
|
|
||
| @Nonnegative | ||
| protected int dim; | ||
| protected int win; |
There was a problem hiding this comment.
@Nonnegative for each variable (win, neg, iter).
| protected Int2FloatOpenHashTable S; | ||
| protected int[] aliasWordId; | ||
|
|
||
| protected AbstractWord2VecModel(final int dim, final int win, final int neg, final int iter, |
There was a problem hiding this comment.
add @Nonnegative for each constructor argument and caller methods.
| } | ||
| } | ||
|
|
||
| protected static float sigmoid(final float v, final float[] sigmoidTable) { |
| } | ||
|
|
||
| protected void updateLearningRate() { | ||
| // TODO: valid lr? |
There was a problem hiding this comment.
remove this TODO comment and blank lines.
| import java.util.List; | ||
|
|
||
| public final class CBoWModel extends AbstractWord2VecModel { | ||
| protected CBoWModel(final int dim, final int win, final int neg, final int iter, |
There was a problem hiding this comment.
add a blank line before constructor.
|
|
||
| updateLearningRate(); | ||
|
|
||
| int docLength = doc.length; |
| opts.addOption("win", "window", true, "Context window size [default: 5]"); | ||
| opts.addOption("neg", "negative", true, | ||
| "The number of negative sampled words per word [default: 5]"); | ||
| opts.addOption("iter", "iteration", true, "The number of iterations [default: 5]"); |
There was a problem hiding this comment.
consistent naming "iters", "iterations" as seen in SLIM.
| opts.addOption("model", "modelName", true, | ||
| "The model name of word2vec: skipgram or cbow [default: skipgram]"); | ||
| opts.addOption( | ||
| "lr", |
There was a problem hiding this comment.
consistent naming eta0, learningRate for the initial learning rate.
There was a problem hiding this comment.
I see.
Does longOpt remain learningRate or remove this field?
There was a problem hiding this comment.
remain learningRate for longOpt and use eta0 for initialLearningRate.
| } | ||
|
|
||
| modelName = cl.getOptionValue("model", modelName); | ||
| if (!(modelName.equals("skipgram") || modelName.equals("cbow"))) { |
There was a problem hiding this comment.
"skipgram".equals(modelName) is null safe.
|
|
|
@myui I resolved conflicts. |
What changes were proposed in this pull request?
Add new algorithm: skip-gram with negative sampling (a.k.a word2vec)
What type of PR is it?
Feature
What is the Jira issue?
https://issues.apache.org/jira/browse/HIVEMALL-118
How was this patch tested?
manual tests on EMR
To train word2vec, I used wikipedia dataset, preprocessed by this perl script.
I evaluated word vector by https://github.com/kudkudak/word-embeddings-benchmarks .
CBoW model of hivemall
Skip-gram of hivemall
CBoW of hivemall when the number of reducer for training is 4
How to use this feature?
please see
word2vec.mdChecklist
mvn formatter:format, for your commit?