framenet_tools.frame_identification package¶
Submodules¶
framenet_tools.frame_identification.frameidentifier module¶
-
class
framenet_tools.frame_identification.frameidentifier.
FrameIdentifier
(cM: framenet_tools.config.ConfigManager)¶ Bases:
object
The FrameIdentifier
Manages the neural network and dataset creation needed for training and evaluation.
-
evaluate
(predictions: List[<MagicMock id='139663474718424'>], xs: List[str], reader: framenet_tools.data_handler.reader.DataReader)¶ Evaluates the model
NOTE: for evaluation purposes use the function evaluate_file instead
Parameters: - predictions – The predictions the model made on xs
- xs – The original fed in data
- reader – The reader from which xs was derived
Returns:
-
evaluate_file
(reader: framenet_tools.data_handler.reader.DataReader, predict_fees: bool = False)¶ Evaluates the model on a given file set
Parameters: reader – The reader to evaluate on Returns: A Triple of True Positives, False Positives and False Negatives
-
get_iter
(reader: framenet_tools.data_handler.reader.DataReader)¶ Creates an Iterator for a given DataReader object.
Parameters: reader – The DataReader object Returns: A Iterator of the dataset
-
load_model
(name: str)¶ Loads a model from a given file
NOTE: This drops the current model!
Parameters: name – The path of the model to load Returns:
-
prepare_dataset
(xs: List[str], ys: List[str], batch_size: int = None)¶ Prepares the dataset and returns a BucketIterator of the dataset
Parameters: - batch_size – The batch_size to which the dataset will be prepared
- xs – A list of sentences
- ys – A list of frames corresponding to the given sentences
Returns: A BucketIterator of the dataset
-
query
(annotation: framenet_tools.data_handler.annotation.Annotation)¶ A simple query for retrieving the most likely frame for a given annotation.
NOTE: require are loaded network and a annotation object which has a sentence and fee!
Parameters: annotation – The annotation containing the sentence and the fee. Returns:
-
query_confidence
(annotation: framenet_tools.data_handler.annotation.Annotation, n: int = 5)¶ A deeper query for retrieving a list of likely frames for a given annotation.
NOTE: require are loaded network and a annotation object which has a sentence and fee!
Parameters: - annotation – The annotation containing the sentence and the fee.
- n – The amount of best guesses retrieved.
Returns:
-
save_model
(name: str)¶ Saves a model as a file
Parameters: name – The path of the model to save to Returns:
-
train
(reader: framenet_tools.data_handler.reader.DataReader, reader_dev: framenet_tools.data_handler.reader.DataReader = None)¶ Trains the model on the given reader.
NOTE: If no development reader is given, autostopping will be disabled!
Parameters: - reader – The DataReader object which contains the training data
- reader_dev – The DataReader object for evaluation and auto stopping
Returns:
-
write_predictions
(file: str, out_file: str, fee_only: bool = False)¶ Prints the predictions of a given file
Parameters: - file – The file to predict (either a raw file or annotated file set)
- out_file – The filename for saving the predictions
- fee_only – If True, only Frame Evoking Elements are predicted, NOTE: In this case there is no need for either train or load a network
Returns:
-
-
framenet_tools.frame_identification.frameidentifier.
get_dataset
(reader: framenet_tools.data_handler.reader.DataReader)¶ Loads the dataset and combines the necessary data
Parameters: reader – The reader that contains the dataset Returns: xs: A list of sentences appended with its FEE ys: A list of frames corresponding to the given sentences
framenet_tools.frame_identification.frameidnetwork module¶
-
class
framenet_tools.frame_identification.frameidnetwork.
FrameIDNetwork
(cM: framenet_tools.config.ConfigManager, embedding_layer: <MagicMock name='mock.Embedding' id='139663474909424'>, num_classes: int)¶ Bases:
object
-
eval_model
(dev_iter: <MagicMock name='mock.Iterator' id='139663474718032'>)¶ Evaluates the model on the given dataset
UPDATE: again required and integrated for evaluating the accuracy during training. Still not recommended for final evaluation purposes.
- NOTE: only works on gold FEEs, therefore deprecated
- use f1 evaluation instead
Parameters: dev_iter – The dataset to evaluate on Returns: The accuracy reached on the given dataset
-
load_model
(path: str)¶ Loads the model from a given path
Parameters: path – The path from where to load the model Returns:
-
predict
(dataset_iter: <MagicMock name='mock.Iterator' id='139663475192216'>)¶ Uses the model to predict all given input data
Parameters: dataset_iter – The dataset to predict Returns: A list of predictions
-
query
(x: List[int])¶ Query a single sentence
Parameters: x – A list of ints representing words according to the embedding dictionary Returns: The prediction of the frame
-
save_model
(path: str)¶ Saves the current model at the given path
Parameters: path – The path to save the model at Returns:
-
train_model
(dataset_size: int, train_iter: <MagicMock name='mock.Iterator' id='139663474833504'>, dev_iter: <MagicMock name='mock.Iterator' id='139663474756912'> = None)¶ Trains the model with the given dataset Uses the model specified in net
Parameters: - dev_iter – The dev dataset for performance measuring
- train_iter – The train dataset iterator including all data for training
- dataset_size – The size of the dataset
- batch_size – The batch size to use for training
Returns:
-