Downloads · 30 days
59
11% of all-time downloads
Daksh0505/Seq2Seq-LSTM-MultiHeadAttention
Seq2Seq-LSTM-MultiHeadAttention is a machine learning model from Daksh0505. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for keras.
This model performs English to Hindi translation using a Seq2Seq architecture with LSTM-based encoder-decoder and multi-head cross-attention. The attention mechanism helps the decoder focus on relevant parts of the in…
Downloads · 30 days
59
11% of all-time downloads
All-time downloads
560
Public
Repo size
671 MB
Likes
4
Public
Click a slice to open those files.
.keras644 MB · 96%
From the Hugging Face model README
This model performs English to Hindi translation using a Seq2Seq architecture with LSTM-based encoder-decoder and multi-head cross-attention. The attention mechanism helps the decoder focus on relevant parts of the input sentence during translation.
| Model | Parameters | Vocabulary | Training Data | Repository |
|---|---|---|---|---|
| Model A | 12M | 50k | 20k English-Hindi sentence pairs | seq2seq-lstm-multiheadattention-12.3 |
| Model B | 42M | 256k | 100k English-Hindi sentence pairs | seq2seq-lstm-multiheadattention-42 |
BLEU or other quantitative metrics can be added if evaluation is performed.
<start> / <end> tokensfrom huggingface_hub import hf_hub_download
from tensorflow.keras.models import load_model
import pickle
# Load model
model_path = hf_hub_download(repo_id="Daksh0505/Seq2Seq-LSTM-MultiHeadAttention", filename="seq2seq-lstm-multiheadattention-12.3.keras")
model = load_model(model_path)
# Load tokenizers
tokenizer_path = hf_hub_download(repo_id="Daksh0505/Seq2Seq-LSTM-MultiHeadAttention", filename="seq2seq-tokenizers-12.3M.pkl")
with open(tokenizer_path, "rb") as f:
tokenizer = pickle.load(f)
tokenizer_en = tokenizer['english']
tokenizer_hi = tokenizer['hindi']
For Encoder-Decoder inference visit Daksh0505/Seq2Seq-LSTM-MultiHeadAttention-Translation
import numpy as np
from tensorflow.keras.preprocessing.sequence import pad_sequences
def preprocess_input(sentence, word2idx_en, max_seq_len, oov_token="<OOV>"):
oov_idx = word2idx_en[oov_token]
seq = [word2idx_en.get(w.lower(), oov_idx) for w in sentence.split()]
return pad_sequences([seq], maxlen=max_seq_len, padding='post')
def decode_sequence(input_seq, encoder_model, decoder_model, word2idx_hi, idx2word_hi, max_seq_len):
start_token = word2idx_hi['<start>']
end_token = word2idx_hi['<end>']
enc_outs, h, c = encoder_model.predict(input_seq, verbose=0)
target_seq = np.array([[start_token]])
decoded_sentence = []
for _ in range(max_seq_len):
output_tokens, h, c = decoder_model.predict([target_seq, h, c, enc_outs], verbose=0)
sampled_idx = np.argmax(output_tokens[0,0,:])
if sampled_idx == end_token:
break
if sampled_idx > 0:
decoded_sentence.append(idx2word_hi[sampled_idx])
target_seq[0,0] = sampled_idx
return " ".join(decoded_sentence)
# Example usage
sentence = "Hello, how are you?"
input_seq = preprocess_input(sentence, tokenizer_en.word_index, max_seq_len=40)
translation = decode_sequence(input_seq, encoder_model, decoder_model, tokenizer_hi.word_index, tokenizer_hi.index_word, max_seq_len=40)
print("Predicted Hindi Translation:", translation)
Click below to test both models live in your browser: