graph_parser
allennlp_models.structured_prediction.models.graph_parser
GraphParser#
@Model.register("graph_parser")
@Model.register("sp-graph-parser")
class GraphParser(Model):
| def __init__(
| self,
| vocab: Vocabulary,
| text_field_embedder: TextFieldEmbedder,
| encoder: Seq2SeqEncoder,
| tag_representation_dim: int,
| arc_representation_dim: int,
| tag_feedforward: FeedForward = None,
| arc_feedforward: FeedForward = None,
| pos_tag_embedding: Embedding = None,
| dropout: float = 0.0,
| input_dropout: float = 0.0,
| edge_prediction_threshold: float = 0.5,
| initializer: InitializerApplicator = InitializerApplicator(),
| **kwargs
| ) -> None
A Parser for arbitrary graph structures.
Registered as a Model
with name "graph_parser".
Parameters¶
- vocab :
Vocabulary
A Vocabulary, required in order to compute sizes for input/output projections. - text_field_embedder :
TextFieldEmbedder
Used to embed thetokens
TextField
we get as input to the model. - encoder :
Seq2SeqEncoder
The encoder (with its own internal stacking) that we will use to generate representations of tokens. - tag_representation_dim :
int
The dimension of the MLPs used for arc tag prediction. - arc_representation_dim :
int
The dimension of the MLPs used for arc prediction. - tag_feedforward :
FeedForward
, optional (default =None
)
The feedforward network used to produce tag representations. By default, a 1 layer feedforward network with an elu activation is used. - arc_feedforward :
FeedForward
, optional (default =None
)
The feedforward network used to produce arc representations. By default, a 1 layer feedforward network with an elu activation is used. - pos_tag_embedding :
Embedding
, optional
Used to embed thepos_tags
SequenceLabelField
we get as input to the model. - dropout :
float
, optional (default =0.0
)
The variational dropout applied to the output of the encoder and MLP layers. - input_dropout :
float
, optional (default =0.0
)
The dropout applied to the embedded text input. - edge_prediction_threshold :
int
, optional (default =0.5
)
The probability at which to consider a scored edge to be 'present' in the decoded graph. Must be between 0 and 1. - initializer :
InitializerApplicator
, optional (default =InitializerApplicator()
)
Used to initialize the model parameters.
forward#
class GraphParser(Model):
| ...
| def forward(
| self,
| tokens: TextFieldTensors,
| pos_tags: torch.LongTensor = None,
| metadata: List[Dict[str, Any]] = None,
| arc_tags: torch.LongTensor = None
| ) -> Dict[str, torch.Tensor]
Parameters¶
- tokens :
TextFieldTensors
The output ofTextField.as_array()
. - pos_tags :
torch.LongTensor
, optional (default =None
)
The output of aSequenceLabelField
containing POS tags. - metadata :
List[Dict[str, Any]]
, optional (default =None
)
A dictionary of metadata for each batch element which has keys: tokens :List[str]
, required. The original string tokens in the sentence. - arc_tags :
torch.LongTensor
, optional (default =None
)
A torch tensor representing the sequence of integer indices denoting the parent of every word in the dependency parse. Has shape(batch_size, sequence_length, sequence_length)
.
Returns¶
- An output dictionary.
make_output_human_readable#
class GraphParser(Model):
| ...
| def make_output_human_readable(
| self,
| output_dict: Dict[str, torch.Tensor]
| ) -> Dict[str, torch.Tensor]
get_metrics#
class GraphParser(Model):
| ...
| def get_metrics(self, reset: bool = False) -> Dict[str, float]