Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-6926

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.

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Critical
    • Resolution: Duplicate
    • Affects Version/s: 1.3.0
    • Fix Version/s: None
    • Component/s: MLlib
    • Labels:
    • Flags:
      Important

      Description

        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 will get a IllegalStateException and then exit app when tag is a word not in vocabulary, because findSynonyms method handle the possible 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 to catch the IllegalStateException to find out what's going on here.

        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")
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                chrispy chrispy
                Shepherd:
                Xiangrui Meng
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: