Search in sources :

Example 36 with SimpleMatrix

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

the class CategoricalFeatureExtractor method encodeDistance.

private static SimpleMatrix encodeDistance(int d) {
    SimpleMatrix m = new SimpleMatrix(11, 1);
    if (d < 5) {
        m.set(d, 1);
    } else if (d < 8) {
        m.set(5, 1);
    } else if (d < 16) {
        m.set(6, 1);
    } else if (d < 32) {
        m.set(7, 1);
    } else if (d < 64) {
        m.set(8, 1);
    } else {
        m.set(9, 1);
    }
    m.set(10, Math.min(d, 64) / 64.0);
    return m;
}
Also used : SimpleMatrix(org.ejml.simple.SimpleMatrix)

Example 37 with SimpleMatrix

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

the class NeuralUtils method elementwiseApplyTanhDerivative.

/**
   * Applies the derivative of tanh to each of the elements in the vector.  Returns a new matrix.
   */
public static SimpleMatrix elementwiseApplyTanhDerivative(SimpleMatrix input) {
    SimpleMatrix output = new SimpleMatrix(input.numRows(), input.numCols());
    output.set(1.0);
    output = output.minus(input.elementMult(input));
    return output;
}
Also used : SimpleMatrix(org.ejml.simple.SimpleMatrix)

Example 38 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 39 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 40 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)

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