小编Ben*_*ben的帖子

使用TensorFlow进行多标签文本分类

文本数据被组织为具有20,000个元素的向量,如[2,1,0,0,5,....,0].第i个元素表示文本中第i个单词的频率.

地面实况标签数据也表示为具有4,000个元素的向量,如[0,0,1,0,1,......,0].第i个元素指示第i个标签是否是文本的肯定标签.文本的标签数量因文本而异.

我有一个单标签文本分类的代码.

如何编辑以下代码进行多标签文本分类?

特别是,我想知道以下几点.

  • 如何使用TensorFlow计算精度.
  • 如何设置判断标签是正面还是负面的阈值.例如,如果输出为[0.80,0.43,0.21,0.01,0.32]且基本事实为[1,1,0,0,1],则得分超过0.25的标签应判断为正数.

谢谢.

import tensorflow as tf

# hidden Layer
class HiddenLayer(object):
    def __init__(self, input, n_in, n_out):
        self.input = input

        w_h = tf.Variable(tf.random_normal([n_in, n_out],mean = 0.0,stddev = 0.05))
        b_h = tf.Variable(tf.zeros([n_out]))

        self.w = w_h
        self.b = b_h
        self.params = [self.w, self.b]

    def output(self):
        linarg = tf.matmul(self.input, self.w) + self.b
        self.output = tf.nn.relu(linarg)

        return self.output

# output Layer
class OutputLayer(object):
    def __init__(self, input, n_in, n_out):
        self.input = input

        w_o = tf.Variable(tf.random_normal([n_in, n_out], mean = 0.0, stddev …
Run Code Online (Sandbox Code Playgroud)

python text-classification multilabel-classification tensorflow

34
推荐指数
2
解决办法
2万
查看次数

如何使用Apache PDFBox从PDF文件中提取文本

我想用Apache PDFBox从给定的PDF文件中提取文本.

我写了这段代码:

PDFTextStripper pdfStripper = null;
PDDocument pdDoc = null;
COSDocument cosDoc = null;
File file = new File(filepath);

PDFParser parser = new PDFParser(new FileInputStream(file));
parser.parse();
cosDoc = parser.getDocument();
pdfStripper = new PDFTextStripper();
pdDoc = new PDDocument(cosDoc);
pdfStripper.setStartPage(1);
pdfStripper.setEndPage(5);
String parsedText = pdfStripper.getText(pdDoc);
System.out.println(parsedText);
Run Code Online (Sandbox Code Playgroud)

但是,我收到以下错误:

Exception in thread "main" java.lang.NullPointerException
at org.apache.fontbox.afm.AFMParser.main(AFMParser.java:304)
Run Code Online (Sandbox Code Playgroud)

我将pdfbox-1.8.5.jar和fontbox-1.8.5.jar添加到类路径中.

编辑

我添加System.out.println("program starts");到程序的开头.

我运行它,然后我得到了与上面提到的相同的错误,program starts并没有出现在控制台中.

因此,我认为我的课程路径有问题.

谢谢.

java pdfbox

26
推荐指数
3
解决办法
7万
查看次数

Android:如何将字节数组转换为Bitmap?

我正在尝试将一个图像从byte []转换为Bitmap以在Android应用程序中显示图像.

byte []的值是由数据库得到的,我检查它不是null.在那之后,我想转换图像,但无法成功.该程序显示Bitmap的值为null.

我认为在转换过程中存在一些问题.

如果您有任何提示,请告诉我.

byte[] image = null;
Bitmap bitmap = null;
        try {
            if (rset4 != null) {
                while (rset4.next()) {
                    image = rset4.getBytes("img");
                    BitmapFactory.Options options = new BitmapFactory.Options();
                    bitmap = BitmapFactory.decodeByteArray(image, 0, image.length, options);
                }
            }
            if (bitmap != null) {
                ImageView researcher_img = (ImageView) findViewById(R.id.researcher_img);
                researcher_img.setImageBitmap(bitmap);
                System.out.println("bitmap is not null");
            } else {
                System.out.println("bitmap is null");
            }

        } catch (SQLException e) {

        }
Run Code Online (Sandbox Code Playgroud)

android bytearray bitmap

10
推荐指数
2
解决办法
4万
查看次数

Java中如何从HTTP请求中获取JSON对象

我现在尝试使用 Java cord 中的 HTTP 请求获取 JSON 对象。

我想知道如何在下面的代码中获取响应或 JSON 对象。

请告诉我。

(在这个程序中,我尝试获取文章“纽约”的维基百科类别。)

 String requestURL = "http://en.wikipedia.org/w/api.php?action=query&prop=categories&format=json&clshow=!hidden&cllimit=10&titles=" + words[i];
 URL wikiRequest = new URL(requestURL);
 URLConnection connection = wikiRequest.openConnection();  
 connection.setDoOutput(true);  

                    /**** I'd like to get response here. ****/

 JSONObject json = Util.parseJson(response);
Run Code Online (Sandbox Code Playgroud)

java json httprequest

6
推荐指数
1
解决办法
7万
查看次数

用于大型数据集的主题建模工具(30GB)

我正在寻找一些适用于大型数据集的主题建模工具.

我目前的培训数据集是30 GB.我尝试过MALLET主题建模,但总是得到OutOfMemoryError.

如果您有任何提示,请告诉我.

lda topic-modeling

5
推荐指数
1
解决办法
2454
查看次数

Java listFiles()默认读取目录中的文件的顺序是什么?

我制作了以下程序,它读取目录中的所有文件.所有文件名都由数字组成(例如10023134.txt).

File dir = new File(directoryPath);
File[] files = dir.listFiles();
for (File file : files)
    try {
        if ( !file.exists())
            continue;
        else if (file.isFile()) {
            // some process
        }
    } catch (Exception e) {}
Run Code Online (Sandbox Code Playgroud)

我想知道默认情况下读取目录中文件的顺序.

似乎程序既不按数字顺序也不按创建日期顺序读取文件.

java java-io

2
推荐指数
2
解决办法
700
查看次数

MALLET主题建模OutOfMemoryError

我使用MALLET进行主题建模.
http://mallet.cs.umass.edu/topics.php

首先,我尝试按照说明导入训练文档集.

bin/mallet import-dir --input /data/topic-input --output topic-input.mallet --keep-sequence --remove-stopwords
Run Code Online (Sandbox Code Playgroud)

我总是得到OutOfMemoryError,虽然我"bin/mallet.bat"按照以下页面改变. Mallet主题建模

我设置set MALLET_MEMORY=32G.

我的数据集大小为30GB.

计算机内存就足够了.

我收到以下错误.

Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded
    at java.util.Arrays.copyOfRange(Arrays.java:3658)
    at java.lang.String.<init>(String.java:201)
    at java.lang.AbstractStringBuilder.substring(AbstractStringBuilder.java:909)
    at java.lang.StringBuffer.subSequence(StringBuffer.java:473)
    at cc.mallet.extract.StringSpan.constructTokenText(StringSpan.java:49)
    at cc.mallet.extract.StringSpan.<init>(StringSpan.java:33)
    at cc.mallet.pipe.CharSequence2TokenSequence.pipe(CharSequence2TokenSequence.java:68)
    at cc.mallet.pipe.Pipe$SimplePipeInstanceIterator.next(Pipe.java:294)
    at cc.mallet.pipe.Pipe$SimplePipeInstanceIterator.next(Pipe.java:282)
    at cc.mallet.pipe.Pipe$SimplePipeInstanceIterator.next(Pipe.java:290)
    at cc.mallet.pipe.Pipe$SimplePipeInstanceIterator.next(Pipe.java:282)
    at cc.mallet.pipe.Pipe$SimplePipeInstanceIterator.next(Pipe.java:290)
    at cc.mallet.pipe.Pipe$SimplePipeInstanceIterator.next(Pipe.java:282)
    at cc.mallet.pipe.Pipe$SimplePipeInstanceIterator.next(Pipe.java:290)
    at cc.mallet.pipe.Pipe$SimplePipeInstanceIterator.next(Pipe.java:282)
    at cc.mallet.types.InstanceList.addThruPipe(InstanceList.java:267)
    at cc.mallet.classify.tui.Text2Vectors.main(Text2Vectors.java:312)
$ bin/mallet import-dir --input ../Text --output topic-input.mallet --keep-sequence --remove-stopwords
Labels = 
   ../Text
Exception …
Run Code Online (Sandbox Code Playgroud)

java out-of-memory mallet

2
推荐指数
1
解决办法
941
查看次数