# Copyright 2022 The HuggingFace Datasets Authors and the current dataset script contributor. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Hausa Visual Genome: A Dataset for Multi-Modal English to Hausa Machine Translation.""" import json import os from PIL import Image import datasets _CITATION = """\ @inproceedings{abdulmumin-etal-2022-hausa, title = "{H}ausa Visual Genome: A Dataset for Multi-Modal {E}nglish to {H}ausa Machine Translation", author = "Abdulmumin, Idris and Dash, Satya Ranjan and Dawud, Musa Abdullahi and Parida, Shantipriya and Muhammad, Shamsuddeen and Ahmad, Ibrahim Sa{'}id and Panda, Subhadarshi and Bojar, Ond{\v{r}}ej and Galadanci, Bashir Shehu and Bello, Bello Shehu", booktitle = "Proceedings of the Thirteenth Language Resources and Evaluation Conference", month = jun, year = "2022", address = "Marseille, France", publisher = "European Language Resources Association", url = "https://aclanthology.org/2022.lrec-1.694", pages = "6471--6479" } """ _DESCRIPTION = """\ Multi-modal Machine Translation (MMT) enables the use of visual information to enhance the quality of translations, especially where the full context is not available to enable the unambiguous translation in standard machine translation. Despite the increasing popularity of such technique, it lacks sufficient and qualitative datasets to maximize the full extent of its potential. Hausa, a Chadic language, is a member of the Afro-Asiatic language family. It is estimated that about 100 to 150 million people speak the language, with more than 80 million indigenous speakers. This is more than any of the other Chadic languages. Despite the large number of speakers, the Hausa language is considered as a low resource language in natural language processing (NLP). This is due to the absence of enough resources to implement most of the tasks in NLP. While some datasets exist, they are either scarce, machine-generated or in the religious domain. Therefore, there is the need to create training and evaluation data for implementing machine learning tasks and bridging the research gap in the language. This work presents the Hausa Visual Genome (HaVG), a dataset that contains the description of an image or a section within the image in Hausa and its equivalent in English. The dataset was prepared by automatically translating the English description of the images in the Hindi Visual Genome (HVG). The synthetic Hausa data was then carefully postedited, taking into cognizance the respective images. The data is made of 32,923 images and their descriptions that are divided into training, development, test, and challenge test set. The Hausa Visual Genome is the first dataset of its kind and can be used for Hausa-English machine translation, multi-modal research, image description, among various other natural language processing and generation tasks. """ _HOMEPAGE = "http://hdl.handle.net/11234/1-4749" _LICENSE = "https://creativecommons.org/licenses/by-nc-sa/4.0/" _URL = "https://lindat.mff.cuni.cz/repository/xmlui/bitstream/handle/11234/1-4749/hausa-visual-genome-10.zip" _BASE_DIR = 'hausa-visual-genome-10' class HausaVGClass(datasets.GeneratorBasedBuilder): """HausaVG dataset""" VERSION = datasets.Version("1.0.0") def _info(self): features = datasets.Features( { "image": datasets.Image(), "X": datasets.Value("int16"), "Y": datasets.Value("int16"), "Width": datasets.Value("int16"), "Height": datasets.Value("int16"), "en_text": datasets.Value("string"), "ha_text": datasets.Value("string") } ) return datasets.DatasetInfo( description=_DESCRIPTION, features=features, homepage=_HOMEPAGE, license=_LICENSE, citation=_CITATION, ) def _split_generators(self, dl_manager): data_dir = dl_manager.download_and_extract(_URL) return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={ "data_f": os.path.join(data_dir, _BASE_DIR, "hausa-visual-genome-train.txt"), "data_dir": os.path.join(data_dir, _BASE_DIR, "hausa-visual-genome-train.images") }, ), datasets.SplitGenerator( name=datasets.Split.VALIDATION, gen_kwargs={ "data_f": os.path.join(data_dir, _BASE_DIR, "hausa-visual-genome-dev.txt"), "data_dir": os.path.join(data_dir, _BASE_DIR, "hausa-visual-genome-dev.images") }, ), datasets.SplitGenerator( name=datasets.Split.TEST, gen_kwargs={ "data_f": os.path.join(data_dir, _BASE_DIR, "hausa-visual-genome-test.txt"), "data_dir": os.path.join(data_dir, _BASE_DIR, "hausa-visual-genome-test.images") }, ), datasets.SplitGenerator( name='challenge_test', gen_kwargs={ "data_f": os.path.join(data_dir, _BASE_DIR, "hausa-visual-genome-challenge-test-set.txt"), "data_dir": os.path.join(data_dir, _BASE_DIR, "hausa-visual-genome-challenge-test-set.images") }, ), ] def _generate_examples(self, data_f, data_dir): with open(data_f, encoding="utf-8") as f: data = f.read().splitlines() for row, item in enumerate(data): filepath, X, Y, Width, Height, en_text, ha_text = item.split("\t") yield row, {"image": os.path.join(data_dir, filepath + '.jpg'), "X": X, "Y": Y, "Width": Width, "Height": Height, "en_text": en_text, "ha_text": ha_text}