File size: 1,727 Bytes
e9cbbe3
 
 
ce7b7a5
 
 
 
 
 
 
e9cbbe3
 
 
 
 
 
 
ce7b7a5
 
e9cbbe3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import datasets

logger = datasets.logging.get_logger(__name__)
_CITATION = """\
@inproceedings{Rajpurkar2016SQuAD10,
  title={SQuAD: 100, 000+ Questions for Machine Comprehension of Text},
  author={Pranav Rajpurkar and Jian Zhang and Konstantin Lopyrev and Percy Liang},
  booktitle={EMNLP},
  year={2016}
}
_DESCRIPTION = """
Georgian language handwriting dataset!
"""
_URL = 'https://huggingface.co/datasets/AnaChikashua/handwriting/resolve/main/handwriting_dataset.rar'
class HandwritingData(datasets.GeneratorBasedBuilder):
    def _info(self):
        return datasets.DatasetInfo(
            description =_DESCRIPTION,
            citation = _CITATION,
            features = datasets.Features(
            {"alphabet": datasets.Value("string"),
             "image": datasets.Image()
             }
            ),
            supervised_keys = None,
            homepage = "https://huggingface.co/datasets/AnaChikashua/handwriting",
        )
    def _split_generators(self, dl_manager):
        path = dl_manager.dowload(_URL)
        image_iters = dl_manager.iter_archive(path)
        return [
            datasets.SplitGenerator(
            name = datasets.Split.TRAIN,
            gen_kwargs = {"images": image_iters}
            ),
        ]
    def _generate_examples(self, images):
        """This function returns the examples in the raw (text) form."""
        idx = 0
        # Iterate through images
        for filepath, image in images:
            # extract the text from the filename
            text = filepath.split("/")[-1].split(".")[0]
            yield idx, {
                "alphabet": text,
                "image": {"path": filepath, "bytes": image.read()}
            }
            idx += 1