phonsobon/khmer_images_captioning_v2
Viewer โข Updated โข 5.65k โข 261
A from-scratch image captioning model for Khmer, following the classic Show, Attend and Tell architecture:
khmer-nltk for Khmer word segmentation.Trained on phonsobon/khmer_images_captioning_v2.
This is not a standard transformers model โ it uses custom PyTorch code (modeling_khmer_captioning.py
in this repo) rather than AutoModel.
config.json โ architecture hyperparametersdecoder.pt โ trained decoder weights (state_dict)vocab.json โ word-level vocabulary (itos list)modeling_khmer_captioning.py โ model classes + load_model() / caption_image() helpersThe encoder is not included โ it's just off-the-shelf frozen ImageNet ResNet-101 weights,
downloaded automatically via torchvision when you load the model.
pip install torch torchvision pillow huggingface_hub
from huggingface_hub import snapshot_download
import sys
repo_dir = snapshot_download("phonsobon/khmer-images_captioning")
sys.path.insert(0, repo_dir)
from modeling_khmer_captioning import load_model, caption_image
encoder, decoder, itos, stoi, cfg = load_model(repo_dir)
caption = caption_image("your_image.jpg", encoder, decoder, itos, stoi, cfg, beam_size=3)
print(caption)
khmer-nltk, whose
probabilistic tokenizer won't always agree exactly with human segmentation, which affects
BLEU-style evaluation more than it affects readability.