# English to Kinyarwanda Translation using RNNs
This project aims to build a model that translates text from English to Kinyarwanda using Recurrent Neural Networks (RNNs).
## Dataset
The dataset used for this project was sourced from publicly available resources:
- Dataset 1
- Dataset 2
- Dataset 3
## Preprocessing
- Lowercasing
- Removing Non-Alphanumeric Characters
- Adding Special Tokens ( , )
- Tokenization
- Padding
## Model Architecture
The model uses a Bidirectional GRU for the encoder and a GRU for the decoder, with embedding layers for converting integer sequences to dense vectors.
### Encoder
from tensorflow.keras.layers import Embedding, GRU, Bidirectional
from tensorflow.keras.models import Model
import tensorflow as tf
class Encoder(Model):
def __init__(self, vocab_size, embedding_dim, enc_units, batch_sz):
super(Encoder, self).__init__()
self.batch_sz = batch_sz
self.enc_units = enc_units
self.embedding = Embedding(vocab_size, embedding_dim)
self.gru = Bidirectional(GRU(self.enc_units, return_sequences=True, return_state=True, recurrent_initializer='glorot_uniform'))
def call(self, x, hidden):
x = self.embedding(x)
output, forward_h, backward_h = self.gru(x, initial_state=hidden)
state = tf.concat([forward_h, backward_h], axis=-1)
return output, state
def initialize_hidden_state(self):
return [tf.zeros((self.batch_sz, self.enc_units)) for _ in range(2)]
### Decoder
class Decoder(Model):
def __init__(self, vocab_size, embedding_dim, dec_units, batch_sz):
super(Decoder, self).__init__()
self.batch_sz = batch_sz
self.dec_units = dec_units
self.embedding = Embedding(vocab_size, embedding_dim)
self.gru = GRU(self.dec_units,
return_sequences=True,
return_state=True,
recurrent_initializer='glorot_uniform')
self.fc = Dense(vocab_size)
def call(self, x, hidden, enc_output):
x = self.embedding(x)
output, state = self.gru(x, initial_state=hidden)
output = self.fc(output)
return output, state
## Training Process and Hyperparameters
### Training Step …