com.kotlinnlp.neuralparser.parsers.transitionbased.models.arcdistance.ArcDistanceEmbeddingsFeaturesExtractor.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of neuralparser Show documentation
Show all versions of neuralparser Show documentation
NeuralParser is a very simple to use dependency parser, based on the SimpleDNN library and
the SyntaxDecoder transition systems framework.
/* 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.arcdistance
import com.kotlinnlp.neuralparser.parsers.transitionbased.templates.inputcontexts.TokensEmbeddingsContext
import com.kotlinnlp.neuralparser.parsers.transitionbased.templates.featuresextractor.EmbeddingsFeaturesExtractor
import com.kotlinnlp.neuralparser.parsers.transitionbased.templates.supportstructure.singleprediction.SPSupportStructure
import com.kotlinnlp.syntaxdecoder.modules.featuresextractor.FeaturesExtractor
import com.kotlinnlp.syntaxdecoder.transitionsystem.models.arcdistance.ArcDistanceTransition
import com.kotlinnlp.syntaxdecoder.transitionsystem.state.StateView
import com.kotlinnlp.syntaxdecoder.transitionsystem.state.templates.StackBufferState
import com.kotlinnlp.syntaxdecoder.utils.getItemOrNull
/**
* The [FeaturesExtractor] that extracts Embeddings as features for the ArcDistance transition system.
*/
class ArcDistanceEmbeddingsFeaturesExtractor
: EmbeddingsFeaturesExtractor<
StackBufferState,
ArcDistanceTransition,
TokensEmbeddingsContext,
SPSupportStructure>() {
/**
* Beat the occurrence of a new example.
*/
override fun newExample() = Unit
/**
* Beat the occurrence of a new batch.
*/
override fun newBatch() = Unit
/**
* Beat the occurrence of a new epoch.
*/
override fun newEpoch() = Unit
/**
* Update the trainable components of this [FeaturesExtractor].
*/
override fun update() = Unit
/**
* Get the tokens window respect to a given state
*
* @param stateView a view of the state
*
* @return the tokens window as list of Int
*/
override fun getTokensWindow(stateView: StateView) = listOf(
stateView.state.stack.getItemOrNull(-2),
stateView.state.stack.getItemOrNull(-1),
stateView.state.buffer.getItemOrNull(0),
stateView.state.buffer.getItemOrNull(1))
}