Description

Word2vec is a group of related models that are used to produce word embeddings. These models are shallow, two-layer neural networks that are trained to reconstruct linguistic contexts of words.

reference: https://en.wikipedia.org/wiki/Word2vec Mikolov, Tomas; et al. (2013). “Efficient Estimation of Word Representations in Vector Space” Mikolov, Tomas; Sutskever, Ilya; Chen, Kai; Corrado, Greg S.; Dean, Jeff (2013). Distributed representations of words and phrases and their compositionality. https://code.google.com/archive/p/word2vec/

Parameters

Name Description Type Required? Default Value
numIter Number of iterations, The default value is 1 Integer 1
selectedCol Name of the selected column used for processing String
vectorSize vector size of embedding Integer 100
alpha learning rate of sgd Double 0.025
wordDelimiter Delimiter of words String “ “
minCount minimum count of word Integer 5
randomWindow Is random window or not String “true”
window the length of window in w2v Integer 5

Script Example

Code

  1. import numpy as np
  2. import pandas as pd
  3. data = np.array([
  4. ["A B C"]
  5. ])
  6. df = pd.DataFrame({"tokens": data[:, 0]})
  7. inOp1 = dataframeToOperator(df, schemaStr='tokens string', op_type='batch')
  8. inOp2 = dataframeToOperator(df, schemaStr='tokens string', op_type='stream')
  9. train = Word2VecTrainBatchOp().setSelectedCol("tokens").setMinCount(1).setVectorSize(4).linkFrom(inOp1)
  10. predictBatch = Word2VecPredictBatchOp().setSelectedCol("tokens").linkFrom(train, inOp1)
  11. [model,predict] = collectToDataframes(train, predictBatch)
  12. print(model)
  13. print(predict)
  14. predictStream = Word2VecPredictStreamOp(train).setSelectedCol("tokens").linkFrom(inOp2)
  15. predictStream.print(refreshInterval=-1)
  16. StreamOperator.execute()

Results

Model
  1. rowID word vec
  2. 0 C 0.8955382525715048 0.7260255668945033 0.153084...
  3. 1 B 0.3799129268855519 0.09451568997723046 0.03543...
  4. 2 A 0.9284417086503712 0.7607143212094577 0.417053...
Prediction
  1. rowID tokens
  2. 0 0.7346309627024759 0.5270851926937304 0.201858...