Seq2Seq-LSTM-MultiHeadAttention
30
3
—
by
Daksh0505
Other
OTHER
New
30 downloads
Early-stage
Edge AI:
Mobile
Laptop
Server
Unknown
Mobile
Laptop
Server
Quick Summary
Seq2Seq LSTM with Multi-Head Attention for English → Hindi Translation This model performs English to Hindi translation using a Seq2Seq architecture with LSTM-...
Code Examples
Example usagepython
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)Deploy This Model
Production-ready deployment in minutes
Together.ai
Instant API access to this model
Production-ready inference API. Start free, scale to millions.
Try Free APIReplicate
One-click model deployment
Run models in the cloud with simple API. No DevOps required.
Deploy NowDisclosure: We may earn a commission from these partners. This helps keep LLMYourWay free.