Skip to content
This repository was archived by the owner on Feb 19, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
ebb3998
Reasonable first crack at neural epic with rule features and position…
gregdurrett Dec 16, 2014
a2f65eb
Additional speed optimizations, first groundwork for the caching firs…
gregdurrett Dec 19, 2014
cb4fe4e
First stuff for caching input layer
gregdurrett Dec 19, 2014
8c96e38
Finished caching implementation of the first layer
gregdurrett Dec 19, 2014
fa38219
Changed random initialization
gregdurrett Dec 21, 2014
4f9719b
Minor tweaks
gregdurrett Dec 25, 2014
7e168d7
Revamped how NNs are instantiated, can now load multiple input vector…
gregdurrett Dec 26, 2014
a85d0d9
Changed how weights are initialized to make backprop into embeddings …
gregdurrett Dec 28, 2014
5cbeff3
First crack at corefdense, additional improvements to the neural pars…
gregdurrett Jan 5, 2015
6ee25e5
More improvements: corefdense stuff, can do fully linear network, etc.
gregdurrett Jan 11, 2015
68bdf2f
Added support for multiple parallel layers
gregdurrett Jan 12, 2015
eec6834
Added support for dependencies
gregdurrett Jan 13, 2015
4aeb231
Various changes
gregdurrett Jan 22, 2015
c3250a5
Small bug fix so it compiles
gregdurrett Jan 22, 2015
9b8aba9
Testing optimization stuff
gregdurrett Jan 25, 2015
faf9269
More optimization playing around
gregdurrett Jan 26, 2015
9523bc2
Adadelta implementation
gregdurrett Jan 27, 2015
04896ad
First crack at NER
gregdurrett Jan 28, 2015
8eeed33
Small updates to dense NER
gregdurrett Jan 28, 2015
39beb0e
Parallel training
gregdurrett Jan 29, 2015
5ed3c63
Added LowRankQuadraticTransform
gregdurrett Jan 29, 2015
6fd0bdf
Added pruning to NER, other changes
gregdurrett Feb 4, 2015
5de8091
Overhauled how nonlinear transforms are handled
gregdurrett Feb 5, 2015
9fba451
Changed how the output layer is handled to allow for LRQT and output …
gregdurrett Feb 5, 2015
9a55ee8
Minor changes
gregdurrett Feb 6, 2015
6a2291d
Separated layer extraction for train and for test to allow dropout to…
gregdurrett Feb 6, 2015
f88adc1
Changes to NER
gregdurrett Feb 6, 2015
f63db36
Changes to set up for dropout in parser
gregdurrett Feb 7, 2015
78eabe9
Embedding clipping, dropout everywhere, etc.
gregdurrett Feb 8, 2015
a79c86e
Before tetra messing
gregdurrett Feb 8, 2015
c5d7986
Random changes
gregdurrett Feb 9, 2015
a7d83c3
Fixed output embedding to be fast in parser
gregdurrett Feb 10, 2015
c23e7b8
Flexibility in input words to the network
gregdurrett Feb 10, 2015
6549e4b
Ensembling
gregdurrett Feb 11, 2015
01eaa88
Expanded set of possible surface features
gregdurrett Feb 12, 2015
933cc97
Added ability to decouple parameters for unaries, binaries, and spans
gregdurrett Feb 13, 2015
b734995
Bug fix
gregdurrett Feb 13, 2015
8bfcd2a
SGD with momentum now supported
gregdurrett Feb 14, 2015
03044e1
Made things serializable, also fixed a bug where SGD wasn't being used
gregdurrett Feb 14, 2015
ff6e16a
Fixed some vector loading stuff
gregdurrett Feb 16, 2015
434b858
Added batch normalization support
gregdurrett Feb 17, 2015
f849f33
Improved output embedding initialization
gregdurrett Feb 17, 2015
1dd7fa9
Fixed initializer for oe
gregdurrett Feb 17, 2015
93f6257
Allowed for lowercased word vectors
gregdurrett Feb 18, 2015
5759b64
Added a way to get a subset of gradient features, also improvements t…
gregdurrett Feb 18, 2015
e3d5705
Added checking coverage of vectors
gregdurrett Feb 20, 2015
756857e
Combo adagrad and skipdep converter implementation
gregdurrett Feb 20, 2015
610bf51
Fixed SpikdepConverter; THIS SHOULD'VE BEEN COMMITTED BEFORE ACL
gregdurrett Mar 7, 2015
331e343
Modernization of neural architecture for coref
gregdurrett Mar 13, 2015
30d506a
Improved coref neural model
gregdurrett Mar 18, 2015
0b23d75
Some camera-ready verification fixes and experiments
gregdurrett May 5, 2015
10605c1
Removed unused classes from the dense package
gregdurrett May 5, 2015
f63bb58
Deleted unused class
gregdurrett May 5, 2015
e124fe4
Moved Word2Vec and Word2VecUtils
gregdurrett May 5, 2015
7f75d11
Moved to dense so we can exclude corefdense
gregdurrett May 5, 2015
3ec611b
Other changes in the move
gregdurrett May 5, 2015
56e4f79
Added NeuralParserTrainer so we can remove casts from ParserTrainer
gregdurrett May 5, 2015
f741202
Camera changes
gregdurrett May 11, 2015
2cd2e23
Improvements to neural coref
gregdurrett May 20, 2015
e7565e9
First crack at sparse net features
gregdurrett May 25, 2015
1411c97
Last of the neural coref stuff, beginning of refactoring
gregdurrett Jun 14, 2015
21894ea
A few more refactoring fixes
gregdurrett Jun 15, 2015
7fc3285
Updating to latest version of epic; minor modifications to trace remo…
gregdurrett Jun 18, 2015
7db377a
Removed batch normalization stuff
gregdurrett Jun 19, 2015
516f590
Mostly reverted ParserTrainer to what it was before neural epic came …
gregdurrett Jun 19, 2015
4a3d1bb
Latest epic commits
gregdurrett Jun 23, 2015
e20db9a
Moved PNMFactory to a better-named file
gregdurrett Jun 23, 2015
3ad6453
More renaming
gregdurrett Jun 23, 2015
6e8ae37
Renaming of files and refactoring so things have better names
gregdurrett Jun 23, 2015
c5d681d
Removed spurious import
gregdurrett Jun 23, 2015
e53a9d3
Readme for the neural stuff
gregdurrett Jun 23, 2015
e264cdd
Some cleanups to the PR
gregdurrett Jun 23, 2015
e70fc0b
Applying dlwh's changes, other removals of commented-out code and one…
gregdurrett Jul 2, 2015
37d2832
Straggler changes
gregdurrett Jul 2, 2015
08a873a
Modified README to point to the downloadable model
gregdurrett Jul 10, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Finished caching implementation of the first layer
  • Loading branch information
gregdurrett committed Dec 19, 2014
commit 8c96e38d1b4e997db54e08a84807bd45be99cedb
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,30 @@ case class CachingLookupAndAffineTransformDense[FV](numOutputs: Int,
val weightst = weights.t

val cache = new HashMap[(Int,Int),DenseVector[Double]]
// val caches = Array.tabulate(6)(i => new HashMap[Int,DenseVector[Double]])

def activations(fv: Array[Int]) = {
val finalVector = DenseVector.zeros[Double](numOutputs)
for (i <- 0 until fv.size) {
val wordPosn = fv(i) -> i
if (!cache.contains(wordPosn)) {
cache.put(wordPosn, weights(i to i+numOutputs, ::) * DenseVector(word2vecFeaturizer.word2vec(wordPosn._1)))
if (fv(i) != -1) {
// caches(i).synchronized {
// if (!caches(i).contains(fv(i))) {
// val startIdx = i * word2vecFeaturizer.wordRepSize
// caches(i).put(fv(i), weights(::, startIdx until startIdx + word2vecFeaturizer.wordRepSize) * DenseVector(word2vecFeaturizer.word2vec(wordPosn._1)))
// }
// finalVector += caches(i)(fv(i))
// }
cache.synchronized {
if (!cache.contains(wordPosn)) {
val startIdx = i * word2vecFeaturizer.wordRepSize
cache.put(wordPosn, weights(::, startIdx until startIdx + word2vecFeaturizer.wordRepSize) * DenseVector(word2vecFeaturizer.word2vec(wordPosn._1)))
}
finalVector += cache(wordPosn)
}
// val startIdx = i * word2vecFeaturizer.wordRepSize
// finalVector += weights(::, startIdx until startIdx + word2vecFeaturizer.wordRepSize) * DenseVector(word2vecFeaturizer.word2vec(wordPosn._1))
}
finalVector += cache(wordPosn)
}
finalVector + bias
}
Expand Down
11 changes: 8 additions & 3 deletions src/main/scala/epic/dense/Word2VecSurfaceFeaturizer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ class Word2VecSurfaceFeaturizerIndexed[W](val wordIndex: Index[W],

def assemble(vectors: Seq[Array[Double]]) = vectors.reduce(_ ++ _)

def convertToVector(indexedWords: Array[Int]) = assemble(indexedWords.map(word2vec(_)))
def convertToVector(indexedWords: Array[Int]) = assemble(indexedWords.map(wordIdx => if (wordIdx == -1) zeroVector else word2vec(wordIdx)))

def anchor(words: IndexedSeq[W]): WordVectorAnchoringIndexed[W] = {
val convertedWords = words.map(converter(_))
val indexedWords = convertedWords.map(wordIndex(_))
new WordVectorAnchoringIndexed[W] {

def featuresForSpan(start: Int, end: Int) = {
Expand All @@ -72,11 +73,15 @@ class Word2VecSurfaceFeaturizerIndexed[W](val wordIndex: Index[W],

def featuresForSplit(start: Int, split: Int, end: Int) = {
// val vect = new DenseVector[Double](assemble(Seq(fetchVector(start - 1), fetchVector(start), fetchVector(split - 1), fetchVector(split), fetchVector(end - 1), fetchVector(end))))
Array(fetchWord(start - 1), fetchWord(start), -1, fetchWord(split - 1), fetchWord(split), fetchWord(end - 1), fetchWord(end))
Array(fetchWord(start - 1), fetchWord(start), fetchWord(split - 1), fetchWord(split), fetchWord(end - 1), fetchWord(end))
}

// private def fetchWord(idx: Int): Int = {
// if (idx < 0 || idx >= words.size || !word2vec.contains(convertedWords(idx))) -1 else wordIndex(convertedWords(idx))
// }

private def fetchWord(idx: Int): Int = {
if (idx < 0 || idx >= words.size || !word2vec.contains(convertedWords(idx))) -1 else wordIndex(convertedWords(idx))
if (idx < 0 || idx >= words.size) -1 else indexedWords(idx)
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/main/scala/epic/parser/models/PositionalNeuralModel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,17 @@ You can also epic.trees.annotations.KMAnnotator to get more or less Klein and Ma
// Convert Array[Float] values to DenseVector[Double] values
val word2vecDoubleVect = word2vec.map(keyValue => (keyValue._1 -> keyValue._2.map(_.toDouble)))
// val word2vecDoubleVect = word2vec.map(keyValue => (keyValue._1 -> new DenseVector[Double](keyValue._2.map(_.toDouble))))
val surfaceFeaturizer = new Word2VecSurfaceFeaturizer(word2vecDoubleVect, (str: String) => Word2Vec.convertWord(str))

val transform = if (useNonlinearity) {
// Affine transform of word embeddings, tanh, affine transform to output layer
new AffineTransformDense(featurizer.index.size, numHidden, new TanhTransform(new AffineTransformDense(numHidden, surfaceFeaturizer.vectorSize, new IdentityTransform[DenseVector[Double]]())))
} else {
new AffineTransformDense(featurizer.index.size, surfaceFeaturizer.vectorSize, new IdentityTransform[DenseVector[Double]]())
}
// val surfaceFeaturizer = new Word2VecSurfaceFeaturizer(word2vecDoubleVect, (str: String) => Word2Vec.convertWord(str))
// val transform = if (useNonlinearity) {
// // Affine transform of word embeddings, tanh, affine transform to output layer
// new AffineTransformDense(featurizer.index.size, numHidden, new TanhTransform(new AffineTransformDense(numHidden, surfaceFeaturizer.vectorSize, new IdentityTransform[DenseVector[Double]]())))
// } else {
// new AffineTransformDense(featurizer.index.size, surfaceFeaturizer.vectorSize, new IdentityTransform[DenseVector[Double]]())
// }

// val indexedSurfaceFeaturizer = Word2VecSurfaceFeaturizerIndexed(word2vecDoubleVect, (str: String) => Word2Vec.convertWord(str))
// val transform = new AffineTransformDense(featurizer.index.size, numHidden, new TanhTransform(new CachingLookupAndAffineTransformDense(numHidden, surfaceFeaturizer.vectorSize, indexedSurfaceFeaturizer)))
val surfaceFeaturizer = Word2VecSurfaceFeaturizerIndexed(word2vecDoubleVect, (str: String) => Word2Vec.convertWord(str))
val transform = new AffineTransformDense(featurizer.index.size, numHidden, new TanhTransform(new CachingLookupAndAffineTransformDense(numHidden, surfaceFeaturizer.vectorSize, surfaceFeaturizer)))

println(surfaceFeaturizer.vectorSize + " x " + numHidden + " x " + featurizer.index.size + " neural net")

Expand Down
12 changes: 6 additions & 6 deletions src/main/scala/epic/parser/models/PositionalTransformModel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import scala.collection.mutable.HashMap
import epic.dense.Transform
import epic.dense.AffineTransformDense
import epic.dense.Word2VecSurfaceFeaturizer
import epic.dense.Word2VecSurfaceFeaturizerIndexed

/**
* TODO
Expand All @@ -35,8 +36,8 @@ class PositionalTransformModel[L, L2, W](annotator: (BinarizedTree[L], IndexedSe
refinedTopology: RuleTopology[L2],
refinements: GrammarRefinements[L, L2],
labelFeaturizer: RefinedFeaturizer[L, W, Feature],
surfaceFeaturizer: Word2VecSurfaceFeaturizer[W],
val transform: AffineTransformDense[DenseVector[Double]]) extends ParserModel[L, W] {
surfaceFeaturizer: Word2VecSurfaceFeaturizerIndexed[W],
val transform: AffineTransformDense[Array[Int]]) extends ParserModel[L, W] {
override type Inference = PositionalTransformModel.Inference[L, L2, W]


Expand All @@ -55,7 +56,6 @@ class PositionalTransformModel[L, L2, W](annotator: (BinarizedTree[L], IndexedSe

override def inferenceFromWeights(weights: DenseVector[Double]): Inference = {
val (layer, innerLayer) = transform.extractLayerAndPenultimateLayer(weights)

val grammar = new PositionalTransformModel.PositionalTransformGrammar[L, L2, W](topology, lexicon, refinedTopology, refinements, labelFeaturizer, surfaceFeaturizer, layer, innerLayer)
new Inference(annotator, constrainer, grammar, refinements)
}
Expand Down Expand Up @@ -86,9 +86,9 @@ object PositionalTransformModel {
val refinedTopology: RuleTopology[L2],
val refinements: GrammarRefinements[L, L2],
labelFeaturizer: RefinedFeaturizer[L, W, Feature],
surfaceFeaturizer: Word2VecSurfaceFeaturizer[W],
layer: AffineTransformDense[DenseVector[Double]]#Layer,
penultimateLayer: epic.dense.Transform.Layer[DenseVector[Double],DenseVector[Double]]) extends Grammar[L, W] with Serializable {
surfaceFeaturizer: Word2VecSurfaceFeaturizerIndexed[W],
layer: AffineTransformDense[Array[Int]]#Layer,
penultimateLayer: epic.dense.Transform.Layer[Array[Int],DenseVector[Double]]) extends Grammar[L, W] with Serializable {

override def withPermissiveLexicon: Grammar[L, W] = {
new PositionalTransformGrammar(topology, lexicon.morePermissive, refinedTopology, refinements, labelFeaturizer, surfaceFeaturizer, layer, penultimateLayer)
Expand Down