Github user davies commented on a diff in the pull request:
https://github.com/apache/spark/pull/2819#discussion_r18932968
--- Diff: python/pyspark/mllib/feature.py ---
@@ -95,90 +360,46 @@ class Word2Vec(object):
>>> sentence = "a b " * 100 + "a c " * 10
>>> localDoc = [sentence, sentence]
>>> doc = sc.parallelize(localDoc).map(lambda line: line.split(" "))
- >>> model = Word2Vec().setVectorSize(10).setSeed(42L).fit(doc)
+ >>> model = Word2Vec(vectorSize=10).fit(doc)
+
>>> syms = model.findSynonyms("a", 2)
- >>> str(syms[0][0])
- 'b'
- >>> str(syms[1][0])
- 'c'
- >>> len(syms)
- 2
+ >>> [s[0] for s in syms]
+ [u'b', u'c']
>>> vec = model.transform("a")
- >>> len(vec)
- 10
>>> syms = model.findSynonyms(vec, 2)
- >>> str(syms[0][0])
- 'b'
- >>> str(syms[1][0])
- 'c'
- >>> len(syms)
- 2
+ >>> [s[0] for s in syms]
+ [u'b', u'c']
"""
- def __init__(self):
+ def __init__(self, vectorSize=100, learningRate=0.025, numPartitions=1,
+ numIterations=1, seed=42L):
"""
Construct Word2Vec instance
- """
- self.vectorSize = 100
- self.learningRate = 0.025
- self.numPartitions = 1
- self.numIterations = 1
- self.seed = 42L
- def setVectorSize(self, vectorSize):
- """
- Sets vector size (default: 100).
+ :param vectorSize: vector size (default: 100).
+ :param learningRate: initial learning rate (default: 0.025).
+ :param numPartitions: number of partitions (default: 1). Use
+ a small number for accuracy.
+ :param numIterations: number of iterations (default: 1), which
should
+ be smaller than or equal to number of
partitions.
"""
--- End diff --
It's good to have same interface crossing languages, but sometimes it looks
wired to having the API that is designed for Java.
I'd like to simply the Python API a little bit (without introducing
confusing), then Python programmer can feel better (in this case). We can find
several similar cases in APIs of pyspark.RDD.
Does it make sense?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]