Datasets:
chuang.li commited on
Commit ·
bbe9e99
1
Parent(s): 887e6ad
Document binary tag policies and add metadata conversion script
Browse files- README.md +54 -26
- convert_tags_to_binary.py +0 -161
- tags_to_binary.py +153 -0
README.md
CHANGED
|
@@ -10,7 +10,7 @@ tags:
|
|
| 10 |
|
| 11 |
# Speech Quality Test Labels
|
| 12 |
|
| 13 |
-
It publishes
|
| 14 |
|
| 15 |
The manifest contains the 10,728-sample PICSAFEv1 subset. It is not a license to redistribute the underlying recordings.
|
| 16 |
|
|
@@ -22,31 +22,6 @@ The manifest contains the 10,728-sample PICSAFEv1 subset. It is not a license to
|
|
| 22 |
- `source_path`: path relative to the origin directory.
|
| 23 |
- `tags`: list of labels.
|
| 24 |
|
| 25 |
-
## Converting tag annotations to binary labels
|
| 26 |
-
|
| 27 |
-
The ExtraTrees threshold-search script uses `binarize_tags` to map the multi-label `Tags` column to one binary label:
|
| 28 |
-
|
| 29 |
-
- `1`: positive sample.
|
| 30 |
-
- `0`: negative sample.
|
| 31 |
-
|
| 32 |
-
The conversion is an exclusion rule: a row is `0` when it contains at least one negative tag for the selected mode; otherwise it is `1`. It does not require a particular positive tag. The modes match `filter_utils/optimal_threshold_search_desiciontree_ExtraTreesClassifier_5.py` exactly:
|
| 33 |
-
|
| 34 |
-
| `positive_mode` | Any of these tags gives `binary_label=0` | Intended strictness |
|
| 35 |
-
| --- | --- | --- |
|
| 36 |
-
| `strict` | `Nspk`, `speech_overlap`, `low_noise_level`, `mid_high_noise_level`, `reverberation`, `music_or_effect`, `microphone_popping`, `excessive_sibilance`, `distortion` | Strictest quality filter |
|
| 37 |
-
| `mid` | `speech_overlap`, `mid_high_noise_level`, `reverberation`, `music_or_effect`, `microphone_popping`, `excessive_sibilance`, `distortion` | Allows `Nspk` and low-level noise |
|
| 38 |
-
| `loose` | `speech_overlap`, `mid_high_noise_level`, `reverberation`, `music_or_effect`, `distortion` | Most permissive |
|
| 39 |
-
|
| 40 |
-
The standalone [`convert_tags_to_binary.py`](./convert_tags_to_binary.py) script accepts both `;` (used by the threshold-search script) and `|` (used by the PICSAFE TSV), preserves the input columns, and appends `binary_label`:
|
| 41 |
-
|
| 42 |
-
```bash
|
| 43 |
-
python convert_tags_to_binary.py \
|
| 44 |
-
--input datasets/test_datasets_labels.tsv \
|
| 45 |
-
--output datasets/test_datasets_labels_binary.tsv \
|
| 46 |
-
--positive-mode strict
|
| 47 |
-
```
|
| 48 |
-
|
| 49 |
-
Additional negative tags can be supplied with `--negative-tag`; any matching tag forces `binary_label=0` before the selected mode is evaluated, for example `--negative-tag wrong_transcript --negative-tag non_speech`.
|
| 50 |
|
| 51 |
## Source datasets and official download paths
|
| 52 |
|
|
@@ -73,6 +48,59 @@ In article, it is described that the 33 labels are:
|
|
| 73 |
|
| 74 |
`Nspk`, `distortion`, `emotional`, `enhanced`, `excessive_sibilance`, `fast_speed`, `female`, `high_pitch`, `imperceptible_noise_level`, `instantaneous_noise`, `low_noise_level`, `low_pitch`, `male`, `microphone_popping`, `mid_high_noise_level`, `music_or_effect`, `nb_noise`, `non_binary`, `non_speech`, `read_speech`, `real_recording`, `regular_pitch`, `regular_speed`, `reverberation`, `singing_voice`, `slow_speed`, `speech_overlap`, `spontaneous_speech`, `synthetic`, `vocal_sound`, `wb_noise`, `whispered_speech`, and `wrong_transcript`.
|
| 75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
## Licensing and limitations
|
| 77 |
|
| 78 |
This repository does not grant, aggregate, or override any source-dataset license. Obtain the audio directly from the source providers and follow their current terms, attribution requirements, access restrictions, and applicable privacy/publicity rules. Some sources require non-commercial research use, registration, a license, or direct permission from the authors.
|
|
|
|
| 10 |
|
| 11 |
# Speech Quality Test Labels
|
| 12 |
|
| 13 |
+
It publishes this README, [`metadata.jsonl`](./metadata.jsonl), and a tag-to-binary conversion script, because the 14 source datasets have different copyright and access terms.
|
| 14 |
|
| 15 |
The manifest contains the 10,728-sample PICSAFEv1 subset. It is not a license to redistribute the underlying recordings.
|
| 16 |
|
|
|
|
| 22 |
- `source_path`: path relative to the origin directory.
|
| 23 |
- `tags`: list of labels.
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
## Source datasets and official download paths
|
| 27 |
|
|
|
|
| 48 |
|
| 49 |
`Nspk`, `distortion`, `emotional`, `enhanced`, `excessive_sibilance`, `fast_speed`, `female`, `high_pitch`, `imperceptible_noise_level`, `instantaneous_noise`, `low_noise_level`, `low_pitch`, `male`, `microphone_popping`, `mid_high_noise_level`, `music_or_effect`, `nb_noise`, `non_binary`, `non_speech`, `read_speech`, `real_recording`, `regular_pitch`, `regular_speed`, `reverberation`, `singing_voice`, `slow_speed`, `speech_overlap`, `spontaneous_speech`, `synthetic`, `vocal_sound`, `wb_noise`, `whispered_speech`, and `wrong_transcript`.
|
| 50 |
|
| 51 |
+
|
| 52 |
+
## Converting tags to binary labels
|
| 53 |
+
|
| 54 |
+
Labels are derived from the human tags, not predictions
|
| 55 |
+
from a decision tree or metric thresholds.
|
| 56 |
+
|
| 57 |
+
- `1`: accepted under the selected policy (positive).
|
| 58 |
+
- `0`: rejected because at least one negative tag is present (negative).
|
| 59 |
+
|
| 60 |
+
The label is `0` if any annotation tag belongs to the mode-specific negative
|
| 61 |
+
set below or the additional `--negative_tags` set; otherwise it is `1`.
|
| 62 |
+
|
| 63 |
+
| Mode | Tags that produce label `0` (any match) |
|
| 64 |
+
| --- | --- |
|
| 65 |
+
| `strict` (default) | `Nspk`, `speech_overlap`, `low_noise_level`, `mid_high_noise_level`, `reverberation`, `music_or_effect`, `microphone_popping`, `excessive_sibilance`, `distortion` |
|
| 66 |
+
| `mid` | `speech_overlap`, `mid_high_noise_level`, `reverberation`, `music_or_effect`, `microphone_popping`, `excessive_sibilance`, `distortion` |
|
| 67 |
+
| `loose` | `speech_overlap`, `mid_high_noise_level`, `reverberation`, `music_or_effect`, `distortion` |
|
| 68 |
+
|
| 69 |
+
`mid` allows `Nspk` and `low_noise_level`; `loose` additionally allows
|
| 70 |
+
`microphone_popping` and `excessive_sibilance`. Other tags do not independently
|
| 71 |
+
cause rejection. In particular, `non_speech`, `wrong_transcript`, `singing_voice`,
|
| 72 |
+
`vocal_sound`, `nb_noise`, `wb_noise`, and `instantaneous_noise` are **not** default
|
| 73 |
+
negative tags. Label `1` means policy acceptance, not a universal claim of clean
|
| 74 |
+
speech or a correct transcript. Add rejection tags explicitly if needed.
|
| 75 |
+
Names are case-sensitive (`Nspk`). An empty tag list yields `1`, matching the
|
| 76 |
+
reference function, but does not establish annotation completeness.
|
| 77 |
+
Missing tag fields and unknown tag names are errors.
|
| 78 |
+
|
| 79 |
+
Run from the repository directory:
|
| 80 |
+
|
| 81 |
+
```bash
|
| 82 |
+
# Default policy.
|
| 83 |
+
python3 tags_to_binary.py --input metadata.jsonl --output /tmp/picsafe_strict.jsonl
|
| 84 |
+
|
| 85 |
+
# Alternative policy (also supports loose).
|
| 86 |
+
python3 tags_to_binary.py --input metadata.jsonl --output /tmp/picsafe_mid.jsonl --positive_mode mid
|
| 87 |
+
|
| 88 |
+
# Custom policy, different from the default labels.
|
| 89 |
+
python3 tags_to_binary.py --input metadata.jsonl --output /tmp/picsafe_custom.jsonl --negative_tags non_speech wrong_transcript
|
| 90 |
+
|
| 91 |
+
# Original annotations: UID and semicolon-separated Tags columns.
|
| 92 |
+
python3 tags_to_binary.py --input annotations.tsv --output /tmp/picsafe_from_tsv.jsonl
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
Output JSONL preserves all original fields and adds `binary_label` and
|
| 96 |
+
`label_policy` (the selected `positive_mode` and additional `negative_tags`).
|
| 97 |
+
TSV input also adds `id` from `UID` and `tags` from `Tags`.
|
| 98 |
+
The script prints class counts, validates unique IDs and tag names, and refuses
|
| 99 |
+
to overwrite existing output files. The source `metadata.jsonl` is unchanged.
|
| 100 |
+
Join with metric scores using globally unique `id`; basenames can collide.
|
| 101 |
+
To reproduce a threshold-search run, use the same mode, additional negative
|
| 102 |
+
tags, and sample subset.
|
| 103 |
+
|
| 104 |
## Licensing and limitations
|
| 105 |
|
| 106 |
This repository does not grant, aggregate, or override any source-dataset license. Obtain the audio directly from the source providers and follow their current terms, attribution requirements, access restrictions, and applicable privacy/publicity rules. Some sources require non-commercial research use, registration, a license, or direct permission from the authors.
|
convert_tags_to_binary.py
DELETED
|
@@ -1,161 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""Convert UID/Tags TSV annotations to binary labels."""
|
| 3 |
-
|
| 4 |
-
import argparse
|
| 5 |
-
import csv
|
| 6 |
-
import re
|
| 7 |
-
from pathlib import Path
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
VALID_TAGS = frozenset(
|
| 11 |
-
{
|
| 12 |
-
"real_recording",
|
| 13 |
-
"synthetic",
|
| 14 |
-
"enhanced",
|
| 15 |
-
"non_speech",
|
| 16 |
-
"whispered_speech",
|
| 17 |
-
"read_speech",
|
| 18 |
-
"spontaneous_speech",
|
| 19 |
-
"singing_voice",
|
| 20 |
-
"vocal_sound",
|
| 21 |
-
"emotional",
|
| 22 |
-
"regular_speed",
|
| 23 |
-
"slow_speed",
|
| 24 |
-
"fast_speed",
|
| 25 |
-
"regular_pitch",
|
| 26 |
-
"low_pitch",
|
| 27 |
-
"high_pitch",
|
| 28 |
-
"male",
|
| 29 |
-
"female",
|
| 30 |
-
"non_binary",
|
| 31 |
-
"Nspk",
|
| 32 |
-
"speech_overlap",
|
| 33 |
-
"nb_noise",
|
| 34 |
-
"wb_noise",
|
| 35 |
-
"instantaneous_noise",
|
| 36 |
-
"imperceptible_noise_level",
|
| 37 |
-
"low_noise_level",
|
| 38 |
-
"mid_high_noise_level",
|
| 39 |
-
"reverberation",
|
| 40 |
-
"music_or_effect",
|
| 41 |
-
"microphone_popping",
|
| 42 |
-
"excessive_sibilance",
|
| 43 |
-
"distortion",
|
| 44 |
-
"wrong_transcript",
|
| 45 |
-
}
|
| 46 |
-
)
|
| 47 |
-
|
| 48 |
-
NEGATIVE_TAGS = {
|
| 49 |
-
"strict": frozenset(
|
| 50 |
-
{
|
| 51 |
-
"Nspk",
|
| 52 |
-
"speech_overlap",
|
| 53 |
-
"low_noise_level",
|
| 54 |
-
"mid_high_noise_level",
|
| 55 |
-
"reverberation",
|
| 56 |
-
"music_or_effect",
|
| 57 |
-
"microphone_popping",
|
| 58 |
-
"excessive_sibilance",
|
| 59 |
-
"distortion",
|
| 60 |
-
}
|
| 61 |
-
),
|
| 62 |
-
"mid": frozenset(
|
| 63 |
-
{
|
| 64 |
-
"speech_overlap",
|
| 65 |
-
"mid_high_noise_level",
|
| 66 |
-
"reverberation",
|
| 67 |
-
"music_or_effect",
|
| 68 |
-
"microphone_popping",
|
| 69 |
-
"excessive_sibilance",
|
| 70 |
-
"distortion",
|
| 71 |
-
}
|
| 72 |
-
),
|
| 73 |
-
"loose": frozenset(
|
| 74 |
-
{
|
| 75 |
-
"speech_overlap",
|
| 76 |
-
"mid_high_noise_level",
|
| 77 |
-
"reverberation",
|
| 78 |
-
"music_or_effect",
|
| 79 |
-
"distortion",
|
| 80 |
-
}
|
| 81 |
-
),
|
| 82 |
-
}
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
def parse_tags(value):
|
| 86 |
-
"""Accept both the source script's ';' and PICSAFE's '|' separators."""
|
| 87 |
-
return [tag.strip() for tag in re.split(r"[;|]", value) if tag.strip()]
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
def binarize_tags(tags, positive_mode, custom_negative_tags):
|
| 91 |
-
tags = set(tags)
|
| 92 |
-
invalid_tags = tags - VALID_TAGS
|
| 93 |
-
if invalid_tags:
|
| 94 |
-
raise ValueError(f"Invalid tags: {sorted(invalid_tags)}")
|
| 95 |
-
if tags.intersection(custom_negative_tags):
|
| 96 |
-
return 0
|
| 97 |
-
return int(not tags.intersection(NEGATIVE_TAGS[positive_mode]))
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
def convert(input_path, output_path, positive_mode, custom_negative_tags):
|
| 101 |
-
output_path.parent.mkdir(parents=True, exist_ok=True)
|
| 102 |
-
with input_path.open("r", encoding="utf-8-sig", newline="") as source:
|
| 103 |
-
reader = csv.DictReader(source, delimiter="\t")
|
| 104 |
-
if not reader.fieldnames or {"UID", "Tags"} - set(reader.fieldnames):
|
| 105 |
-
raise ValueError("Input TSV must contain UID and Tags columns")
|
| 106 |
-
|
| 107 |
-
fieldnames = [*reader.fieldnames, "binary_label"]
|
| 108 |
-
counts = {0: 0, 1: 0}
|
| 109 |
-
seen_uids = set()
|
| 110 |
-
with output_path.open("w", encoding="utf-8", newline="") as target:
|
| 111 |
-
writer = csv.DictWriter(target, fieldnames=fieldnames, delimiter="\t")
|
| 112 |
-
writer.writeheader()
|
| 113 |
-
for row in reader:
|
| 114 |
-
uid = row["UID"]
|
| 115 |
-
if uid in seen_uids:
|
| 116 |
-
raise ValueError(f"Duplicate UID: {uid}")
|
| 117 |
-
seen_uids.add(uid)
|
| 118 |
-
label = binarize_tags(
|
| 119 |
-
parse_tags(row["Tags"]), positive_mode, custom_negative_tags
|
| 120 |
-
)
|
| 121 |
-
row["binary_label"] = label
|
| 122 |
-
writer.writerow(row)
|
| 123 |
-
counts[label] += 1
|
| 124 |
-
return len(seen_uids), counts
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
def main():
|
| 128 |
-
parser = argparse.ArgumentParser(description=__doc__)
|
| 129 |
-
parser.add_argument("--input", type=Path, required=True, help="Input TSV")
|
| 130 |
-
parser.add_argument("--output", type=Path, required=True, help="Output TSV")
|
| 131 |
-
parser.add_argument(
|
| 132 |
-
"--positive-mode",
|
| 133 |
-
choices=sorted(NEGATIVE_TAGS),
|
| 134 |
-
default="strict",
|
| 135 |
-
help="Binarization rule (default: strict)",
|
| 136 |
-
)
|
| 137 |
-
parser.add_argument(
|
| 138 |
-
"--negative-tag",
|
| 139 |
-
action="append",
|
| 140 |
-
default=[],
|
| 141 |
-
help="Additional negative tag; repeat the option or separate values with commas",
|
| 142 |
-
)
|
| 143 |
-
args = parser.parse_args()
|
| 144 |
-
|
| 145 |
-
custom_negative_tags = {
|
| 146 |
-
tag.strip()
|
| 147 |
-
for value in args.negative_tag
|
| 148 |
-
for tag in value.split(",")
|
| 149 |
-
if tag.strip()
|
| 150 |
-
}
|
| 151 |
-
rows, counts = convert(
|
| 152 |
-
args.input, args.output, args.positive_mode, custom_negative_tags
|
| 153 |
-
)
|
| 154 |
-
print(
|
| 155 |
-
f"Wrote {rows} rows to {args.output} "
|
| 156 |
-
f"(positive=1: {counts[1]}, negative=0: {counts[0]})"
|
| 157 |
-
)
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
if __name__ == "__main__":
|
| 161 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tags_to_binary.py
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Convert PICSAFEv1 tags to binary labels using only the standard library.
|
| 3 |
+
|
| 4 |
+
Policy copied from binarize_tags in optimal_threshold_search_desiciontree.py.
|
| 5 |
+
1 = accepted under the selected policy; 0 = rejected.
|
| 6 |
+
"""
|
| 7 |
+
import argparse
|
| 8 |
+
import csv
|
| 9 |
+
import json
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
from typing import List, Tuple, Union
|
| 12 |
+
|
| 13 |
+
VALID_TAGS = set(
|
| 14 |
+
[ # Data source
|
| 15 |
+
"real_recording",
|
| 16 |
+
"synthetic",
|
| 17 |
+
"enhanced",
|
| 18 |
+
# Speech styles
|
| 19 |
+
"non_speech",
|
| 20 |
+
"whispered_speech",
|
| 21 |
+
"read_speech",
|
| 22 |
+
"spontaneous_speech",
|
| 23 |
+
"singing_voice",
|
| 24 |
+
"vocal_sound",
|
| 25 |
+
"emotional",
|
| 26 |
+
# Speaking rate and pitch
|
| 27 |
+
"regular_speed",
|
| 28 |
+
"slow_speed",
|
| 29 |
+
"fast_speed",
|
| 30 |
+
"regular_pitch",
|
| 31 |
+
"low_pitch",
|
| 32 |
+
"high_pitch",
|
| 33 |
+
# Speaker attributes
|
| 34 |
+
"male",
|
| 35 |
+
"female",
|
| 36 |
+
"non_binary",
|
| 37 |
+
"Nspk",
|
| 38 |
+
"speech_overlap",
|
| 39 |
+
# Noise
|
| 40 |
+
"nb_noise",
|
| 41 |
+
"wb_noise",
|
| 42 |
+
"instantaneous_noise",
|
| 43 |
+
"imperceptible_noise_level",
|
| 44 |
+
"low_noise_level",
|
| 45 |
+
"mid_high_noise_level",
|
| 46 |
+
# Reverberation, distortion, and other interferences
|
| 47 |
+
"reverberation",
|
| 48 |
+
"music_or_effect",
|
| 49 |
+
"microphone_popping",
|
| 50 |
+
"excessive_sibilance",
|
| 51 |
+
"distortion",
|
| 52 |
+
"wrong_transcript",
|
| 53 |
+
]
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
def binarize_tags( #标签二值化函数:根据不同标签和mode将音频分为0/1两类
|
| 57 |
+
tags: Union[List[str], Tuple[str]],
|
| 58 |
+
positive_mode: str = "strict",
|
| 59 |
+
negative_tags: Union[List[str], Tuple[str], None] = (),
|
| 60 |
+
):
|
| 61 |
+
if not VALID_TAGS.issuperset(tags):
|
| 62 |
+
raise ValueError(f"Invalid tags: {tags}")
|
| 63 |
+
if negative_tags and set(tags).intersection(negative_tags):
|
| 64 |
+
# If any of the negative tags is present, consider the sample as negative
|
| 65 |
+
return 0
|
| 66 |
+
if positive_mode == "strict":
|
| 67 |
+
# Only consider tags that are strictly positive (clean speech)
|
| 68 |
+
negative_tags = set(
|
| 69 |
+
[
|
| 70 |
+
"Nspk",
|
| 71 |
+
"speech_overlap",
|
| 72 |
+
"low_noise_level",
|
| 73 |
+
"mid_high_noise_level",
|
| 74 |
+
"reverberation",
|
| 75 |
+
"music_or_effect",
|
| 76 |
+
"microphone_popping",
|
| 77 |
+
"excessive_sibilance",
|
| 78 |
+
"distortion",
|
| 79 |
+
]
|
| 80 |
+
)
|
| 81 |
+
return 0 if negative_tags.intersection(tags) else 1
|
| 82 |
+
elif positive_mode == "mid":
|
| 83 |
+
# Consider tags that are either clean speech or low-level noise
|
| 84 |
+
negative_tags = set(
|
| 85 |
+
[
|
| 86 |
+
"speech_overlap",
|
| 87 |
+
"mid_high_noise_level",
|
| 88 |
+
"reverberation",
|
| 89 |
+
"music_or_effect",
|
| 90 |
+
"microphone_popping",
|
| 91 |
+
"excessive_sibilance",
|
| 92 |
+
"distortion",
|
| 93 |
+
]
|
| 94 |
+
)
|
| 95 |
+
return 0 if negative_tags.intersection(tags) else 1
|
| 96 |
+
elif positive_mode == "loose":
|
| 97 |
+
# Consider all tags, including distortions and noise
|
| 98 |
+
negative_tags = set(
|
| 99 |
+
[
|
| 100 |
+
"speech_overlap",
|
| 101 |
+
"mid_high_noise_level",
|
| 102 |
+
"reverberation",
|
| 103 |
+
"music_or_effect",
|
| 104 |
+
"distortion",
|
| 105 |
+
]
|
| 106 |
+
)
|
| 107 |
+
return 0 if negative_tags.intersection(tags) else 1
|
| 108 |
+
else:
|
| 109 |
+
raise ValueError(f"Invalid positive mode: {positive_mode}")
|
| 110 |
+
|
| 111 |
+
def main():
|
| 112 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 113 |
+
parser.add_argument("--input", type=Path, default=Path(__file__).with_name("metadata.jsonl"))
|
| 114 |
+
parser.add_argument("--output", type=Path, required=True, help="New JSONL output path")
|
| 115 |
+
parser.add_argument("--positive_mode", choices=["strict", "mid", "loose"], default="strict")
|
| 116 |
+
parser.add_argument("--negative_tags", nargs="+", default=[], choices=sorted(VALID_TAGS))
|
| 117 |
+
args = parser.parse_args()
|
| 118 |
+
if args.input.resolve() == args.output.resolve():
|
| 119 |
+
parser.error("Input and output must be different files")
|
| 120 |
+
records, seen = [], set()
|
| 121 |
+
with args.input.open(encoding="utf-8") as stream:
|
| 122 |
+
is_tsv = args.input.suffix.lower() == ".tsv"
|
| 123 |
+
rows = csv.DictReader(stream, delimiter="\t") if is_tsv else (
|
| 124 |
+
json.loads(line) for line in stream if line.strip()
|
| 125 |
+
)
|
| 126 |
+
for row in rows:
|
| 127 |
+
if is_tsv:
|
| 128 |
+
row = dict(row, id=row["UID"], tags=row["Tags"].split(";"))
|
| 129 |
+
uid, tags = row["id"], row["tags"]
|
| 130 |
+
if not isinstance(uid, str) or not uid or uid in seen:
|
| 131 |
+
raise ValueError(f"Empty, invalid or duplicate id: {uid!r}")
|
| 132 |
+
seen.add(uid)
|
| 133 |
+
if not isinstance(tags, list) or not all(isinstance(t, str) for t in tags):
|
| 134 |
+
raise ValueError(f"{uid}: tags must be a list of strings")
|
| 135 |
+
if "binary_label" in row or "label_policy" in row:
|
| 136 |
+
raise ValueError(f"{uid}: input already has binary label fields")
|
| 137 |
+
records.append(dict(row,
|
| 138 |
+
binary_label=binarize_tags(tags, args.positive_mode, args.negative_tags),
|
| 139 |
+
label_policy={"positive_mode": args.positive_mode,
|
| 140 |
+
"negative_tags": args.negative_tags}))
|
| 141 |
+
if not records:
|
| 142 |
+
raise ValueError("Input contains no records")
|
| 143 |
+
with args.output.open("x", encoding="utf-8") as stream:
|
| 144 |
+
for row in records:
|
| 145 |
+
stream.write(json.dumps(row, ensure_ascii=False) + "\n")
|
| 146 |
+
positive = sum(row["binary_label"] for row in records)
|
| 147 |
+
print(json.dumps({"total": len(records), "positive": positive,
|
| 148 |
+
"negative": len(records) - positive,
|
| 149 |
+
"positive_mode": args.positive_mode,
|
| 150 |
+
"negative_tags": args.negative_tags}))
|
| 151 |
+
|
| 152 |
+
if __name__ == "__main__":
|
| 153 |
+
main()
|