Skip to content

Commit

Permalink
Make write pretranslate async
Browse files Browse the repository at this point in the history
  • Loading branch information
johnml1135 committed Nov 27, 2024
1 parent 244d66f commit 4a0e5cb
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ await _parallelCorpusPreprocessingService.Preprocess(
Translation = row.SourceSegment
}
);
return Task.CompletedTask;
},
false
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ await _parallelCorpusPreprocessingService.Preprocess(
if (row.SourceSegment.Length > 0 && row.TargetSegment.Length > 0)
trainCount++;
},
(row, corpus) =>
async (row, corpus) =>
{
if (row.SourceSegment.Length > 0 && row.TargetSegment.Length == 0)
{
Expand All @@ -135,7 +135,7 @@ await _parallelCorpusPreprocessingService.Preprocess(
pretranslateCount++;
}
if (pretranslateWriter.BytesPending > 1024 * 1024)
pretranslateWriter.FlushAsync();
await pretranslateWriter.FlushAsync();
},
(bool?)buildOptionsObject?["use_key_terms"] ?? true
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public interface IParallelCorpusPreprocessingService
Task Preprocess(
IReadOnlyList<ParallelCorpus> corpora,
Func<Row, Task> train,
Action<Row, ParallelCorpus> pretranslate,
Func<Row, ParallelCorpus, Task> pretranslate,
bool useKeyTerms = false
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal int Seed
public async Task Preprocess(
IReadOnlyList<ParallelCorpus> corpora,
Func<Row, Task> train,
Action<Row, ParallelCorpus> pretranslate,
Func<Row, ParallelCorpus, Task> pretranslate,
bool useKeyTerms = false
)
{
Expand Down Expand Up @@ -106,7 +106,7 @@ public async Task Preprocess(

foreach (Row row in CollapseRanges(pretranslateCorpus.ToArray()))
{
pretranslate(row, corpus);
await pretranslate(row, corpus);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ await processor.Preprocess(
{
if (row.SourceSegment.Length > 0 && row.TargetSegment.Length == 0)
pretranslateCount++;
return Task.CompletedTask;
},
false
);
Expand Down

0 comments on commit 4a0e5cb

Please sign in to comment.