[ 
https://issues.apache.org/jira/browse/SPARK-6925?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

chrispy updated SPARK-6925:
---------------------------
    Description: 
{code}
  val doc = sc.textFile("/xxx/segrestxt", args(3).toInt).map(line => 
line.split(" ").toSeq)
  val model = new 
Word2Vec().setVectorSize(10).setSeed(42L).setNumIterations(3).fit(doc)
  val cpseeds = sc.textFile("/xxx/seeds/cp.tag", args(3).toInt)
{code} 
        
it will get a {{IllegalStateException}} and then exit app when tag is a word 
not in vocabulary, because {{findSynonyms}} method handle the possible 
IllegalStateException.  

{code}
  cpseeds.map {
    tag =>
      val syn = model.findSynonyms(tag, 30).map(l => l._1)
      tag + ":" + Joiner.on(" 
").join(JavaConversions.asJavaIterator(syn.toIterator))
  }.saveAsTextFile("/xxx/synonyms/cp")
{code}
        
developer need to catch the IllegalStateException to find out what's going on 
here.

{code}
  cpseeds.map {
    tag =>
      try {
        val syn = model.findSynonyms(tag, 30).map(l => l._1)
        tag + ":" + Joiner.on(" 
").join(JavaConversions.asJavaIterator(syn.toIterator))
      } catch {
        case e: IllegalStateException => log.error(s"cp tag:$tag", e)
      }
  }.saveAsTextFile("/xxx/synonyms/cp")
{code}

  was:
    val doc = sc.textFile("/xxx/segrestxt", args(3).toInt).map(line => 
line.split(" ").toSeq)
    val model = new 
Word2Vec().setVectorSize(10).setSeed(42L).setNumIterations(3).fit(doc)
        val cpseeds = sc.textFile("/xxx/seeds/cp.tag", args(3).toInt)
        
        // it got IllegalStateException then exit app when tag is a word not in 
vocabulary.
        // but findSynonyms method neither throw IllegalStateException nor try 
catch IllegalStateException.  
        cpseeds.map {
      tag =>
                val syn = model.findSynonyms(tag, 30).map(l => l._1)
                tag + ":" + Joiner.on(" 
").join(JavaConversions.asJavaIterator(syn.toIterator))
    }.saveAsTextFile("/xxx/synonyms/cp")
        
        // developer need try catch IllegalStateException
    cpseeds.map {
      tag =>
        try {
          val syn = model.findSynonyms(tag, 30).map(l => l._1)
          tag + ":" + Joiner.on(" 
").join(JavaConversions.asJavaIterator(syn.toIterator))
        } catch {
          case e: IllegalStateException => log.error(s"cp tag:$tag", e)
        }
    }.saveAsTextFile("/xxx/synonyms/cp")


> Word2Vec's transform method throw IllegalStateException if a word not in 
> vocabulary, but  findSynonyms(word: String, num: Int) method neither try 
> catch exception nor throw exception. 
> ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: SPARK-6925
>                 URL: https://issues.apache.org/jira/browse/SPARK-6925
>             Project: Spark
>          Issue Type: Bug
>          Components: MLlib
>    Affects Versions: 1.3.0
>            Reporter: chrispy
>            Priority: Minor
>              Labels: mllib, word2vec
>
> {code}
>   val doc = sc.textFile("/xxx/segrestxt", args(3).toInt).map(line => 
> line.split(" ").toSeq)
>   val model = new 
> Word2Vec().setVectorSize(10).setSeed(42L).setNumIterations(3).fit(doc)
>   val cpseeds = sc.textFile("/xxx/seeds/cp.tag", args(3).toInt)
> {code} 
>       
> it will get a {{IllegalStateException}} and then exit app when tag is a word 
> not in vocabulary, because {{findSynonyms}} method handle the possible 
> IllegalStateException.  
> {code}
>   cpseeds.map {
>     tag =>
>       val syn = model.findSynonyms(tag, 30).map(l => l._1)
>       tag + ":" + Joiner.on(" 
> ").join(JavaConversions.asJavaIterator(syn.toIterator))
>   }.saveAsTextFile("/xxx/synonyms/cp")
> {code}
>       
> developer need to catch the IllegalStateException to find out what's going on 
> here.
> {code}
>   cpseeds.map {
>     tag =>
>       try {
>         val syn = model.findSynonyms(tag, 30).map(l => l._1)
>         tag + ":" + Joiner.on(" 
> ").join(JavaConversions.asJavaIterator(syn.toIterator))
>       } catch {
>         case e: IllegalStateException => log.error(s"cp tag:$tag", e)
>       }
>   }.saveAsTextFile("/xxx/synonyms/cp")
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

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

Reply via email to