
com.kotlinnlp.neuralparser.parsers.transitionbased.models.arcstandard.td.BiRNNTDArcStandardParserModel.kt Maven / Gradle / Ivy
/* Copyright 2017-present The KotlinNLP Authors. All Rights Reserved.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* ------------------------------------------------------------------*/
package com.kotlinnlp.neuralparser.parsers.transitionbased.models.arcstandard.td
import com.kotlinnlp.linguisticdescription.language.Language
import com.kotlinnlp.neuralparser.language.CorpusDictionary
import com.kotlinnlp.neuralparser.parsers.transitionbased.models.ScorerNetworkConfiguration
import com.kotlinnlp.neuralparser.parsers.transitionbased.templates.parsers.birnn.ActionsScorerNetworkBuilder
import com.kotlinnlp.neuralparser.parsers.transitionbased.templates.parsers.birnn.simple.BiRNNParserModel
import com.kotlinnlp.simplednn.core.functionalities.activations.ActivationFunction
import com.kotlinnlp.simplednn.core.layers.LayerType
import com.kotlinnlp.simplednn.core.neuralnetwork.NeuralNetwork
import com.kotlinnlp.syntaxdecoder.transitionsystem.state.scoreaccumulator.ScoreAccumulator
/**
* The parser model for the ArcStandard parser based on the BiRNN with Transition+Deprel actions scorer.
*
* @property language the language within the parser works (default = unknown)
* @property scoreAccumulatorFactory a factory of score accumulators
* @property corpusDictionary a corpus dictionary
* @property wordEmbeddingSize the size of each word embedding vector
* @property posEmbeddingSize the size of each pos embedding vector
* @param biRNNConnectionType the recurrent connection type of the BiRNN used to encode tokens
* @param biRNNHiddenActivation the hidden activation function of the BiRNN used to encode tokens
* @param biRNNLayers number of stacked BiRNNs
* @param scorerNetworkConfig the configuration of the scorer network
*/
class BiRNNTDArcStandardParserModel(
language: Language = Language.Unknown,
scoreAccumulatorFactory: ScoreAccumulator.Factory,
corpusDictionary: CorpusDictionary,
wordEmbeddingSize: Int,
posEmbeddingSize: Int,
biRNNConnectionType: LayerType.Connection,
biRNNHiddenActivation: ActivationFunction?,
biRNNLayers: Int,
scorerNetworkConfig: ScorerNetworkConfiguration
) : BiRNNParserModel(
language = language,
scoreAccumulatorFactory = scoreAccumulatorFactory,
corpusDictionary = corpusDictionary,
wordEmbeddingSize = wordEmbeddingSize,
posEmbeddingSize = posEmbeddingSize,
biRNNConnectionType = biRNNConnectionType,
biRNNHiddenActivation = biRNNHiddenActivation,
biRNNLayers = biRNNLayers) {
companion object {
/**
* Private val used to serialize the class (needed from Serializable)
*/
@Suppress("unused")
private const val serialVersionUID: Long = 1L
}
/**
* The neural network used by the ActionsScorer to score transitions.
*/
val transitionScorerNetwork: NeuralNetwork = ActionsScorerNetworkBuilder(
inputSize = 4 * this.deepBiRNN.outputSize, // the input is a tokens window of 4 elements
inputType = LayerType.Input.Dense,
outputSize = 4, // Shift, Root, ArcLeft, ArcRight
scorerNetworkConfig = scorerNetworkConfig
)
/**
* The neural network used by the ActionsScorer to score deprels.
*/
val deprelScorerNetwork: NeuralNetwork = ActionsScorerNetworkBuilder(
inputSize = 4 * this.deepBiRNN.outputSize, // the input is a tokens window of 4 elements
inputType = LayerType.Input.Dense,
outputSize = this.corpusDictionary.deprelTags.size + 1, // Deprels + Shift
scorerNetworkConfig = scorerNetworkConfig
)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy