Snap
Browse files- clustering_segments.py +97 -0
clustering_segments.py
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import datasets
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
logger = datasets.logging.get_logger(__name__)
|
| 6 |
+
|
| 7 |
+
_DATA_PATH = "https://huggingface.co/datasets/conversy/clustering_segments/resolve/main/dataset.pkl"
|
| 8 |
+
|
| 9 |
+
class ClusteringSegmentsConfig(datasets.BuilderConfig):
|
| 10 |
+
"""BuilderConfig for Conversy Benchmark."""
|
| 11 |
+
|
| 12 |
+
def __init__(self, name, version, **kwargs):
|
| 13 |
+
"""BuilderConfig for Conversy Benchmark.
|
| 14 |
+
Args:
|
| 15 |
+
**kwargs: keyword arguments forwarded to super.
|
| 16 |
+
"""
|
| 17 |
+
self.name = name
|
| 18 |
+
self.version = version
|
| 19 |
+
self.features = kwargs.pop("features", None)
|
| 20 |
+
self.description = kwargs.pop("description", None)
|
| 21 |
+
self.data_url = kwargs.pop("data_url", None)
|
| 22 |
+
self.nb_data_shards = kwargs.pop("nb_data_shards", None)
|
| 23 |
+
|
| 24 |
+
super(ClusteringSegmentsConfig, self).__init__(
|
| 25 |
+
name=name,
|
| 26 |
+
version=version,
|
| 27 |
+
**kwargs
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class ClusteringSegments(datasets.GeneratorBasedBuilder):
|
| 32 |
+
"""Conversy benchmark"""
|
| 33 |
+
VERSION = datasets.Version("1.0.0")
|
| 34 |
+
BUILDER_CONFIGS = [
|
| 35 |
+
ClusteringSegmentsConfig(
|
| 36 |
+
name="VPClusteringBenchmark",
|
| 37 |
+
version=VERSION,
|
| 38 |
+
description="Conversy Benchmark for ML models evaluation",
|
| 39 |
+
features=["segment_id", "filename", "speaker", "duration", "vp",
|
| 40 |
+
"start", "end", "readable_start", "readable_end",
|
| 41 |
+
"segment_clean"],
|
| 42 |
+
data_url=_DATA_PATH,
|
| 43 |
+
nb_data_shards=1)
|
| 44 |
+
]
|
| 45 |
+
|
| 46 |
+
def _info(self):
|
| 47 |
+
description = (
|
| 48 |
+
"Voice Print Clustering Benchmark"
|
| 49 |
+
)
|
| 50 |
+
features = datasets.Features(
|
| 51 |
+
{
|
| 52 |
+
"segment_id": datasets.Value("int32"),
|
| 53 |
+
"filename": datasets.Value("string"),
|
| 54 |
+
"speaker": datasets.Value("string"),
|
| 55 |
+
"duration": datasets.Value("float32"),
|
| 56 |
+
"segment_clean": datasets.Value("bool"),
|
| 57 |
+
"start": datasets.Value("float32"),
|
| 58 |
+
"end": datasets.Value("float32"),
|
| 59 |
+
"readable_start": datasets.Value("string"),
|
| 60 |
+
"readable_end": datasets.Value("string"),
|
| 61 |
+
"vp": datasets.Sequence(datasets.Value("float32"))
|
| 62 |
+
})
|
| 63 |
+
return datasets.DatasetInfo(
|
| 64 |
+
description=description,
|
| 65 |
+
features=features,
|
| 66 |
+
supervised_keys=None,
|
| 67 |
+
version=self.config.version
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
def _split_generators(self, dl_manager):
|
| 71 |
+
"""Returns SplitGenerators."""
|
| 72 |
+
data_url = self.config.data_url
|
| 73 |
+
downloaded_file = dl_manager.download_and_extract(data_url)
|
| 74 |
+
return [
|
| 75 |
+
datasets.SplitGenerator(
|
| 76 |
+
name=datasets.Split.TRAIN,
|
| 77 |
+
gen_kwargs={"file_path": downloaded_file},
|
| 78 |
+
),
|
| 79 |
+
]
|
| 80 |
+
|
| 81 |
+
def _generate_examples(self, file_path):
|
| 82 |
+
"""Yields examples."""
|
| 83 |
+
df = pd.read_pickle(file_path)
|
| 84 |
+
|
| 85 |
+
for idx, row in df.iterrows():
|
| 86 |
+
yield idx, {
|
| 87 |
+
"segment_id": row["segment_id"],
|
| 88 |
+
"filename": row["filename"],
|
| 89 |
+
"speaker": row["speaker"],
|
| 90 |
+
"duration": row["duration"],
|
| 91 |
+
"segment_clean": row["segment_clean"],
|
| 92 |
+
"start": row['start'],
|
| 93 |
+
"end": row['end'],
|
| 94 |
+
"readable_start": row['readable_start'],
|
| 95 |
+
"readable_end": row['readable_end'],
|
| 96 |
+
"vp": np.asarray(row["vp"], dtype=np.float32)
|
| 97 |
+
}
|