Summarizer
class Summarizer
__init__
def __init__()
init_model
def init_model(preprocessor, vectorizer, embedding_weights_encoder, embedding_weights_decoder)
Initializes the model and provides necessary information for compilation.
Args
-
preprocessor: Preprocessor object that preprocesses text for training and prediction.
-
vectorizer: Vectorizer object that performs vectorization of the text.
-
embedding_weights_encoder (optional): Matrix to initialize the encoder embedding.
-
embedding_weights_decoder (optional): Matrix to initialize the decoder embedding.
predict
def predict(text)
Predicts summary of an input text.
predict_vectors
def predict_vectors(input_text, target_text)
Predicts summary of an input text and outputs information needed for evaluation: output logits, input tokens, output tokens, predicted tokens, preprocessed text, attention alignment.
Args
-
input_text: Text used as input for prediction.
-
target_text: Text used for evaluation.
Returns
new_train_step
def new_train_step(loss_function, batch_size, apply_gradients)
Initializes the train_step function to train the model on batches of data.
Args
-
loss_function: Loss function to perform backprop on.
-
batch_size: Batch size to use for training.
-
apply_gradients: Whether to apply the gradients, i.e. False if you want to validate the model on test data.
save
def save(out_path)
Saves the model to a file.
Args
- out_path: Path to directory for saving the model.
load
def load(in_path)
Loads the model from a file.
Args
- in_path: Path to the model directory.