generated from sensein/python-package-template
-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Word-Level Alignment #215
Open
ibevers
wants to merge
28
commits into
main
Choose a base branch
from
214-task-word-level-alignment
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
11b3ec5
Clean up tuple unpacking
ibevers f0e0f6f
Update to calculate character timestamps
ibevers bbac27f
Start implementation with ScriptLine
ibevers 4a1c447
Merge branch 'main' into 214-task-word-level-alignment
ibevers cb6d965
Update timestamping to use dicts
ibevers e8c7bb3
Update _assign_timestamps_to_characters to fully align
ibevers 525110a
Clean up vestigial code and comments
ibevers ed88772
Remove unused args
ibevers 47442df
Update ScriptLine conversion to use from_dict
ibevers f177a29
Update comments and fix mypy errors
ibevers f9c9b13
Clean up long comment
ibevers eef0734
Fix 2 broken tests
ibevers ded8325
Remove vestigial test
ibevers bbd4107
Add fixture with real alignment for comparison
ibevers fdaa824
Add had that curiosity audio fixture
ibevers 7f8ebd3
Add test with had_that_curiosity audio
ibevers 816fb76
Adjust curiosity test
ibevers 060cf4e
Replace segment level whisper timestamps with more accurate alignment…
ibevers 5934adf
Add forced alignment alignment difference check function
ibevers 94e351e
Improve evaluation function name
ibevers eda1af0
Update alignment comparison to use lower case
ibevers 88cbd7b
Add compare_alignments to curiosity test
ibevers 754b1fe
Rename assign timestamps function
ibevers 0429de0
Merge branch 'main' into 214-task-word-level-alignment
ibevers 8d04540
Change default device type to CPU
ibevers 8a7cdfa
Update test_align_transcriptions_fixture to transcribe the input audio
ibevers 64a0011
Add aligned mono audio fixture
ibevers 650e5f5
Remove redundant test
ibevers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"""Provides alignment evaluation functions.""" | ||
|
||
from senselab.utils.data_structures.script_line import ScriptLine | ||
|
||
|
||
def compare_alignments(alignment_one: ScriptLine, alignment_two: ScriptLine, difference_tolerance: float = 0.1) -> None: | ||
"""Check if two alignments are within the specified difference tolerance. | ||
|
||
Args: | ||
alignment_one (ScriptLine): The first alignment segment. | ||
alignment_two (ScriptLine): The second alignment segment. | ||
difference_tolerance (float): Allowed difference in start and end times (seconds). | ||
|
||
Raises: | ||
AssertionError: If the start or end times differ by more than the tolerance. | ||
""" | ||
print(f"Texts: {alignment_one.text} | {alignment_two.text}") | ||
if alignment_one.text and alignment_two.text: | ||
assert alignment_one.text.lower() == alignment_two.text.lower(), f"{alignment_one.text} {alignment_two.text}" | ||
if alignment_one.start is not None and alignment_two.start is not None: | ||
assert abs(alignment_one.start - alignment_two.start) < difference_tolerance | ||
if alignment_one.end is not None and alignment_two.end is not None: | ||
assert abs(alignment_one.end - alignment_two.end) < difference_tolerance | ||
if alignment_one.chunks and alignment_two.chunks and len(alignment_one.chunks) == len(alignment_two.chunks): | ||
for a1, a2 in zip(alignment_one.chunks, alignment_two.chunks): | ||
compare_alignments(a1, a2) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see some useful scenarios for using compare_alignments. Thank you for implementing it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem, glad to hear!