在DL4J中的Doc2Vec, 或段落向量
Doc2Vec的主要目的是將任意文檔與標(biāo)簽關(guān)聯(lián),因此需要標(biāo)簽。Doc2Vec是Word2Vec的一個(gè)擴(kuò)展,它學(xué)習(xí)關(guān)聯(lián)標(biāo)簽和單詞,而不是用單詞關(guān)聯(lián)單詞。DL4J實(shí)現(xiàn)它的意圖是為了服務(wù)于Java、Scala和Culjule社區(qū)。
第一步是提出一個(gè)表示文檔“含義”的向量,然后可以將其用作有監(jiān)督的機(jī)器學(xué)習(xí)算法的輸入,來(lái)把文檔與標(biāo)簽相關(guān)聯(lián)。
在ParagraphVectors構(gòu)建器模式中,labels() 方法指向用于訓(xùn)練的標(biāo)簽。在下面的示例中,你可以看到與情感分析相關(guān)的標(biāo)簽:
.labels(Arrays.asList("negative", "neutral","positive"))

image.gif
下面是段落向量分類的可運(yùn)行的完整示例:
public void testDifferentLabels() throws Exception {
ClassPathResource resource = new ClassPathResource("/labeled");
File file = resource.getFile();
LabelAwareSentenceIterator iter = LabelAwareUimaSentenceIterator.createWithPath(file.getAbsolutePath());
TokenizerFactory t = new UimaTokenizerFactory();
ParagraphVectors vec = new ParagraphVectors.Builder()
.minWordFrequency(1).labels(Arrays.asList("negative", "neutral","positive"))
.layerSize(100)
.stopWords(new ArrayList<String>())
.windowSize(5).iterate(iter).tokenizerFactory(t).build();
vec.fit();
assertNotEquals(vec.lookupTable().vector("UNK"), vec.lookupTable().vector("negative"));
assertNotEquals(vec.lookupTable().vector("UNK"),vec.lookupTable().vector("positive"));
assertNotEquals(vec.lookupTable().vector("UNK"),vec.lookupTable().vector("neutral"));}

image.gif
延伸閱讀
翻譯:風(fēng)一樣的男子

image
如果您覺(jué)得我的文章給了您幫助,請(qǐng)為我買一杯飲料吧!以下是我的支付寶,意思一下我將非常感激!

image