README: English to Croatian and Croatian to English Translator
Overview
This project involves building a translator capable of converting text:
- From English to Croatian
- From Croatian to English
Two models are implemented for this task:
- LSTM-Based Translator
- Seq-to-Seq Translator (without attention)
The project includes dataset preparation, model training, evaluation using BLEU and CHRF scores, and a comparison of the models' performance.
How the Translator Works
1. Translation Models
LSTM-Based Translator
- The LSTM (Long Short-Term Memory) model uses recurrent layers to process sequences of words.
- The input text is tokenized and converted into numerical representations (word embeddings).
- The LSTM processes the sequence word by word, generating an output sequence in the target language.
- The final output sequence is reconstructed into text.
Seq-to-Seq Translator
- The Seq-to-Seq (Sequence-to-Sequence) model uses two main components:
- Encoder: Encodes the input sequence into a fixed-length vector representation.
- Decoder: Decodes the vector representation into the target language sequence.
- Unlike the LSTM-based translator, the Seq-to-Seq model does not use attention mechanisms.
- This simpler structure may lead to lower accuracy on long sentences but works effectively for shorter sequences.
2. Dataset Preparation
- The dataset is sourced from the HuggingFace dataset repository.
- The data is prepared in a parallel format to align English and Croatian sentences:
<s>
<en> This is a sample sentence in English. </en>
<cr> Ovo je primjer rečenice na hrvatskom jeziku. </cr>
</s>
- Both English-to-Croatian and Croatian-to-English pairs are created for training.
3. Training Process
- Input Data: Sentences are tokenized into word or subword tokens.
- Model Training:
- For each pair of input and target sequences, the model learns to predict the target tokens from the input tokens.
- Loss is calculated based on the difference between the predicted sequence and the target sequence.
- Validation: The model's performance is evaluated on a separate validation dataset to monitor overfitting or underfitting.
Evaluation Metrics
- BLEU Scores:
- Measure n-gram overlap between the predicted and reference translations.
- Higher scores indicate better translation accuracy.
- CHRF Scores:
- Evaluate translation quality at the character level, useful for morphologically rich languages like Croatian.
- Training Curves:
- Training and validation loss are plotted to assess the model's learning progress.
File Structure
English-Croatian-Translator/
├── data/
│ ├── Cleaned_Croatian.json #Dataset in parallel format
├── notebooks/
│ ├── lstm_translator.ipynb # LSTM-based translator implementation
│ ├── seq2seq_translator.ipynb # Seq-to-Seq translator implementation
├── results/
│ ├── bleu_scores.csv # BLEU scores for both models
│ ├── chrf_scores.csv # CHRF scores for both models
│ ├── training_curves/
│ │ ├── lstm_training_curve.png # LSTM training/validation loss curve
│ │ ├── seq2seq_training_curve.png # Seq-to-Seq training/validation loss curve
│ ├── bleu_comparison_plot.png # BLEU score comparison plot
│ ├── chrf_comparison_plot.png # CHRF score comparison plot
├── README.md # Project README file
How to Run
- Dataset Preparation:
- Ensure the dataset is formatted in the parallel structure mentioned above.
- Upload the dataset files (`cleaned_croatian.json') to the project folder or Colab.
- Training:
- Open the provided Colab notebooks:
lstm_translator.ipynb
seq2seq_translator.ipynb
- Run all cells to train the models.
- Evaluation:
- Calculate BLEU and CHRF scores using the test dataset.
- Plots for training curves, BLEU, and CHRF comparisons will be automatically generated and saved.
- Results:
- Review the generated score files (
bleu_scores.csv and chrf_scores.csv) and plots in the results/ folder.
References
This project enables translation between English and Croatian using two types of models, showcasing the strengths and weaknesses of LSTM-based and Seq-to-Seq architectures.