Skip to content

Commit

Permalink
Working test, minor updates to naming
Browse files Browse the repository at this point in the history
  • Loading branch information
Enkidu93 committed Jan 17, 2025
1 parent 672c630 commit e862df2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
2 changes: 1 addition & 1 deletion machine/jobs/build_word_alignment_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def run(args: dict):


def main() -> None:
parser = argparse.ArgumentParser(description="Trains an SMT model.")
parser = argparse.ArgumentParser(description="Trains a word alignment model.")
parser.add_argument("--model-type", required=True, type=str, help="Model type")
parser.add_argument("--build-id", required=True, type=str, help="Build id")
parser.add_argument("--clearml", default=False, action="store_true", help="Initializes a ClearML task")
Expand Down
4 changes: 2 additions & 2 deletions machine/jobs/word_alignment_file_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def __init__(
config: Any,
source_filename: str = "train.src.txt",
target_filename: str = "train.trg.txt",
word_alignment_input_filename: str = "word_alignment_inputs.json",
word_alignment_output_filename: str = "word_alignment_outputs.json",
word_alignment_input_filename: str = "word_alignments.inputs.json",
word_alignment_output_filename: str = "word_alignments.outputs.json",
) -> None:

self._source_filename = source_filename
Expand Down
30 changes: 28 additions & 2 deletions tests/jobs/test_word_alignment_build_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from machine.corpora import DictionaryTextCorpus, MemoryText, TextRow
from machine.jobs import DictToJsonWriter, WordAlignmentBuildJob, WordAlignmentModelFactory
from machine.jobs.word_alignment_file_service import WordAlignmentFileService
from machine.jobs.word_alignment_file_service import WordAlignmentFileService, WordAlignmentInput
from machine.translation import Trainer, TrainStats, WordAlignmentMatrix
from machine.translation.word_alignment_model import WordAlignmentModel
from machine.utils import CanceledError
Expand Down Expand Up @@ -90,6 +90,32 @@ def __init__(self, decoy: Decoy) -> None:
decoy.when(self.word_alignment_file_service.exists_source_corpus()).then_return(True)
decoy.when(self.word_alignment_file_service.exists_target_corpus()).then_return(True)

decoy.when(self.word_alignment_file_service.get_word_alignment_inputs()).then_return(
[
WordAlignmentInput(
corpusId="corpus1",
textId="text1",
refs=["1"],
source="¿Le importaría darnos las llaves de la habitación, por favor?",
target="Would you mind giving us the room keys, please?",
),
WordAlignmentInput(
corpusId="corpus1",
textId="text1",
refs=["2"],
source="¿Le importaría cambiarme a otra habitación más tranquila?",
target="Would you mind moving me to another quieter room?",
),
WordAlignmentInput(
corpusId="corpus1",
textId="text1",
refs=["3"],
source="Me parece que existe un problema.",
target="I think there is a problem.",
),
]
)

self.alignment_json = ""

@contextmanager
Expand All @@ -100,7 +126,7 @@ def open_target_alignment_writer(env: _TestEnvironment) -> Iterator[DictToJsonWr
file.write("\n]\n")
env.alignment_json = file.getvalue()

decoy.when(self.word_alignment_file_service.open_target_alignment_writer()).then_do(
decoy.when(self.word_alignment_file_service.open_alignment_output_writer()).then_do(
lambda: open_target_alignment_writer(self)
)

Expand Down

0 comments on commit e862df2

Please sign in to comment.