我正在尝试设置一个简单的代码,在其中传递数据帧并使用 johnSnowLabs Spark-NLP 库提供的预训练解释管道对其进行测试。我正在使用 anaconda 的 jupyter 笔记本,并使用 apache toree 进行了 spark scala kernet 设置。每次我运行应该加载预训练管道的步骤时,它都会抛出一个 tensorflow 错误。有没有办法可以在本地 Windows 上运行它?
I was trying this in a maven project earlier and the same error had happened. Another colleague tried it on a linux system and it worked. Below is the code I have tried and the error that it gave.
import org.apache.spark.ml.PipelineModel
import com.johnsnowlabs.nlp.pretrained.PretrainedPipeline
import com.johnsnowlabs.nlp.SparkNLP
import org.apache.spark.sql.SparkSession
val spark: SparkSession = SparkSession
.builder()
.appName("test")
.master("local[*]")
.config("spark.driver.memory", "4G")
.config("spark.kryoserializer.buffer.max", "200M")
.config("spark.serializer", "org.apache.spark.serializer.KryoSerializer") …Run Code Online (Sandbox Code Playgroud) 我有一个要求,我必须在词形还原步骤中添加一个字典。在尝试在管道中使用它并执行 pipeline.fit() 时,我收到一个 arrayIndexOutOfBounds 异常。实现这一点的正确方法是什么?有什么例子吗?
我将 token 作为词形还原的 inputcol 和 lemma 作为 outputcol 传递。以下是我的代码:
// DocumentAssembler annotator
val document = new DocumentAssembler()
.setInputCol("text")
.setOutputCol("document")
// SentenceDetector annotator
val sentenceDetector = new SentenceDetector()
.setInputCols("document")
.setOutputCol("sentence")
// tokenizer annotaor
val token = new Tokenizer()
.setInputCols("sentence")
.setOutputCol("token")
import com.johnsnowlabs.nlp.util.io.ExternalResource
// lemmatizer annotator
val lemmatizer = new Lemmatizer()
.setInputCols(Array("token"))
.setOutputCol("lemma")
.setDictionary(ExternalResource("C:/data/notebook/lemmas001.txt","LINE_BY_LINE",Map("keyDelimiter"->",","valueDelimiter"->"|")))
val pipeline = new Pipeline().setStages(Array(document,sentenceDetector,token,lemmatizer))
val result= pipeline.fit(df).transform(df)
Run Code Online (Sandbox Code Playgroud)
错误信息是:
Name: java.lang.ArrayIndexOutOfBoundsException
Message: 1
StackTrace: at com.johnsnowlabs.nlp.util.io.ResourceHelper$$anonfun$flattenRevertValuesAsKeys$1$$anonfun$apply$14.apply(ResourceHelper.scala:315)
at com.johnsnowlabs.nlp.util.io.ResourceHelper$$anonfun$flattenRevertValuesAsKeys$1$$anonfun$apply$14.apply(ResourceHelper.scala:312)
at scala.collection.Iterator$class.foreach(Iterator.scala:891)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1334)
at …Run Code Online (Sandbox Code Playgroud)