Skip to content

Commit

Permalink
Add check for tgt_lang s2t (facebookresearch#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mubaraq Sani authored and Mubaraq Sani committed Sep 20, 2023
1 parent dcc037d commit c5e0010
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions simuleval/data/dataloader/s2t_dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ def get_video_id(url):
sound.export(name, format="wav")
return name

def load_list_from_file(file_path: Union[Path, str]) -> List[str]:
with open(file_path) as f:
return [line.strip() for line in f]


@register_dataloader("speech-to-text")
class SpeechToTextDataloader(GenericDataloader):
Expand Down Expand Up @@ -92,12 +96,11 @@ def from_files(
target: Union[Path, str],
tgt_lang: Union[Path, str],
) -> SpeechToTextDataloader:
with open(source) as f:
source_list = [line.strip() for line in f]
with open(target) as f:
target_list = [line.strip() for line in f]
with open(tgt_lang) as f:
tgt_lang_list = [line.strip() for line in f]
source_list = load_list_from_file(source)
target_list = load_list_from_file(target)
tgt_lang_list = []
if tgt_lang is not None:
tgt_lang_list = load_list_from_file(tgt_lang)
dataloader = cls(source_list, target_list, tgt_lang_list)
return dataloader

Expand All @@ -117,14 +120,11 @@ def from_files(
target: Union[Path, str],
tgt_lang: Union[Path, str, None] = None,
) -> SpeechToSpeechDataloader:
with open(source) as f:
source_list = [line.strip() for line in f]
with open(target) as f:
target_list = [line.strip() for line in f]
source_list = load_list_from_file(source)
target_list = load_list_from_file(target)
tgt_lang_list = []
if tgt_lang is not None:
with open(tgt_lang) as f:
tgt_lang_list = [line.strip() for line in f]
tgt_lang_list = load_list_from_file(tgt_lang)
dataloader = cls(source_list, target_list, tgt_lang_list)
return dataloader

Expand Down

0 comments on commit c5e0010

Please sign in to comment.