chunkseg 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- chunkseg-0.1.0/LICENSE +21 -0
- chunkseg-0.1.0/PKG-INFO +283 -0
- chunkseg-0.1.0/README.md +252 -0
- chunkseg-0.1.0/pyproject.toml +47 -0
- chunkseg-0.1.0/setup.cfg +4 -0
- chunkseg-0.1.0/src/chunkseg/__init__.py +8 -0
- chunkseg-0.1.0/src/chunkseg/align.py +210 -0
- chunkseg-0.1.0/src/chunkseg/cli.py +119 -0
- chunkseg-0.1.0/src/chunkseg/core.py +67 -0
- chunkseg-0.1.0/src/chunkseg/display.py +29 -0
- chunkseg-0.1.0/src/chunkseg/evaluate.py +205 -0
- chunkseg-0.1.0/src/chunkseg/metrics.py +211 -0
- chunkseg-0.1.0/src/chunkseg/parsers.py +429 -0
- chunkseg-0.1.0/src/chunkseg.egg-info/PKG-INFO +283 -0
- chunkseg-0.1.0/src/chunkseg.egg-info/SOURCES.txt +17 -0
- chunkseg-0.1.0/src/chunkseg.egg-info/dependency_links.txt +1 -0
- chunkseg-0.1.0/src/chunkseg.egg-info/entry_points.txt +2 -0
- chunkseg-0.1.0/src/chunkseg.egg-info/requires.txt +6 -0
- chunkseg-0.1.0/src/chunkseg.egg-info/top_level.txt +1 -0
chunkseg-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
chunkseg-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: chunkseg
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Evaluate segmentation quality for audio and video content in a discretized time space
|
|
5
|
+
Author-email: Fabian Retkowski <f@retkow.ski>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/retkowski/chunkseg
|
|
8
|
+
Project-URL: Repository, https://github.com/retkowski/chunkseg
|
|
9
|
+
Project-URL: Issues, https://github.com/retkowski/chunkseg/issues
|
|
10
|
+
Keywords: segmentation,evaluation,audio,video,chapter,boundary,temporal
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Multimedia :: Sound/Audio :: Analysis
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering
|
|
22
|
+
Requires-Python: >=3.9
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: numpy
|
|
26
|
+
Requires-Dist: segeval
|
|
27
|
+
Requires-Dist: nltk
|
|
28
|
+
Provides-Extra: align
|
|
29
|
+
Requires-Dist: alqalign; extra == "align"
|
|
30
|
+
Dynamic: license-file
|
|
31
|
+
|
|
32
|
+
# chunkseg
|
|
33
|
+
|
|
34
|
+
A lightweight Python package for evaluating **segmentation quality** (also called **chaptering**) in audio and video content. Chunkseg evaluates in the time space rather text space and thus is transcript-invariant, enabling comparability between a broad set of different models. The package converts segment boundaries into **fixed-size time chunks** and computes **established and comprehensive metrics** including binary classification scores (precision, recall, F1) and segmentation-specific measures (Pk, WindowDiff, Boundary Similarity, GHD).
|
|
35
|
+
|
|
36
|
+
The package supports **direct timestamp evaluation** or **automatic boundary extraction from structured transcripts via forced alignment**.
|
|
37
|
+
|
|
38
|
+
## Install
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install chunkseg
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
For transcript alignment support (requires `alqalign`):
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install chunkseg[align]
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Evaluation Modes
|
|
51
|
+
|
|
52
|
+
Chunkseg supports three evaluation modes depending on your input format:
|
|
53
|
+
|
|
54
|
+
### 1. Timestamps Mode
|
|
55
|
+
Provide boundary timestamps directly as lists of floats. Use when you already have predicted timestamps (e.g., from a timestamps-only model). **No audio or transcript needed.**
|
|
56
|
+
|
|
57
|
+
### 2. Structured Transcript (Forced Alignment)
|
|
58
|
+
Provide a structured transcript without timestamps (e.g., `[CSTART] Title [CEND] text...`). Use when your model produces chapter structure but no timestamps. **Requires audio file and `alqalign`.**
|
|
59
|
+
|
|
60
|
+
**How it works:** Parse transcript → sentence-tokenize → align to audio → derive boundary timestamps from aligned sections.
|
|
61
|
+
|
|
62
|
+
### 3. Structured Transcript with Timestamps
|
|
63
|
+
Provide a structured transcript with embedded timestamps (e.g., `[CSTART] 1:23:45 - Title [CEND] text...`). Use when your model produces both structure and timestamps.
|
|
64
|
+
|
|
65
|
+
**Two modes:**
|
|
66
|
+
- **Use provided timestamps** (default): Fast, no alignment needed, no audio required
|
|
67
|
+
- **Force alignment** (`--force-alignment`): Ignores timestamps, uses audio alignment instead (requires audio + `alqalign`)
|
|
68
|
+
|
|
69
|
+
## Quick Reference
|
|
70
|
+
|
|
71
|
+
| Mode | Format | Audio Required? | `force_alignment` | Example |
|
|
72
|
+
|------|--------|-----------------|-------------------|---------|
|
|
73
|
+
| **Timestamps** | `list[float]` | No | N/A | `hypothesis=[0.0, 125.0]` |
|
|
74
|
+
| **Transcript (FA)** | `cstart`, `markdown`, etc. | Yes | N/A (always aligns) | `format="cstart", audio="..."` |
|
|
75
|
+
| **Transcript + Timestamps (use provided)** | `cstart_ts`, `markdown_ts`, etc. | No | `False` (default) | `format="cstart_ts"` |
|
|
76
|
+
| **Transcript + Timestamps (force FA)** | `cstart_ts`, `markdown_ts`, etc. | Yes | `True` | `format="cstart_ts", force_alignment=True` |
|
|
77
|
+
|
|
78
|
+
## Usage
|
|
79
|
+
|
|
80
|
+
### Python API
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from chunkseg import evaluate, evaluate_batch, print_results
|
|
84
|
+
|
|
85
|
+
# Mode 1: Timestamps mode
|
|
86
|
+
result = evaluate(
|
|
87
|
+
hypothesis=[0.0, 120.5, 300.0],
|
|
88
|
+
reference=[0.0, 125.0, 310.0],
|
|
89
|
+
duration=600.0,
|
|
90
|
+
chunk_size=6.0,
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
# Mode 2: Structured transcript (forced alignment)
|
|
94
|
+
result = evaluate(
|
|
95
|
+
hypothesis="[CSTART] Intro [CEND] text... [CSTART] Main [CEND] more...",
|
|
96
|
+
reference=[0.0, 125.0],
|
|
97
|
+
audio="/path/to/audio.wav",
|
|
98
|
+
duration=600.0,
|
|
99
|
+
format="cstart",
|
|
100
|
+
lang="eng",
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
# Mode 3a: Transcript with timestamps (use provided)
|
|
104
|
+
result = evaluate(
|
|
105
|
+
hypothesis="[CSTART] 0:00:00 - Intro [CEND] text... [CSTART] 2:05:30 - Main [CEND]...",
|
|
106
|
+
reference=[0.0, 125.0],
|
|
107
|
+
duration=600.0,
|
|
108
|
+
format="cstart_ts", # timestamps embedded, use them
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
# Mode 3b: Transcript with timestamps (force alignment)
|
|
112
|
+
result = evaluate(
|
|
113
|
+
hypothesis="[CSTART] 0:00:00 - Intro [CEND] text... [CSTART] 2:05:30 - Main [CEND]...",
|
|
114
|
+
reference=[0.0, 125.0],
|
|
115
|
+
audio="/path/to/audio.wav",
|
|
116
|
+
duration=600.0,
|
|
117
|
+
format="cstart_ts",
|
|
118
|
+
force_alignment=True, # ignore timestamps, use alignment
|
|
119
|
+
lang="eng",
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
# Batch evaluation
|
|
123
|
+
results = evaluate_batch(
|
|
124
|
+
samples=[
|
|
125
|
+
{"hypothesis": [0.0, 120.5], "reference": [0.0, 125.0], "duration": 600.0},
|
|
126
|
+
{"hypothesis": [0.0, 300.0], "reference": [0.0, 310.0], "duration": 500.0},
|
|
127
|
+
],
|
|
128
|
+
chunk_size=6.0,
|
|
129
|
+
)
|
|
130
|
+
print_results(results)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### CLI
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
# Mode 1: Timestamps mode
|
|
137
|
+
chunkseg timestamps.jsonl --chunk-size 6.0
|
|
138
|
+
|
|
139
|
+
# Mode 2: Structured transcript (forced alignment)
|
|
140
|
+
chunkseg transcripts.jsonl --chunk-size 6.0 --format cstart --lang eng
|
|
141
|
+
|
|
142
|
+
# Mode 3a: Transcript with timestamps (use provided)
|
|
143
|
+
chunkseg transcripts_with_ts.jsonl --chunk-size 6.0 --format cstart_ts
|
|
144
|
+
|
|
145
|
+
# Mode 3b: Transcript with timestamps (force alignment, ignore timestamps)
|
|
146
|
+
chunkseg transcripts_with_ts.jsonl --chunk-size 6.0 --format cstart_ts --force-alignment --lang eng
|
|
147
|
+
|
|
148
|
+
# Output to JSON file
|
|
149
|
+
chunkseg samples.jsonl --chunk-size 6.0 --output results.json
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Input Formats
|
|
153
|
+
|
|
154
|
+
### Mode 1: Timestamps Mode
|
|
155
|
+
|
|
156
|
+
```json
|
|
157
|
+
{"hypothesis": [0.0, 120.5, 300.0], "reference": [0.0, 125.0, 310.0], "duration": 600.0}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
**Fields:**
|
|
161
|
+
- `hypothesis`: List of predicted boundary timestamps (seconds)
|
|
162
|
+
- `reference`: List of ground truth boundary timestamps (seconds)
|
|
163
|
+
- `duration`: Total audio duration (seconds)
|
|
164
|
+
|
|
165
|
+
### Mode 2: Structured Transcript (Forced Alignment)
|
|
166
|
+
|
|
167
|
+
```json
|
|
168
|
+
{"hypothesis": "[CSTART] Intro [CEND] text...", "reference": [0.0, 125.0], "audio": "/path/to/audio.wav", "duration": 600.0}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
**Fields:**
|
|
172
|
+
- `hypothesis`: Structured transcript string (no timestamps)
|
|
173
|
+
- `reference`: Ground truth boundary timestamps
|
|
174
|
+
- `audio`: Full path to audio file (required for alignment)
|
|
175
|
+
- `duration`: Total audio duration
|
|
176
|
+
|
|
177
|
+
**Note:** Requires format like `cstart`, `newline`, `markdown`, or `custom` (no `_ts` suffix).
|
|
178
|
+
|
|
179
|
+
### Mode 3: Transcript with Timestamps
|
|
180
|
+
|
|
181
|
+
```json
|
|
182
|
+
{"hypothesis": "[CSTART] 0:00:00 - Intro [CEND] text... [CSTART] 2:05:30 - Main [CEND]...", "reference": [0.0, 125.0], "duration": 600.0}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
**Fields:**
|
|
186
|
+
- `hypothesis`: Structured transcript with embedded timestamps
|
|
187
|
+
- `reference`: Ground truth boundary timestamps
|
|
188
|
+
- `duration`: Total audio duration
|
|
189
|
+
- `audio`: (optional) Full path to audio - only needed if using `--force-alignment`
|
|
190
|
+
|
|
191
|
+
**Format:** Use `cstart_ts`, `markdown_ts`, or `custom_ts` (with `_ts` suffix).
|
|
192
|
+
|
|
193
|
+
**Behavior:**
|
|
194
|
+
- Default: Uses timestamps from the text
|
|
195
|
+
- With `--force-alignment`: Ignores timestamps, requires `audio` field
|
|
196
|
+
|
|
197
|
+
## Parser Presets
|
|
198
|
+
|
|
199
|
+
| Preset | Description | Example |
|
|
200
|
+
|--------|-------------|---------|
|
|
201
|
+
| `cstart` | `[CSTART] Title [CEND]` tags | `[CSTART] Intro [CEND] text...` |
|
|
202
|
+
| `cstart_ts` | Tags with timestamps | `[CSTART] 1:23:45 - Title [CEND] text...` |
|
|
203
|
+
| `newline` | Double newline separator | `Chapter 1 text.\n\nChapter 2 text.` |
|
|
204
|
+
| `markdown` | Markdown headers | `# Title\nText\n## Subtitle\nMore text` |
|
|
205
|
+
| `markdown_ts` | Headers with timestamps | `# 0:15:30 - Introduction\nText...` |
|
|
206
|
+
| `custom` | User-provided regex | Split on any regex pattern |
|
|
207
|
+
| `custom_ts` | Regex with timestamp capture | Named groups: `(?P<timestamp>...)`, `(?P<title>...)` |
|
|
208
|
+
|
|
209
|
+
### Timestamp Formats for `markdown_ts`
|
|
210
|
+
|
|
211
|
+
The markdown timestamped parser supports multiple header formats:
|
|
212
|
+
|
|
213
|
+
- `# 00:15:30 - Title` (timestamp first with separator)
|
|
214
|
+
- `# 00:15:30 Title` (timestamp first, no separator)
|
|
215
|
+
- `# Title @ 00:15:30` (timestamp last with @)
|
|
216
|
+
- `## 1:23:45 - Chapter Title` (any header level)
|
|
217
|
+
|
|
218
|
+
### Custom Pattern with Timestamps (`custom_ts`)
|
|
219
|
+
|
|
220
|
+
For `custom_ts`, provide a regex pattern with named groups:
|
|
221
|
+
|
|
222
|
+
```python
|
|
223
|
+
from chunkseg import evaluate
|
|
224
|
+
|
|
225
|
+
result = evaluate(
|
|
226
|
+
hypothesis="[ Intro @ 1:23:45 ] text... [ Main @ 2:00:00 ] more...",
|
|
227
|
+
reference=[0.0, 125.0],
|
|
228
|
+
duration=600.0,
|
|
229
|
+
format="custom_ts",
|
|
230
|
+
custom_pattern=r"\[\s*(?P<title>[^@]+?)\s*@\s*(?P<timestamp>\d+:\d{2}:\d{2})\s*\]",
|
|
231
|
+
timestamp_format="H:MM:SS",
|
|
232
|
+
)
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Supported `timestamp_format` values:
|
|
236
|
+
- `"HH:MM:SS"` — 2-digit hours (e.g., `01:23:45`)
|
|
237
|
+
- `"H:MM:SS"` — variable hours (e.g., `1:23:45`) — **default**
|
|
238
|
+
- `"MM:SS"` — 2-digit minutes (e.g., `23:45`)
|
|
239
|
+
- `"M:SS"` — variable minutes (e.g., `3:45`)
|
|
240
|
+
- Custom regex with named groups: `(?P<h>...)`, `(?P<m>...)`, `(?P<s>...)`
|
|
241
|
+
|
|
242
|
+
## Metrics
|
|
243
|
+
|
|
244
|
+
### Binary Classification
|
|
245
|
+
|
|
246
|
+
| Metric | Description |
|
|
247
|
+
|--------|-------------|
|
|
248
|
+
| F1 | Harmonic mean of precision and recall |
|
|
249
|
+
| Precision | TP / (TP + FP) |
|
|
250
|
+
| Recall | TP / (TP + FN) |
|
|
251
|
+
| Accuracy | (TP + TN) / Total |
|
|
252
|
+
| Specificity | TN / (TN + FP) |
|
|
253
|
+
|
|
254
|
+
### Segmentation-Specific
|
|
255
|
+
|
|
256
|
+
| Metric | Description |
|
|
257
|
+
|--------|-------------|
|
|
258
|
+
| Pk | Beeferman's Pk metric (via segeval) |
|
|
259
|
+
| WindowDiff | Window difference metric (via segeval) |
|
|
260
|
+
| Boundary Similarity | Boundary similarity score (via segeval) |
|
|
261
|
+
| GHD | Generalized Hamming Distance (via nltk) |
|
|
262
|
+
|
|
263
|
+
### Statistics
|
|
264
|
+
|
|
265
|
+
- Bootstrap confidence intervals for all metrics
|
|
266
|
+
- Standard deviation
|
|
267
|
+
- Prediction and reference segment counts
|
|
268
|
+
|
|
269
|
+
## Dependencies
|
|
270
|
+
|
|
271
|
+
**Required:**
|
|
272
|
+
- `numpy`
|
|
273
|
+
- `segeval`
|
|
274
|
+
- `nltk`
|
|
275
|
+
|
|
276
|
+
**Optional:**
|
|
277
|
+
- `alqalign` — for transcript alignment (install with `pip install chunkseg[align]`)
|
|
278
|
+
|
|
279
|
+
## License
|
|
280
|
+
|
|
281
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
282
|
+
|
|
283
|
+
The MIT License is a permissive open-source license that allows you to use, modify, and distribute this software for any purpose, including commercial applications, with minimal restrictions.
|
chunkseg-0.1.0/README.md
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
# chunkseg
|
|
2
|
+
|
|
3
|
+
A lightweight Python package for evaluating **segmentation quality** (also called **chaptering**) in audio and video content. Chunkseg evaluates in the time space rather text space and thus is transcript-invariant, enabling comparability between a broad set of different models. The package converts segment boundaries into **fixed-size time chunks** and computes **established and comprehensive metrics** including binary classification scores (precision, recall, F1) and segmentation-specific measures (Pk, WindowDiff, Boundary Similarity, GHD).
|
|
4
|
+
|
|
5
|
+
The package supports **direct timestamp evaluation** or **automatic boundary extraction from structured transcripts via forced alignment**.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install chunkseg
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
For transcript alignment support (requires `alqalign`):
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install chunkseg[align]
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Evaluation Modes
|
|
20
|
+
|
|
21
|
+
Chunkseg supports three evaluation modes depending on your input format:
|
|
22
|
+
|
|
23
|
+
### 1. Timestamps Mode
|
|
24
|
+
Provide boundary timestamps directly as lists of floats. Use when you already have predicted timestamps (e.g., from a timestamps-only model). **No audio or transcript needed.**
|
|
25
|
+
|
|
26
|
+
### 2. Structured Transcript (Forced Alignment)
|
|
27
|
+
Provide a structured transcript without timestamps (e.g., `[CSTART] Title [CEND] text...`). Use when your model produces chapter structure but no timestamps. **Requires audio file and `alqalign`.**
|
|
28
|
+
|
|
29
|
+
**How it works:** Parse transcript → sentence-tokenize → align to audio → derive boundary timestamps from aligned sections.
|
|
30
|
+
|
|
31
|
+
### 3. Structured Transcript with Timestamps
|
|
32
|
+
Provide a structured transcript with embedded timestamps (e.g., `[CSTART] 1:23:45 - Title [CEND] text...`). Use when your model produces both structure and timestamps.
|
|
33
|
+
|
|
34
|
+
**Two modes:**
|
|
35
|
+
- **Use provided timestamps** (default): Fast, no alignment needed, no audio required
|
|
36
|
+
- **Force alignment** (`--force-alignment`): Ignores timestamps, uses audio alignment instead (requires audio + `alqalign`)
|
|
37
|
+
|
|
38
|
+
## Quick Reference
|
|
39
|
+
|
|
40
|
+
| Mode | Format | Audio Required? | `force_alignment` | Example |
|
|
41
|
+
|------|--------|-----------------|-------------------|---------|
|
|
42
|
+
| **Timestamps** | `list[float]` | No | N/A | `hypothesis=[0.0, 125.0]` |
|
|
43
|
+
| **Transcript (FA)** | `cstart`, `markdown`, etc. | Yes | N/A (always aligns) | `format="cstart", audio="..."` |
|
|
44
|
+
| **Transcript + Timestamps (use provided)** | `cstart_ts`, `markdown_ts`, etc. | No | `False` (default) | `format="cstart_ts"` |
|
|
45
|
+
| **Transcript + Timestamps (force FA)** | `cstart_ts`, `markdown_ts`, etc. | Yes | `True` | `format="cstart_ts", force_alignment=True` |
|
|
46
|
+
|
|
47
|
+
## Usage
|
|
48
|
+
|
|
49
|
+
### Python API
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from chunkseg import evaluate, evaluate_batch, print_results
|
|
53
|
+
|
|
54
|
+
# Mode 1: Timestamps mode
|
|
55
|
+
result = evaluate(
|
|
56
|
+
hypothesis=[0.0, 120.5, 300.0],
|
|
57
|
+
reference=[0.0, 125.0, 310.0],
|
|
58
|
+
duration=600.0,
|
|
59
|
+
chunk_size=6.0,
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
# Mode 2: Structured transcript (forced alignment)
|
|
63
|
+
result = evaluate(
|
|
64
|
+
hypothesis="[CSTART] Intro [CEND] text... [CSTART] Main [CEND] more...",
|
|
65
|
+
reference=[0.0, 125.0],
|
|
66
|
+
audio="/path/to/audio.wav",
|
|
67
|
+
duration=600.0,
|
|
68
|
+
format="cstart",
|
|
69
|
+
lang="eng",
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
# Mode 3a: Transcript with timestamps (use provided)
|
|
73
|
+
result = evaluate(
|
|
74
|
+
hypothesis="[CSTART] 0:00:00 - Intro [CEND] text... [CSTART] 2:05:30 - Main [CEND]...",
|
|
75
|
+
reference=[0.0, 125.0],
|
|
76
|
+
duration=600.0,
|
|
77
|
+
format="cstart_ts", # timestamps embedded, use them
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
# Mode 3b: Transcript with timestamps (force alignment)
|
|
81
|
+
result = evaluate(
|
|
82
|
+
hypothesis="[CSTART] 0:00:00 - Intro [CEND] text... [CSTART] 2:05:30 - Main [CEND]...",
|
|
83
|
+
reference=[0.0, 125.0],
|
|
84
|
+
audio="/path/to/audio.wav",
|
|
85
|
+
duration=600.0,
|
|
86
|
+
format="cstart_ts",
|
|
87
|
+
force_alignment=True, # ignore timestamps, use alignment
|
|
88
|
+
lang="eng",
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
# Batch evaluation
|
|
92
|
+
results = evaluate_batch(
|
|
93
|
+
samples=[
|
|
94
|
+
{"hypothesis": [0.0, 120.5], "reference": [0.0, 125.0], "duration": 600.0},
|
|
95
|
+
{"hypothesis": [0.0, 300.0], "reference": [0.0, 310.0], "duration": 500.0},
|
|
96
|
+
],
|
|
97
|
+
chunk_size=6.0,
|
|
98
|
+
)
|
|
99
|
+
print_results(results)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### CLI
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
# Mode 1: Timestamps mode
|
|
106
|
+
chunkseg timestamps.jsonl --chunk-size 6.0
|
|
107
|
+
|
|
108
|
+
# Mode 2: Structured transcript (forced alignment)
|
|
109
|
+
chunkseg transcripts.jsonl --chunk-size 6.0 --format cstart --lang eng
|
|
110
|
+
|
|
111
|
+
# Mode 3a: Transcript with timestamps (use provided)
|
|
112
|
+
chunkseg transcripts_with_ts.jsonl --chunk-size 6.0 --format cstart_ts
|
|
113
|
+
|
|
114
|
+
# Mode 3b: Transcript with timestamps (force alignment, ignore timestamps)
|
|
115
|
+
chunkseg transcripts_with_ts.jsonl --chunk-size 6.0 --format cstart_ts --force-alignment --lang eng
|
|
116
|
+
|
|
117
|
+
# Output to JSON file
|
|
118
|
+
chunkseg samples.jsonl --chunk-size 6.0 --output results.json
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Input Formats
|
|
122
|
+
|
|
123
|
+
### Mode 1: Timestamps Mode
|
|
124
|
+
|
|
125
|
+
```json
|
|
126
|
+
{"hypothesis": [0.0, 120.5, 300.0], "reference": [0.0, 125.0, 310.0], "duration": 600.0}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
**Fields:**
|
|
130
|
+
- `hypothesis`: List of predicted boundary timestamps (seconds)
|
|
131
|
+
- `reference`: List of ground truth boundary timestamps (seconds)
|
|
132
|
+
- `duration`: Total audio duration (seconds)
|
|
133
|
+
|
|
134
|
+
### Mode 2: Structured Transcript (Forced Alignment)
|
|
135
|
+
|
|
136
|
+
```json
|
|
137
|
+
{"hypothesis": "[CSTART] Intro [CEND] text...", "reference": [0.0, 125.0], "audio": "/path/to/audio.wav", "duration": 600.0}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
**Fields:**
|
|
141
|
+
- `hypothesis`: Structured transcript string (no timestamps)
|
|
142
|
+
- `reference`: Ground truth boundary timestamps
|
|
143
|
+
- `audio`: Full path to audio file (required for alignment)
|
|
144
|
+
- `duration`: Total audio duration
|
|
145
|
+
|
|
146
|
+
**Note:** Requires format like `cstart`, `newline`, `markdown`, or `custom` (no `_ts` suffix).
|
|
147
|
+
|
|
148
|
+
### Mode 3: Transcript with Timestamps
|
|
149
|
+
|
|
150
|
+
```json
|
|
151
|
+
{"hypothesis": "[CSTART] 0:00:00 - Intro [CEND] text... [CSTART] 2:05:30 - Main [CEND]...", "reference": [0.0, 125.0], "duration": 600.0}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
**Fields:**
|
|
155
|
+
- `hypothesis`: Structured transcript with embedded timestamps
|
|
156
|
+
- `reference`: Ground truth boundary timestamps
|
|
157
|
+
- `duration`: Total audio duration
|
|
158
|
+
- `audio`: (optional) Full path to audio - only needed if using `--force-alignment`
|
|
159
|
+
|
|
160
|
+
**Format:** Use `cstart_ts`, `markdown_ts`, or `custom_ts` (with `_ts` suffix).
|
|
161
|
+
|
|
162
|
+
**Behavior:**
|
|
163
|
+
- Default: Uses timestamps from the text
|
|
164
|
+
- With `--force-alignment`: Ignores timestamps, requires `audio` field
|
|
165
|
+
|
|
166
|
+
## Parser Presets
|
|
167
|
+
|
|
168
|
+
| Preset | Description | Example |
|
|
169
|
+
|--------|-------------|---------|
|
|
170
|
+
| `cstart` | `[CSTART] Title [CEND]` tags | `[CSTART] Intro [CEND] text...` |
|
|
171
|
+
| `cstart_ts` | Tags with timestamps | `[CSTART] 1:23:45 - Title [CEND] text...` |
|
|
172
|
+
| `newline` | Double newline separator | `Chapter 1 text.\n\nChapter 2 text.` |
|
|
173
|
+
| `markdown` | Markdown headers | `# Title\nText\n## Subtitle\nMore text` |
|
|
174
|
+
| `markdown_ts` | Headers with timestamps | `# 0:15:30 - Introduction\nText...` |
|
|
175
|
+
| `custom` | User-provided regex | Split on any regex pattern |
|
|
176
|
+
| `custom_ts` | Regex with timestamp capture | Named groups: `(?P<timestamp>...)`, `(?P<title>...)` |
|
|
177
|
+
|
|
178
|
+
### Timestamp Formats for `markdown_ts`
|
|
179
|
+
|
|
180
|
+
The markdown timestamped parser supports multiple header formats:
|
|
181
|
+
|
|
182
|
+
- `# 00:15:30 - Title` (timestamp first with separator)
|
|
183
|
+
- `# 00:15:30 Title` (timestamp first, no separator)
|
|
184
|
+
- `# Title @ 00:15:30` (timestamp last with @)
|
|
185
|
+
- `## 1:23:45 - Chapter Title` (any header level)
|
|
186
|
+
|
|
187
|
+
### Custom Pattern with Timestamps (`custom_ts`)
|
|
188
|
+
|
|
189
|
+
For `custom_ts`, provide a regex pattern with named groups:
|
|
190
|
+
|
|
191
|
+
```python
|
|
192
|
+
from chunkseg import evaluate
|
|
193
|
+
|
|
194
|
+
result = evaluate(
|
|
195
|
+
hypothesis="[ Intro @ 1:23:45 ] text... [ Main @ 2:00:00 ] more...",
|
|
196
|
+
reference=[0.0, 125.0],
|
|
197
|
+
duration=600.0,
|
|
198
|
+
format="custom_ts",
|
|
199
|
+
custom_pattern=r"\[\s*(?P<title>[^@]+?)\s*@\s*(?P<timestamp>\d+:\d{2}:\d{2})\s*\]",
|
|
200
|
+
timestamp_format="H:MM:SS",
|
|
201
|
+
)
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Supported `timestamp_format` values:
|
|
205
|
+
- `"HH:MM:SS"` — 2-digit hours (e.g., `01:23:45`)
|
|
206
|
+
- `"H:MM:SS"` — variable hours (e.g., `1:23:45`) — **default**
|
|
207
|
+
- `"MM:SS"` — 2-digit minutes (e.g., `23:45`)
|
|
208
|
+
- `"M:SS"` — variable minutes (e.g., `3:45`)
|
|
209
|
+
- Custom regex with named groups: `(?P<h>...)`, `(?P<m>...)`, `(?P<s>...)`
|
|
210
|
+
|
|
211
|
+
## Metrics
|
|
212
|
+
|
|
213
|
+
### Binary Classification
|
|
214
|
+
|
|
215
|
+
| Metric | Description |
|
|
216
|
+
|--------|-------------|
|
|
217
|
+
| F1 | Harmonic mean of precision and recall |
|
|
218
|
+
| Precision | TP / (TP + FP) |
|
|
219
|
+
| Recall | TP / (TP + FN) |
|
|
220
|
+
| Accuracy | (TP + TN) / Total |
|
|
221
|
+
| Specificity | TN / (TN + FP) |
|
|
222
|
+
|
|
223
|
+
### Segmentation-Specific
|
|
224
|
+
|
|
225
|
+
| Metric | Description |
|
|
226
|
+
|--------|-------------|
|
|
227
|
+
| Pk | Beeferman's Pk metric (via segeval) |
|
|
228
|
+
| WindowDiff | Window difference metric (via segeval) |
|
|
229
|
+
| Boundary Similarity | Boundary similarity score (via segeval) |
|
|
230
|
+
| GHD | Generalized Hamming Distance (via nltk) |
|
|
231
|
+
|
|
232
|
+
### Statistics
|
|
233
|
+
|
|
234
|
+
- Bootstrap confidence intervals for all metrics
|
|
235
|
+
- Standard deviation
|
|
236
|
+
- Prediction and reference segment counts
|
|
237
|
+
|
|
238
|
+
## Dependencies
|
|
239
|
+
|
|
240
|
+
**Required:**
|
|
241
|
+
- `numpy`
|
|
242
|
+
- `segeval`
|
|
243
|
+
- `nltk`
|
|
244
|
+
|
|
245
|
+
**Optional:**
|
|
246
|
+
- `alqalign` — for transcript alignment (install with `pip install chunkseg[align]`)
|
|
247
|
+
|
|
248
|
+
## License
|
|
249
|
+
|
|
250
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
251
|
+
|
|
252
|
+
The MIT License is a permissive open-source license that allows you to use, modify, and distribute this software for any purpose, including commercial applications, with minimal restrictions.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "chunkseg"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Evaluate segmentation quality for audio and video content in a discretized time space"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "Fabian Retkowski", email = "f@retkow.ski"}
|
|
14
|
+
]
|
|
15
|
+
keywords = ["segmentation", "evaluation", "audio", "video", "chapter", "boundary", "temporal"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Intended Audience :: Science/Research",
|
|
19
|
+
"Intended Audience :: Developers",
|
|
20
|
+
"License :: OSI Approved :: MIT License",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Programming Language :: Python :: 3.9",
|
|
23
|
+
"Programming Language :: Python :: 3.10",
|
|
24
|
+
"Programming Language :: Python :: 3.11",
|
|
25
|
+
"Programming Language :: Python :: 3.12",
|
|
26
|
+
"Topic :: Multimedia :: Sound/Audio :: Analysis",
|
|
27
|
+
"Topic :: Scientific/Engineering",
|
|
28
|
+
]
|
|
29
|
+
dependencies = [
|
|
30
|
+
"numpy",
|
|
31
|
+
"segeval",
|
|
32
|
+
"nltk",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[project.urls]
|
|
36
|
+
Homepage = "https://github.com/retkowski/chunkseg"
|
|
37
|
+
Repository = "https://github.com/retkowski/chunkseg"
|
|
38
|
+
Issues = "https://github.com/retkowski/chunkseg/issues"
|
|
39
|
+
|
|
40
|
+
[project.optional-dependencies]
|
|
41
|
+
align = ["alqalign"]
|
|
42
|
+
|
|
43
|
+
[project.scripts]
|
|
44
|
+
chunkseg = "chunkseg.cli:main"
|
|
45
|
+
|
|
46
|
+
[tool.setuptools.packages.find]
|
|
47
|
+
where = ["src"]
|
chunkseg-0.1.0/setup.cfg
ADDED