• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Pair类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.deeplearning4j.berkeley.Pair的典型用法代码示例。如果您正苦于以下问题:Java Pair类的具体用法?Java Pair怎么用?Java Pair使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Pair类属于org.deeplearning4j.berkeley包,在下文中一共展示了Pair类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: init

import org.deeplearning4j.berkeley.Pair; //导入依赖的package包/类
private void init(String location) {
    csv = new File(location);
    pair = new HashMap<>();
    sentenceToPhrase = new HashMap<>();

    CSV csv1 = CSV.separator('\t')
            .ignoreLeadingWhiteSpace().skipLines(1)
            .create();
    //PhraseId	SentenceId	Phrase	Sentiment
    csv1.read(csv,new CSVReadProc() {
        @Override
        public void procRow(int rowIndex, String... values) {
            //sentence id -> phrase id
            List<String> phrases = sentenceToPhrase.get(values[1]);
            if(phrases == null) {
                phrases = new ArrayList<>();
                sentenceToPhrase.put(values[1],phrases);
            }

            phrases.add(values[2]);

            pair.put(values[0],new Pair<>(values[2],values[3]));
        }
    });
}
 
开发者ID:ihuerga,项目名称:deeplearning4j-nlp-examples,代码行数:26,代码来源:TextRetriever.java


示例2: predict

import org.deeplearning4j.berkeley.Pair; //导入依赖的package包/类
public List<Pair<String, Double>> predict(@NotNull String name, @NotNull SourceSegment source, @NotNull List<var> inputs) {

     /*
      Now we'll iterate over unlabeled data, and check which label it could be assigned to
      Please note: for many domains it's normal to have 1 document fall into few labels at once,
      with different "weight" for each.
     */
        MeansBuilder meansBuilder = new MeansBuilder((InMemoryLookupTable<VocabWord>) paragraphVectors.getLookupTable(),
                                                     tokenizerFactory);
        LabelSeeker seeker = new LabelSeeker(iterator.getLabelsSource().getLabels(),
                                             (InMemoryLookupTable<VocabWord>) paragraphVectors.getLookupTable());


        LabelledDocument document = new LabelledDocument();
        document.setContent(signatureToText(name, inputs));
        INDArray documentAsCentroid = meansBuilder.documentAsVector(document);
        List<Pair<String, Double>> scores = seeker.getScores(documentAsCentroid);
        return scores;

    }
 
开发者ID:sillelien,项目名称:dollar,代码行数:21,代码来源:ParagraphVectorsClassifierExample.java


示例3: getScores

import org.deeplearning4j.berkeley.Pair; //导入依赖的package包/类
/**
 * This method accepts vector, that represents any document,
 * and returns distances between this document, and previously trained categories
 * @return
 */
public List<Pair<String, Double>> getScores(@NonNull INDArray vector) {
    List<Pair<String, Double>> result = new ArrayList<>();
    for (String label: labelsUsed) {
        INDArray vecLabel = lookupTable.vector(label);
        if (vecLabel == null) throw new IllegalStateException("Label '"+ label+"' has no known vector!");

        double sim = Transforms.cosineSim(vector, vecLabel);
        result.add(new Pair<String, Double>(label, sim));
    }
    return result;
}
 
开发者ID:tteofili,项目名称:par2hier,代码行数:17,代码来源:LabelSeeker.java


示例4: testRetrieval

import org.deeplearning4j.berkeley.Pair; //导入依赖的package包/类
@Test
public void testRetrieval() throws  Exception {
    Map<String,Pair<String,String>> data = retriever.data();
    Pair<String,String> phrase2 = data.get("2");
    assertEquals("A series of escapades demonstrating the adage that what is good for the goose",phrase2.getFirst());
    assertEquals("2",phrase2.getSecond());

}
 
开发者ID:ihuerga,项目名称:deeplearning4j-nlp-examples,代码行数:9,代码来源:TextRetrieverTest.java


示例5: getScores

import org.deeplearning4j.berkeley.Pair; //导入依赖的package包/类
/**
 * This method accepts vector, that represents any document,
 * and returns distances between this document, and previously trained categories
 *
 * @return
 */
@Nonnull
public List<Pair<String, Double>> getScores(@Nonnull INDArray vector) {
    List<Pair<String, Double>> result = new ArrayList<>();
    for (String label : labelsUsed) {
        INDArray vecLabel = lookupTable.vector(label);
        if (vecLabel == null) throw new IllegalStateException("Label '" + label + "' has no known vector!");

        double sim = Transforms.cosineSim(vector, vecLabel);
        result.add(new Pair<>(label, sim));
    }
    return result;
}
 
开发者ID:sillelien,项目名称:dollar,代码行数:19,代码来源:LabelSeeker.java


示例6: predict

import org.deeplearning4j.berkeley.Pair; //导入依赖的package包/类
@Nullable
@Override
public TypePrediction predict(@NotNull String name, @NotNull SourceSegment source, @NotNull List<var> inputs) {
    try {
        List<Pair<String, Double>> scores = classifier.predict(name, source, inputs);
        log.info("Predictions: ");
        log.info("{}", scores);
        return new SmartTypePrediction(scores);
    } catch (Exception e) {
        log.debug(e.getMessage(), e);
        return new SingleValueTypePrediction(Type._ANY);
    }


}
 
开发者ID:sillelien,项目名称:dollar,代码行数:16,代码来源:SmartTypeLearner.java


示例7: probability

import org.deeplearning4j.berkeley.Pair; //导入依赖的package包/类
@Override
public @NotNull Double probability(@NotNull Type type) {
    for (Pair<String, Double> score : scores) {
        if (score.getFirst().equals(type.name())) {
            return score.getSecond() / 2 + 0.5;
        }
    }
    return 0.0;
}
 
开发者ID:sillelien,项目名称:dollar,代码行数:10,代码来源:SmartTypeLearner.java


示例8: probableType

import org.deeplearning4j.berkeley.Pair; //导入依赖的package包/类
@Override
public @Nullable Type probableType() {
    Pair<String, Double> max = scores.stream().max(Comparator.comparing(Pair::getSecond)).orElse(null);
    if (max != null) {
        return Type.of(max.getFirst());
    }
    return null;
}
 
开发者ID:sillelien,项目名称:dollar,代码行数:9,代码来源:SmartTypeLearner.java


示例9: checkUnlabeledData

import org.deeplearning4j.berkeley.Pair; //导入依赖的package包/类
void checkUnlabeledData() throws FileNotFoundException {
  /*
  At this point we assume that we have model built and we can check
  which categories our unlabeled document falls into.
  So we'll start loading our unlabeled documents and checking them
 */
    ClassPathResource unClassifiedResource = new ClassPathResource("paravec/unlabeled");
    FileLabelAwareIterator unClassifiedIterator = new FileLabelAwareIterator.Builder()
                                                          .addSourceFolder(unClassifiedResource.getFile())
                                                          .build();

 /*
  Now we'll iterate over unlabeled data, and check which label it could be assigned to
  Please note: for many domains it's normal to have 1 document fall into few labels at once,
  with different "weight" for each.
 */
    MeansBuilder meansBuilder = new MeansBuilder(
                                                        (InMemoryLookupTable<VocabWord>) paragraphVectors.getLookupTable(),
                                                        tokenizerFactory);
    LabelSeeker seeker = new LabelSeeker(iterator.getLabelsSource().getLabels(),
                                         (InMemoryLookupTable<VocabWord>) paragraphVectors.getLookupTable());

    while (unClassifiedIterator.hasNextDocument()) {
        LabelledDocument document = unClassifiedIterator.nextDocument();
        INDArray documentAsCentroid = meansBuilder.documentAsVector(document);
        List<Pair<String, Double>> scores = seeker.getScores(documentAsCentroid);

     /*
      please note, document.getLabel() is used just to show which document we're looking at now,
      as a substitute for printing out the whole document name.
      So, labels on these two documents are used like titles,
      just to visualize our classification done properly
     */
        log.info("Document '" + document.getLabel() + "' falls into the following categories: ");
        for (Pair<String, Double> score : scores) {
            log.info("        " + score.getFirst() + ": " + score.getSecond());
        }
    }

}
 
开发者ID:sillelien,项目名称:dollar,代码行数:41,代码来源:ParagraphVectorsClassifierExample.java


示例10: main

import org.deeplearning4j.berkeley.Pair; //导入依赖的package包/类
public static void main(String[] args) throws Exception {

        ClassPathResource resource = new ClassPathResource("paravec/labeled");

        iter = new FileLabelAwareIterator.Builder()
                .addSourceFolder(resource.getFile())
                .build();

        tFact = new DefaultTokenizerFactory();
        tFact.setTokenPreProcessor(new CommonPreprocessor());

        pVect = new ParagraphVectors.Builder()
                .learningRate(0.025)
                .minLearningRate(0.001)
                .batchSize(1000)
                .epochs(20)
                .iterate(iter)
                .trainWordVectors(true)
                .tokenizerFactory(tFact)
                .build();

        pVect.fit();


        ClassPathResource unlabeledText = new ClassPathResource("paravec/unlabeled");
        FileLabelAwareIterator unlabeledIter = new FileLabelAwareIterator.Builder()
                .addSourceFolder(unlabeledText.getFile())
                .build();


        MeansBuilder mBuilder = new MeansBuilder(
                (InMemoryLookupTable<VocabWord>) pVect.getLookupTable(),
                tFact);
        LabelSeeker lSeeker = new LabelSeeker(iter.getLabelsSource().getLabels(),
                (InMemoryLookupTable<VocabWord>) pVect.getLookupTable());

        while (unlabeledIter.hasNextDocument()) {
            LabelledDocument doc = unlabeledIter.nextDocument();
            INDArray docCentroid = mBuilder.documentAsVector(doc);
            List<Pair<String, Double>> scores = lSeeker.getScores(docCentroid);

            out.println("Document '" + doc.getLabel() + "' falls into the following categories: ");
            for (Pair<String, Double> score : scores) {
                out.println("        " + score.getFirst() + ": " + score.getSecond());
            }

        }
    }
 
开发者ID:PacktPublishing,项目名称:Machine-Learning-End-to-Endguide-for-Java-developers,代码行数:49,代码来源:ParagraphVectorsClassifierExample.java


示例11: data

import org.deeplearning4j.berkeley.Pair; //导入依赖的package包/类
public Map<String,Pair<String,String>> data() {
    return pair;
}
 
开发者ID:ihuerga,项目名称:deeplearning4j-nlp-examples,代码行数:4,代码来源:TextRetriever.java


示例12: checkUnlabelledData

import org.deeplearning4j.berkeley.Pair; //导入依赖的package包/类
private void checkUnlabelledData(Word2Vec paragraphVectors, LabelAwareIterator iterator, TokenizerFactory tokenizerFactory) throws FileNotFoundException {
  ClassPathResource unClassifiedResource = new ClassPathResource("papers/unlabeled");
  FileLabelAwareIterator unClassifiedIterator = new FileLabelAwareIterator.Builder()
      .addSourceFolder(unClassifiedResource.getFile())
      .build();

  MeansBuilder meansBuilder = new MeansBuilder(
      (InMemoryLookupTable<VocabWord>) paragraphVectors.getLookupTable(),
      tokenizerFactory);
  LabelSeeker seeker = new LabelSeeker(iterator.getLabelsSource().getLabels(),
      (InMemoryLookupTable<VocabWord>) paragraphVectors.getLookupTable());

  System.out.println(paragraphVectors + " classification results");
  double cc = 0;
  double size = 0;
  while (unClassifiedIterator.hasNextDocument()) {
    LabelledDocument document = unClassifiedIterator.nextDocument();
    INDArray documentAsCentroid = meansBuilder.documentAsVector(document);
    List<Pair<String, Double>> scores = seeker.getScores(documentAsCentroid);

    double max = -Integer.MAX_VALUE;
    String cat = null;
    for (Pair<String, Double> p : scores) {
      if (p.getSecond() > max) {
        max = p.getSecond();
        cat = p.getFirst();
      }
    }
    if (document.getLabels().contains(cat)) {
      cc++;
    }
    size++;

  }
  System.out.println("acc:" + (cc / size));

}
 
开发者ID:tteofili,项目名称:par2hier,代码行数:38,代码来源:Par2HierClassificationTest.java


示例13: SmartTypePrediction

import org.deeplearning4j.berkeley.Pair; //导入依赖的package包/类
public SmartTypePrediction(List<Pair<String, Double>> scores) {this.scores = scores;} 
开发者ID:sillelien,项目名称:dollar,代码行数:2,代码来源:SmartTypeLearner.java



注:本文中的org.deeplearning4j.berkeley.Pair类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java VideoOptions类代码示例发布时间:2022-05-22
下一篇:
Java IGaService类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap