Search in sources :

Example 46 with SimpleMatrix

use of org.ejml.simple.SimpleMatrix in project CoreNLP by stanfordnlp.

the class NeuralUtils method concatenate.

/**
   * Concatenates several column vectors into one large column vector
   */
public static SimpleMatrix concatenate(SimpleMatrix... vectors) {
    int size = 0;
    for (SimpleMatrix vector : vectors) {
        size += vector.numRows();
    }
    SimpleMatrix result = new SimpleMatrix(size, 1);
    int index = 0;
    for (SimpleMatrix vector : vectors) {
        result.insertIntoThis(index, 0, vector);
        index += vector.numRows();
    }
    return result;
}
Also used : SimpleMatrix(org.ejml.simple.SimpleMatrix)

Example 47 with SimpleMatrix

use of org.ejml.simple.SimpleMatrix in project CoreNLP by stanfordnlp.

the class NeuralUtils method concatenateWithBias.

/**
   * Concatenates several column vectors into one large column
   * vector, adds a 1.0 at the end as a bias term
   */
public static SimpleMatrix concatenateWithBias(SimpleMatrix... vectors) {
    int size = 0;
    for (SimpleMatrix vector : vectors) {
        size += vector.numRows();
    }
    // one extra for the bias
    size++;
    SimpleMatrix result = new SimpleMatrix(size, 1);
    int index = 0;
    for (SimpleMatrix vector : vectors) {
        result.insertIntoThis(index, 0, vector);
        index += vector.numRows();
    }
    result.set(index, 0, 1.0);
    return result;
}
Also used : SimpleMatrix(org.ejml.simple.SimpleMatrix)

Example 48 with SimpleMatrix

use of org.ejml.simple.SimpleMatrix in project CoreNLP by stanfordnlp.

the class SentimentModel method initRandomWordVectors.

void initRandomWordVectors(List<Tree> trainingTrees) {
    if (op.numHid == 0) {
        throw new RuntimeException("Cannot create random word vectors for an unknown numHid");
    }
    Set<String> words = Generics.newHashSet();
    words.add(UNKNOWN_WORD);
    for (Tree tree : trainingTrees) {
        List<Tree> leaves = tree.getLeaves();
        for (Tree leaf : leaves) {
            String word = leaf.label().value();
            if (op.lowercaseWordVectors) {
                word = word.toLowerCase();
            }
            words.add(word);
        }
    }
    this.wordVectors = Generics.newTreeMap();
    for (String word : words) {
        SimpleMatrix vector = randomWordVector();
        wordVectors.put(word, vector);
    }
}
Also used : SimpleMatrix(org.ejml.simple.SimpleMatrix) Tree(edu.stanford.nlp.trees.Tree)

Example 49 with SimpleMatrix

use of org.ejml.simple.SimpleMatrix in project CoreNLP by stanfordnlp.

the class ConvertMatlabModel method copyWordVector.

/** Will not overwrite an existing word vector if it is already there */
public static void copyWordVector(Map<String, SimpleMatrix> wordVectors, String source, String target) {
    if (wordVectors.containsKey(target) || !wordVectors.containsKey(source)) {
        return;
    }
    log.info("Using wordVector " + source + " for " + target);
    wordVectors.put(target, new SimpleMatrix(wordVectors.get(source)));
}
Also used : SimpleMatrix(org.ejml.simple.SimpleMatrix)

Example 50 with SimpleMatrix

use of org.ejml.simple.SimpleMatrix in project CoreNLP by stanfordnlp.

the class SentimentCostAndGradient method getTensorGradient.

private static SimpleTensor getTensorGradient(SimpleMatrix deltaFull, SimpleMatrix leftVector, SimpleMatrix rightVector) {
    int size = deltaFull.getNumElements();
    SimpleTensor Wt_df = new SimpleTensor(size * 2, size * 2, size);
    // TODO: combine this concatenation with computeTensorDeltaDown?
    SimpleMatrix fullVector = NeuralUtils.concatenate(leftVector, rightVector);
    for (int slice = 0; slice < size; ++slice) {
        Wt_df.setSlice(slice, fullVector.scale(deltaFull.get(slice)).mult(fullVector.transpose()));
    }
    return Wt_df;
}
Also used : SimpleTensor(edu.stanford.nlp.neural.SimpleTensor) SimpleMatrix(org.ejml.simple.SimpleMatrix)

Aggregations

SimpleMatrix (org.ejml.simple.SimpleMatrix)52 Tree (edu.stanford.nlp.trees.Tree)8 Map (java.util.Map)7 DeepTree (edu.stanford.nlp.trees.DeepTree)5 TwoDimensionalMap (edu.stanford.nlp.util.TwoDimensionalMap)5 SimpleTensor (edu.stanford.nlp.neural.SimpleTensor)4 LexicalizedParser (edu.stanford.nlp.parser.lexparser.LexicalizedParser)4 Pair (edu.stanford.nlp.util.Pair)4 IdentityHashMap (java.util.IdentityHashMap)4 Mention (edu.stanford.nlp.coref.data.Mention)3 BufferedWriter (java.io.BufferedWriter)3 File (java.io.File)3 FileWriter (java.io.FileWriter)3 ArrayList (java.util.ArrayList)3 CoreLabel (edu.stanford.nlp.ling.CoreLabel)2 Embedding (edu.stanford.nlp.neural.Embedding)2 ParserQuery (edu.stanford.nlp.parser.common.ParserQuery)2 RerankingParserQuery (edu.stanford.nlp.parser.lexparser.RerankingParserQuery)2 FileFilter (java.io.FileFilter)2 Bone (com.jme3.animation.Bone)1