File size: 4,019 Bytes
bc53380
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Copyright 2024 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.

"""ASR Dataset for various football leagues and seasons"""

import json
import os

import datasets


_CITATION = """\
@InProceedings{huggingface:dataset,
title = {ASR Dataset for Football Leagues},
author={Your Name},
year={2024}
}
"""

_DESCRIPTION = """\
This dataset contains Automatic Speech Recognition (ASR) data for various football leagues and seasons. 
The dataset includes ASR outputs from Whisper v1, v2, and v3, along with their English-translated versions.
"""

_HOMEPAGE = "https://github.com/SoccerNet/sn-echoes"

_LICENSE = "Apache License 2.0"

_URLS = {
    "whisper_v1": "whisper_v1/",
    "whisper_v1_en":  "wisper_v1_en/",
    "whisper_v2":  "wisper_v2/",
    "whisper_v2_en":  "wisper_v2_en/",
    "whisper_v3":  "wisper_v3/",
}


class FootballASRDataset(datasets.GeneratorBasedBuilder):
    """ASR Dataset for various football leagues and seasons"""

    VERSION = datasets.Version("1.0.0")

    BUILDER_CONFIGS = [
        datasets.BuilderConfig(name="whisper_v1", version=VERSION, description="Contains ASR from Whisper v1"),
        datasets.BuilderConfig(name="whisper_v1_en", version=VERSION, description="English-translated datasets from Whisper v1"),
        # datasets.BuilderConfig(name="whisper_v2", version=VERSION, description="Contains ASR from Whisper v2"),
        # datasets.BuilderConfig(name="whisper_v2_en", version=VERSION, description="English-translated datasets from Whisper v2"),
        # datasets.BuilderConfig(name="whisper_v3", version=VERSION, description="Contains ASR from Whisper v3"),
    ]

    DEFAULT_CONFIG_NAME = "whisper_v1"

    def _info(self):
        features = datasets.Features(
            {
                "segment_index": datasets.Value("int32"),
                "start_time": datasets.Value("float"),
                "end_time": datasets.Value("float"),
                "transcribed_text": datasets.Value("string"),
            }
        )
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=features,
            homepage=_HOMEPAGE,
            license=_LICENSE,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        urls = _URLS[self.config.name]
        data_dir = dl_manager.download_and_extract("https://codeload.github.com/SoccerNet/sn-echoes/zip/refs/heads/main") +"/sn-echoes-main/Dataset/"
        print("data_dir", {  "data_dir": os.path.join(data_dir+ urls),})
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={
                    "data_dir": os.path.join(data_dir+ urls),
                },)
        ]

    def _generate_examples(self, data_dir,):
        for root, _, files in os.walk(data_dir):
            for file in files:
                if file.endswith(".json"):
                    with open(os.path.join(root, file), encoding="utf-8") as f:
                        data = json.load(f)
                        for segment_index, segment_data in data["segments"].items():
                            yield f"{file}_{segment_index}", {
                                "segment_index": segment_index,
                                "start_time": segment_data[0],
                                "end_time": segment_data[1],
                                "transcribed_text": segment_data[2],
                            }