public static void main(String[] args){ W2VDistanceMeasurer vw2v = W2VDistanceMeasurer.getInstance(); double value = vw2v.vec.similarity("product", "item"); System.out.println(value); }
public void setStructure() { ArrayList<Attribute> att = new ArrayList<Attribute>(); // Add one attribute for each embedding dimension for (int i = 0; i < this.vec.getLayerSize(); i++) { att.add(new Attribute("embedding-" + i)); } att.add(new Attribute("word_id", (ArrayList<String>) null)); m_structure = new Instances("W2V model loaded from " + this.m_File.toString(), att, 0); }
if (vec.hasWord(curTokenText)) curVec = vec.getWordVectorMatrix(curTokenText); } else { if (vec.hasWord(curTokenText)) curVec = curVec.add(vec.getWordVectorMatrix(curTokenText));
vec.fit(); Collection<String> lst = vec.wordsNearest("french", 10); System.out.println(lst);
((org.deeplearning4j.models.word2vec.Word2Vec) vec).fit();
@Override public Instances getDataSet() throws IOException { if (m_sourceFile == null) { throw new IOException("No source has been specified"); } if (getRetrieval() == INCREMENTAL) { throw new IOException("This loader cannot load instances incrementally."); } setRetrieval(BATCH); if (m_structure == null) { getStructure(); } Instances result = new Instances(m_structure); for (String word : vec.getVocab().words()) { double[] values = new double[result.numAttributes()]; for (int i = 0; i < this.vec.getWordVector(word).length; i++) values[i] = this.vec.getWordVector(word)[i]; values[result.numAttributes() - 1] = result.attribute("word_id").addStringValue(word); Instance inst = new DenseInstance(1, values); inst.setDataset(result); result.add(inst); } return result; }
vec.fit(); } catch (IOException e) { Collection<String> lst = vec.wordsNearest("day", 10); System.out.println(lst);
double value = w2v.vec.similarity(lemma1, lemma2); results.add(w2vPrefix+new Float(value).toString());
sim = 1.0; else sim = vec.similarity(str1, str2);