@Test public void testListEncoding() { Document doc = DocumentFactory.fromText(bullets, DocumentFactory.Newlines.KEEP); StructureEncoder enc = new StructureEncoder(); enc.encodeEach(doc, Sentence.class); assertEquals(5, doc.countSentences()); assertEquals(Nd4j.create(new double[]{1,1,0,0,0,1,0}), doc.getSentence(0).getVector(StructureEncoder.class)); assertEquals(Nd4j.create(new double[]{0,1,1,0,0,1,0}), doc.getSentence(1).getVector(StructureEncoder.class)); assertEquals(Nd4j.create(new double[]{0,1,1,0,0,0,0}), doc.getSentence(2).getVector(StructureEncoder.class)); assertEquals(Nd4j.create(new double[]{0,0,0,0,0,1,0}), doc.getSentence(3).getVector(StructureEncoder.class)); assertEquals(Nd4j.create(new double[]{0,1,1,0,0,1,1}), doc.getSentence(4).getVector(StructureEncoder.class)); }
@Override public void encodeEach(Document d, Class<? extends Span> timeStepClass) { int i = 0; if(timeStepClass == Token.class) { List<INDArray> vecs = encodeTokens(d); for(Token t : d.getTokens()) t.putVector(StructureEncoder.class, vecs.get(i++)); } else if(timeStepClass == Sentence.class) { List<INDArray> vecs = encodeSentences(d); for(Sentence s : d.getSentences()) s.putVector(StructureEncoder.class, vecs.get(i++)); } else throw new IllegalArgumentException("Cannot encode class " + timeStepClass.toString() + " from Document"); }
StructureEncoder extends StaticEncoder { @Override public void encodeEach(Document d, Class<? extends Span> timeStepClass) { int i = 0; if(timeStepClass == Token.class) { List<INDArray> vecs = encodeTokens(d); for(Token t : d.getTokens()) t.putVector(StructureEncoder.class, vecs.get(i++)); } else if(timeStepClass == Sentence.class) { List<INDArray> vecs = encodeSentences(d); for(Sentence s : d.getSentences()) s.putVector(StructureEncoder.class, vecs.get(i++)); } else throw new IllegalArgumentException("Cannot encode class " + timeStepClass.toString() + " from Document"); } }
StructureEncoder extends StaticEncoder { @Override public void encodeEach(Document d, Class<? extends Span> timeStepClass) { int i = 0; if(timeStepClass == Token.class) { List<INDArray> vecs = encodeTokens(d); for(Token t : d.getTokens()) t.putVector(StructureEncoder.class, vecs.get(i++)); } else if(timeStepClass == Sentence.class) { List<INDArray> vecs = encodeSentences(d); for(Sentence s : d.getSentences()) s.putVector(StructureEncoder.class, vecs.get(i++)); } else throw new IllegalArgumentException("Cannot encode class " + timeStepClass.toString() + " from Document"); } StructureEncoder();  StructureEncoder(String id); }
StructureEncoder extends StaticEncoder { @Override public void encodeEach(Document d, Class<? extends Span> timeStepClass) { int i = 0; if(timeStepClass == Token.class) { List<INDArray> vecs = encodeTokens(d); for(Token t : d.getTokens()) t.putVector(StructureEncoder.class, vecs.get(i++)); } else if(timeStepClass == Sentence.class) { List<INDArray> vecs = encodeSentences(d); for(Sentence s : d.getSentences()) s.putVector(StructureEncoder.class, vecs.get(i++)); } else throw new IllegalArgumentException("Cannot encode class " + timeStepClass.toString() + " from Document"); } StructureEncoder();  StructureEncoder(String id); @Override String getName(); @Override @JsonIgnore long getEmbeddingVectorSize(); void setVectorSize(int size); @Override INDArray encodeMatrix(List<Document> input, int maxTimeSteps, Class<? extends Span> timeStepClass); @Override INDArray encode(Span span); @Override INDArray encode(String token); @Override void encodeEach(Document d, Class<? extends Span> timeStepClass); @Override void encodeEach(Sentence input, Class<? extends Span> elementClass); }
StructureEncoder extends StaticEncoder { @Override public void encodeEach(Document d, Class<? extends Span> timeStepClass) { int i = 0; if(timeStepClass == Token.class) { List<INDArray> vecs = encodeTokens(d); for(Token t : d.getTokens()) t.putVector(StructureEncoder.class, vecs.get(i++)); } else if(timeStepClass == Sentence.class) { List<INDArray> vecs = encodeSentences(d); for(Sentence s : d.getSentences()) s.putVector(StructureEncoder.class, vecs.get(i++)); } else throw new IllegalArgumentException("Cannot encode class " + timeStepClass.toString() + " from Document"); } StructureEncoder();  StructureEncoder(String id); @Override String getName(); @Override @JsonIgnore long getEmbeddingVectorSize(); void setVectorSize(int size); @Override INDArray encodeMatrix(List<Document> input, int maxTimeSteps, Class<? extends Span> timeStepClass); @Override INDArray encode(Span span); @Override INDArray encode(String token); @Override void encodeEach(Document d, Class<? extends Span> timeStepClass); @Override void encodeEach(Sentence input, Class<? extends Span> elementClass);  }