Views
No views yet

salehalmansour/english-to-arabic-translate dataset.1graph LR
2 A[English Input Sequence] --> B[Embedding Layer]
3 B --> C[LSTM Encoder]
4 C --> D[Context Vector]
5 D --> E[Repeat Vector]
6 E --> F[LSTM Decoder]
7 F --> G[Dense Layer / Softmax]
8 G --> H[Arabic Output Sequence]| Component | Specification |
|---|---|
| Model Type | Seq2Seq LSTM |
| Hidden Units | 512 |
| Embedding Size | 512 |
| Input Depth | 20 Timesteps |
| Output Depth | 20 Timesteps |
| Optimizer | Adam |
| Loss Function | Sparse Categorical Crossentropy |
| Metric | Training | Validation |
|---|---|---|
| Accuracy | 85.99% | 85.74% |
| Loss | 0.9594 | 1.1926 |
pip install tensorflow numpy pandas scikit-learn huggingface_hub1from huggingface_hub import snapshot_download
2import tensorflow as tf
3import numpy as np
4import os
5import pickle
6from tensorflow.keras.preprocessing.sequence import pad_sequences
7
8# 1. Download model and tokenizers
9repo_id = "Ali0044/LinguaFlow"
10local_dir = snapshot_download(repo_id=repo_id)
11
12# 2. Load resources
13model = tf.keras.models.load_model(os.path.join(local_dir, "Translation_model.keras"))
14
15with open(os.path.join(local_dir, "eng_tokenizer.pkl"), "rb") as f:
16 eng_tokenizer = pickle.load(f)
17
18with open(os.path.join(local_dir, "ar_tokenizer.pkl"), "rb") as f:
19 ar_tokenizer = pickle.load(f)
20
21# 3. Translation Function
22def translate(sentences):
23 # Clean and tokenize
24 seq = eng_tokenizer.texts_to_sequences(sentences)
25 # Pad sequences
26 padded = pad_sequences(seq, maxlen=20, padding='post')
27 # Predict
28 preds = model.predict(padded)
29 preds = np.argmax(preds, axis=-1)
30
31 results = []
32 for s in preds:
33 text = [ar_tokenizer.index_word[i] for i in s if i != 0]
34 results.append(' '.join(text))
35 return results
36
37# 4. Try it out!
38print(translate(["Hello, how are you?"]))