Vishal74/Seq2SeqModel_LSTM
0
Text Summarization Model with Seq2Seq and LSTM
This model is a sequence-to-sequence (seq2seq) model for text summarization. It uses a bidirectional LSTM encoder and an LSTM decoder to generate summaries from input articles. The model was trained on a dataset with sequences of length up to 800 tokens.
Dataset
CNN-DailyMail News Text Summarization from kaggle
Model Architecture
Encoder
- Input Layer: Takes input sequences of length
max_len_article. - Embedding Layer: Converts input sequences into dense vectors of size 100.
- Bidirectional LSTM Layer: Processes the embedded input, capturing dependencies in both forward and backward directions. Outputs hidden and cell states from both directions.
- State Concatenation: Combines forward and backward hidden and cell states to form the final encoder states.
Decoder
- Input Layer: Takes target sequences of variable length.
- Embedding Layer: Converts target sequences into dense vectors of size 100.
- LSTM Layer: Processes the embedded target sequences using an LSTM with the initial states set to the encoder states.
- Dense Layer: Applies a Dense layer with softmax activation to generate the probabilities for each word in the vocabulary.
Model Summary
Total params: 94,724,060
Trainable params: 94,724,058
Non-trainable params: 0
Training
The model was trained on a dataset with sequences of length up to 800 tokens using the following configuration:
- Optimizer: Adam
- Loss Function: Categorical Crossentropy
- Metrics: Accuracy
Training Loss and Validation Loss
Test Loss
Usage -- I will update this soon
To use this model, you can load it using the Hugging Face Transformers library:
from transformers import TFAutoModel
model = TFAutoModel.from_pretrained('your-model-name')
from transformers import AutoTokenizer, TFAutoModelForSeq2SeqLM
tokenizer = AutoTokenizer.from_pretrained('your-model-name')
model = TFAutoModelForSeq2SeqLM.from_pretrained('your-model-name')
article = "Your input text here."
inputs = tokenizer.encode("summarize: " + article, return_tensors="tf", max_length=800, truncation=True)
summary_ids = model.generate(inputs, max_length=150, min_length=40, length_penalty=2.0, num_beams=4, early_stopping=True)
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
print(summary)
