Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Multithreading Spark在读取ML模型时创建的线程太多_Multithreading_Apache Spark_Machine Learning_Apache Spark Mllib_Multilabel Classification - Fatal编程技术网

Multithreading Spark在读取ML模型时创建的线程太多

Multithreading Spark在读取ML模型时创建的线程太多,multithreading,apache-spark,machine-learning,apache-spark-mllib,multilabel-classification,Multithreading,Apache Spark,Machine Learning,Apache Spark Mllib,Multilabel Classification,我有一个多标签文本分类问题,我试图使用二进制关联方法解决这个问题,方法是为每个标签创建一个二进制分类器。 我必须阅读10000个模型分类器,在我的培训阶段之后,使用spark对我的所有文档执行分类阶段。 但不知什么原因,当我尝试阅读1000多个模型时,它变得非常慢,因为spark每次都会创建一个新线程,这会逐渐减慢进程,我不知道为什么。 下面是说明我的问题的最小代码 package entrepot.spark; import java.io.FileNotFoundException; im

我有一个多标签文本分类问题,我试图使用二进制关联方法解决这个问题,方法是为每个标签创建一个二进制分类器。 我必须阅读10000个模型分类器,在我的培训阶段之后,使用spark对我的所有文档执行分类阶段。 但不知什么原因,当我尝试阅读1000多个模型时,它变得非常慢,因为spark每次都会创建一个新线程,这会逐渐减慢进程,我不知道为什么。 下面是说明我的问题的最小代码

package entrepot.spark;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.spark.ml.classification.MultilayerPerceptronClassificationModel;
import org.apache.spark.sql.SparkSession;

public class maintest {
    public static void main(String[] args) throws FileNotFoundException, IllegalArgumentException, IOException {
        try(SparkSession spark = SparkSession.builder().appName("test").getOrCreate()) {
            //Listing directories to get the list of labels
            Set<String> labels = new HashSet<>();
            FileStatus[] filesstatus = FileSystem.get(spark.sparkContext().hadoopConfiguration()).listStatus(new Path("C:\\Users\\*\\Desktop\\model\\"));
            for(int i = 0; i < filesstatus.length; i++) {
                if(filesstatus[i].isDirectory()) {
                    labels.add(filesstatus[i].getPath().getName());
                }
            }

            List<MultilayerPerceptronClassificationModel> models = new ArrayList<>();
            // Here is the problem
            for(String label : labels) {
                System.out.println(label);
                MultilayerPerceptronClassificationModel model = MultilayerPerceptronClassificationModel.load("C:\\Users\\*\\Desktop\\model\\" + label + "\\CL\\");
                models.add(model);
            }

            System.out.println("done");
        }
    }
}
要下载我的一个标签模型的一个小的重复示例,这里有一个链接:we.tl/T50s9UffYV(为什么我不能发布一个简单的链接??)


PS:即使模型是可序列化的,我也无法使用java集合和对象流同时保存和加载所有内容,因为我遇到了scala转换错误。相反,我在每个模型上使用MLLib中的save/load static方法,生成了数十万个文件。

我不得不问。。为什么要这样设置?多类应该在这方面做得更好。因为这是一个多标签分类问题,而不是多类。文档中有多少类可以分配给大声思考没有限制。。使用与word2vec相同的方法如何。在这些问题中,词汇量非常大,通过计算所有内部向量的余弦距离来预测正确的标签(中间词或周围词,取决于cbow或skip gram)。好吧,我没有想到这种方法,我将来会尝试一下,但它仍然不能解决我的问题:/。我不得不问。。为什么要这样设置?多类应该在这方面做得更好。因为这是一个多标签分类问题,而不是多类。文档中有多少类可以分配给大声思考没有限制。。使用与word2vec相同的方法如何。在这些问题中,词汇量非常大,通过计算所有内部向量的余弦距离来预测正确的标签(中间词或周围词,取决于cbow或skip gram)。好吧,我没有想到这种方法,我将来会尝试一下,但它仍然不能解决我的问题:/。
 .\bin\spark-submit^
 --class entrepot.spark.maintest^
 --master local[*]^
  /C:/Users/*/eclipse-workspace/spark/target/spark-0.0.1-SNAPSHOT.jar