Github user Ishiihara commented on a diff in the pull request:

    https://github.com/apache/spark/pull/2356#discussion_r18122598
  
    --- Diff: python/pyspark/mllib/Word2Vec.py ---
    @@ -0,0 +1,124 @@
    +#
    +# Licensed to the Apache Software Foundation (ASF) under one or more
    +# contributor license agreements.  See the NOTICE file distributed with
    +# this work for additional information regarding copyright ownership.
    +# The ASF licenses this file to You under the Apache License, Version 2.0
    +# (the "License"); you may not use this file except in compliance with
    +# the License.  You may obtain a copy of the License at
    +#
    +#    http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +#
    +
    +"""
    +Python package for Word2Vec in MLlib.
    +"""
    +
    +from pyspark import PickleSerializer
    +
    +from pyspark.mllib.linalg import _convert_to_vector
    +
    +__all__ = ['Word2Vec', 'Word2VecModel']
    +
    +
    +class Word2VecModel(object):
    +    """
    +    class for Word2Vec model
    +    """
    +    def __init__(self, sc, java_model):
    +        """
    +        :param sc:  Spark context
    +        :param java_model:  Handle to Java model object
    +        """
    +        self._sc = sc
    +        self._java_model = java_model
    +
    +    def __del__(self):
    +        self._sc._gateway.detach(self._java_model)
    +
    +    def transform(self, word):
    +        result = self._java_model.transform(word)
    +        return 
PickleSerializer().loads(str(self._sc._jvm.SerDe.dumps(result)))
    +
    +    def findSynonyms(self, x, num):
    +        jlist = self._java_model.findSynonyms(x, num)
    +        words, similarity = 
PickleSerializer().loads(str(self._sc._jvm.SerDe.dumps(jlist)))
    +        return zip(words, similarity)
    +
    +
    +class Word2Vec(object):
    +    """
    +    Word2Vec creates vector representation of words in a text corpus.
    +    The algorithm first constructs a vocabulary from the corpus
    +    and then learns vector representation of words in the vocabulary.
    +    The vector representation can be used as features in
    +    natural language processing and machine learning algorithms.
    +
    +    We used skip-gram model in our implementation and hierarchical softmax
    +    method to train the model. The variable names in the implementation
    +    matches the original C implementation.
    +    For original C implementation, see https://code.google.com/p/word2vec/
    +    For research papers, see
    +    Efficient Estimation of Word Representations in Vector Space
    +    and
    +    Distributed Representations of Words and Phrases and their 
Compositionality.
    --- End diff --
    
    Done


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to