Word2VecModel

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

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]][source]

Find synonyms of a word

New in version 1.2.0.

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[source]

Returns a map of words to their vector representations.

New in version 1.4.0.

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

Load a model from the given path.

New in version 1.5.0.

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

Save this model to the given path.

New in version 1.3.0.

transform(word: str)pyspark.mllib.linalg.Vector[source]

Transforms a word to its vector representation

New in version 1.2.0.

Parameters
wordstr

a word

Returns
pyspark.mllib.linalg.Vector

vector representation of word(s)

Notes

Local use only