Word2VecModel

class pyspark.mllib.feature.Word2VecModel(java_model: py4j.java_gateway.JavaObject)

class for Word2Vec model

Methods

call(name, *a)

Call method of java_model

findSynonyms(word, num)

Find synonyms of a word

getVectors()

Returns a map of words to their vector representations.

load(sc, path)

Load a model from the given path.

save(sc, path)

Save this model to the given path.

transform(word)

Transforms a word to its vector representation

Methods Documentation

call(name: str, *a: Any) → Any

Call method of java_model

findSynonyms(word: Union[str, VectorLike], num: int) → Iterable[Tuple[str, float]]

Find synonyms of a word

Parameters
wordstr or pyspark.mllib.linalg.Vector

a word or a vector representation of word

numint

number of synonyms to find

Returns
collections.abc.Iterable

array of (word, cosineSimilarity)

Notes

Local use only

getVectors() → py4j.java_collections.JavaMap

Returns a map of words to their vector representations.

classmethod load(sc: pyspark.context.SparkContext, path: str)pyspark.mllib.feature.Word2VecModel

Load a model from the given path.

save(sc: pyspark.context.SparkContext, path: str) → None

Save this model to the given path.

transform(word: str)pyspark.mllib.linalg.Vector

Transforms a word to its vector representation

Parameters
wordstr

a word

Returns
pyspark.mllib.linalg.Vector

vector representation of word(s)

Notes

Local use only