Skip to content
Back to research

MSc Computer Science thesis · Pokhara University

Image Captioning in Nepali

Generating Nepali descriptions of images with a Swin Transformer encoder and GPT-2 decoder, with experiments in language-specific tokenisation, model architecture, and dataset scale.

Research paper co-authored with Dr. Basanta Joshi.

Vision–language modelling
Transformers
Nepali NLP
Experimental evaluation
Architectures compared
2
Experiment configurations
11
Captioning datasets
2

The problem

Image captioning connects visual recognition with language generation. This research investigates generating captions in Nepali, using adapted Flickr8k and Flickr30k image–caption datasets. The challenge is to represent visual content and generate useful descriptions in a language with limited captioning resources and different tokenisation needs from English.

My contribution

  • Developed Model A using a Swin Transformer visual encoder and a GPT-2 text decoder connected through cross-attention.
  • Investigated a Nepali-trained tokenizer and compared it with the default GPT-2 tokenizer, including caption scores and validation time.
  • Compared Model A with a ConvNeXtV2–Swin–GPT-2 hybrid, varying encoder depths, attention heads, decoder layers, and dataset size across 11 configurations.
  • Evaluated generated captions using BLEU-1 through BLEU-4 and METEOR, and examined qualitative examples alongside reported literature results.

Approach

  1. Prepare image–caption pairs

    Use Nepali adaptations of Flickr8k and Flickr30k, with five reference captions per image. Clean caption text, handle beginning/end/padding tokens, and resize input images to 224 × 224 pixels. The reported training/validation/test proportions are 75% / 12.5% / 12.5%.

  2. Connect vision and language

    Model A uses Swin to encode visual features and GPT-2 to generate captions autoregressively through cross-attention. Model B adds ConvNeXtV2 feature extraction before Swin, keeping the language-generation approach comparable.

  3. Adapt tokenisation and architecture

    Train a tokenizer on Nepali caption text and compare it with the default tokenizer. Explore four-, six-, and twelve-layer decoder configurations, encoder depth, and attention heads. The selected Model A configuration uses six decoder layers.

  4. Train and evaluate

    Implement experiments with Hugging Face and TensorFlow/Keras in Kaggle. Tune learning rate and batch size, then compare configurations across 10, 20, 40, and 60 epochs using caption metrics and generated examples. GPU memory limits constrain the configurations explored.

Results & findings

On Flickr30k, Swin + GPT-2 recorded BLEU-1 of 0.69, BLEU-4 of 0.35, and METEOR of 0.22. The hybrid matched its BLEU-2, BLEU-3, BLEU-4, and METEOR scores, with a slightly lower BLEU-1 of 0.68. On Flickr8k, the two architectures showed different strengths across the BLEU metrics.

Image Captioning in Nepali: comparison results
Model / datasetBLEU-1BLEU-2BLEU-3BLEU-4METEOR
Swin + GPT-2 · Flickr8k0.590.430.320.230.19
Swin + GPT-2 · Flickr30k0.690.540.440.350.22
ConvNeXtV2 + Swin + GPT-2 · Flickr8k0.580.440.340.260.19
ConvNeXtV2 + Swin + GPT-2 · Flickr30k0.680.540.440.350.22

Best reported configurations for each architecture and dataset. These are caption-evaluation scores, rather than classification accuracy percentages.

What changed with Nepali tokenisation?

What changed with Nepali tokenisation?
TokenizerBLEU-1BLEU-4Validation / epoch
Default GPT-20.520.167m 31s
Nepali-trained0.550.203m 16s

Minimal Swin + GPT-2 configurations on Flickr8k, comparing caption scores at 60 epochs. Validation timings are reported per epoch for these experiments. They are not general inference-speed benchmarks.

Comparison with the reported CNN–Transformer reference

Comparison with the reported CNN–Transformer reference
Flickr8k modelBLEU-1BLEU-2BLEU-3BLEU-4
CNN–Transformer · Subedi et al.0.520.420.370.34
Swin + GPT-20.590.430.320.23
ConvNeXtV2 + Swin + GPT-20.580.440.340.26

Reference scores are from Subedi et al. Differences in preprocessing and evaluation may affect comparability.

Download results CSV

Experiments & analysis

Select a figure to view it at full size.

Swin–GPT-2 architecture: an image is partitioned into patches and encoded by Swin; visual features enter the GPT-2 cross-attention layers alongside tokenised Nepali captions, leading to predicted caption tokens.
Swin + GPT-2 architecture from the research paper. Cross-attention connects visual features with the language decoder.
Five original images and their generated Nepali captions from the Flickr8k-trained and Flickr30k-trained Swin–GPT-2 models. Examples include people outdoors, a dancer, a child playing, and horses.
Generated Nepali captions from the paper. These are qualitative examples of model predictions, including imperfect descriptions.

Limitations & what I learned

Where I would take this next

  • Add human evaluation by Nepali speakers and complementary metrics such as CIDEr, SPICE, ROUGE-L, and BERTScore.
  • Evaluate more diverse image domains and caption styles, and audit image-level splits and tokenizer-training boundaries when reproducing the experiments.
  • Measure inference latency, memory use, and caption quality together before considering deployment in resource-constrained settings.