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;
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations