Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPARKNLP-873 Issue with MarianTransformers models #13908

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import org.apache.spark.ml.param.{IntArrayParam, IntParam, Param, StringArrayPar
import org.apache.spark.ml.util.Identifiable
import org.apache.spark.sql.SparkSession

import scala.jdk.CollectionConverters.asScalaBufferConverter

/** MarianTransformer: Fast Neural Machine Translation
*
* Marian is an efficient, free Neural Machine Translation framework written in pure C++ with
Expand Down Expand Up @@ -317,6 +319,13 @@ class MarianTransformer(override val uid: String)
/** @group setParam * */
def getModelIfNotSet: Marian = _model.get.value

def getVocabulary: Array[String] = {
if ($(vocabulary).isInstanceOf[java.util.ArrayList[String]]) {
val arrayListValue = $(vocabulary).asInstanceOf[java.util.ArrayList[String]]
arrayListValue.asScala.toArray
} else $(vocabulary)
}

setDefault(
maxInputLength -> 40,
maxOutputLength -> 40,
Expand Down Expand Up @@ -349,7 +358,7 @@ class MarianTransformer(override val uid: String)
sentences = allAnnotations.map(_._1),
maxInputLength = $(maxInputLength),
maxOutputLength = $(maxOutputLength),
vocabs = $(vocabulary),
vocabs = getVocabulary,
langId = $(langId),
batchSize = $(batchSize),
ignoreTokenIds = $(ignoreTokenIds))
Expand Down Expand Up @@ -441,7 +450,6 @@ trait ReadMarianMTDLModel extends ReadTensorflowModel with ReadSentencePieceMode
addReader(readModel)

def loadSavedModel(modelPath: String, spark: SparkSession): MarianTransformer = {

val (localModelPath, detectedEngine) = modelSanityCheck(modelPath)

val sppSrc = loadSentencePieceAsset(localModelPath, "source.spm")
Expand Down