Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Echo/src/EchoEngine/TranslationEngineService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ .. tokens.Select(

await platform.InsertPretranslationsAsync(
engineId,
buildId,
pretranslations.ToAsyncEnumerable(),
linkedCts.Token
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Task BuildCompletedAsync(

Task InsertInferenceResultsAsync(
string engineId,
string buildId,
Stream pretranslationsStream,
CancellationToken cancellationToken = default
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ public Task UpdateBuildStatusAsync(string buildId, int step, CancellationToken c

public async Task InsertInferenceResultsAsync(
string engineId,
string buildId,
Stream pretranslationsStream,
CancellationToken cancellationToken = default
)
{
await _platformService.InsertPretranslationsAsync(
engineId,
buildId,
ReadPretranslationsAsync(pretranslationsStream, cancellationToken),
cancellationToken
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public Task UpdateBuildStatusAsync(string buildId, int step, CancellationToken c

public async Task InsertInferenceResultsAsync(
string engineId,
string buildId,
Stream wordAlignmentsStream,
CancellationToken cancellationToken = default
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ CancellationToken cancellationToken
)
)
{
await PlatformService.InsertInferenceResultsAsync(engineId, wordAlignmentStream, cancellationToken);
await PlatformService.InsertInferenceResultsAsync(
engineId,
buildId,
wordAlignmentStream,
cancellationToken
);
}

int additionalCorpusSize = await SaveModelAsync(engineId, buildId, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ CancellationToken cancellationToken
)
)
{
await PlatformService.InsertInferenceResultsAsync(engineId, pretranslationsStream, cancellationToken);
await PlatformService.InsertInferenceResultsAsync(
engineId,
buildId,
pretranslationsStream,
cancellationToken
);
}

int additionalCorpusSize = await SaveModelAsync(engineId, buildId, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ await JsonSerializer.SerializeAsync(
}
);
stream.Seek(0, SeekOrigin.Begin);
await env.Service.InsertInferenceResultsAsync("engine1", stream);
await env.Service.InsertInferenceResultsAsync("engine1", "build1", stream);
}

await env
.PlatformService.Received()
.InsertPretranslationsAsync(
"engine1",
"build1",
Arg.Any<IAsyncEnumerable<PretranslationContract>>(),
Arg.Any<CancellationToken>()
);
Expand Down Expand Up @@ -79,13 +80,14 @@ await JsonSerializer.SerializeAsync(
}
);
stream.Seek(0, SeekOrigin.Begin);
await env.Service.InsertInferenceResultsAsync("engine1", stream);
await env.Service.InsertInferenceResultsAsync("engine1", "build1", stream);
}

await env
.PlatformService.Received()
.InsertPretranslationsAsync(
"engine1",
"build1",
Arg.Any<IAsyncEnumerable<PretranslationContract>>(),
Arg.Any<CancellationToken>()
);
Expand Down Expand Up @@ -125,6 +127,7 @@ public TestEnvironment()
PlatformService = Substitute.For<ITranslationPlatformService>();
PlatformService
.InsertPretranslationsAsync(
Arg.Any<string>(),
Arg.Any<string>(),
Arg.Any<IAsyncEnumerable<PretranslationContract>>(),
Arg.Any<CancellationToken>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ await JsonSerializer.SerializeAsync(
}
);
stream.Seek(0, SeekOrigin.Begin);
await env.Service.InsertInferenceResultsAsync("engine1", stream);
await env.Service.InsertInferenceResultsAsync("engine1", "build1", stream);
}

await env
Expand Down Expand Up @@ -85,7 +85,7 @@ await JsonSerializer.SerializeAsync(
}
);
stream.Seek(0, SeekOrigin.Begin);
await env.Service.InsertInferenceResultsAsync("engine1", stream);
await env.Service.InsertInferenceResultsAsync("engine1", "build1", stream);
}

await env
Expand Down
3 changes: 3 additions & 0 deletions src/Serval/src/Serval.Client/Client.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11521,6 +11521,9 @@ public partial class ExecutionData
[Newtonsoft.Json.JsonProperty("resolvedTargetLanguage", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string? ResolvedTargetLanguage { get; set; } = default!;

[Newtonsoft.Json.JsonProperty("averagePretranslationConfidence", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public double? AveragePretranslationConfidence { get; set; } = default!;

}

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Task UpdateBuildStatusAsync(
Task IncrementEngineCorpusSizeAsync(string engineId, int count = 1, CancellationToken cancellationToken = default);
Task InsertPretranslationsAsync(
string engineId,
string buildId,
IAsyncEnumerable<PretranslationContract> pretranslations,
CancellationToken cancellationToken = default
);
Expand Down
1 change: 1 addition & 0 deletions src/Serval/src/Serval.Translation/Dtos/ExecutionDataDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ public record ExecutionDataDto
public string? EngineTargetLanguageTag { get; init; }
public string? ResolvedSourceLanguage { get; init; }
public string? ResolvedTargetLanguage { get; init; }
public double? AveragePretranslationConfidence { get; init; }
}
1 change: 1 addition & 0 deletions src/Serval/src/Serval.Translation/Models/ExecutionData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ public record ExecutionData
public string? EngineTargetLanguageTag { get; init; }
public string? ResolvedSourceLanguage { get; init; }
public string? ResolvedTargetLanguage { get; init; }
public double? AveragePretranslationConfidence { get; init; }
}
1 change: 1 addition & 0 deletions src/Serval/src/Serval.Translation/Services/DtoMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ private static ExecutionDataDto Map(ExecutionData source) =>
EngineTargetLanguageTag = source.EngineTargetLanguageTag,
ResolvedSourceLanguage = source.ResolvedSourceLanguage,
ResolvedTargetLanguage = source.ResolvedTargetLanguage,
AveragePretranslationConfidence = source.AveragePretranslationConfidence,
};
}

Expand Down
11 changes: 11 additions & 0 deletions src/Serval/src/Serval.Translation/Services/PlatformService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ await _engines.UpdateAsync(

public async Task InsertPretranslationsAsync(
string engineId,
string buildId,
IAsyncEnumerable<PretranslationContract> pretranslations,
CancellationToken cancellationToken = default
)
Expand All @@ -375,6 +376,8 @@ public async Task InsertPretranslationsAsync(
int nextModelRevision = engine.ModelRevision + 1;

var batch = new List<Pretranslation>();
double confidenceTotal = 0.0;
int numPretranslations = 0;
await foreach (PretranslationContract item in pretranslations.WithCancellation(cancellationToken))
{
batch.Add(
Expand All @@ -401,6 +404,8 @@ public async Task InsertPretranslationsAsync(
Confidence = item.Confidence,
}
);
confidenceTotal += item.Confidence ?? 0.0;
numPretranslations += 1;
if (batch.Count == PretranslationInsertBatchSize)
{
await _pretranslations.InsertAllAsync(batch, cancellationToken);
Expand All @@ -409,5 +414,11 @@ public async Task InsertPretranslationsAsync(
}
if (batch.Count > 0)
await _pretranslations.InsertAllAsync(batch, CancellationToken.None);

await _builds.UpdateAsync(
b => b.Id == buildId,
u => u.Set(b => b.ExecutionData.AveragePretranslationConfidence, confidenceTotal / numPretranslations),
cancellationToken: cancellationToken
);
}
}
1 change: 1 addition & 0 deletions src/Serval/test/Serval.E2ETests/ServalApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ public async Task Nmt_Paratext(bool withAdditionalFiles)
string buildId = await _helperClient.BuildEngineAsync(engineId);
TranslationBuild build = await _helperClient.TranslationEnginesClient.GetBuildAsync(engineId, buildId);
Assert.That(build.State, Is.EqualTo(JobState.Completed), JsonSerializer.Serialize(build));
Assert.That(build.ExecutionData.AveragePretranslationConfidence, Is.GreaterThan(0.3));

IList<Pretranslation> translations = await _helperClient.TranslationEnginesClient.GetAllPretranslationsAsync(
engineId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ await env.Builds.InsertAsync(
Assert.That(env.Engines.Get("e0").IsBuilding, Is.False);

Assert.That(env.Pretranslations.Count, Is.EqualTo(0));
await env.PlatformService.InsertPretranslationsAsync("e0", GetTestPretranslations());
await env.PlatformService.InsertPretranslationsAsync("e0", "b0", GetTestPretranslations());
Assert.That(env.Pretranslations.Count, Is.EqualTo(1));

await env.PlatformService.BuildFaultedAsync("b0", "");
Expand All @@ -48,14 +48,18 @@ await env.Builds.InsertAsync(
Assert.That(env.Engines.Get("e0").IsBuilding, Is.False);

await env.PlatformService.BuildRestartingAsync("b0");
await env.PlatformService.InsertPretranslationsAsync("e0", GetTestPretranslations());
await env.PlatformService.InsertPretranslationsAsync("e0", "b0", GetTestPretranslations());
Assert.That(env.Pretranslations.Count, Is.EqualTo(1));
await env.PlatformService.BuildCompletedAsync("b0", 0, 0.0);
Assert.That(env.Pretranslations.Count, Is.EqualTo(1));
await env.PlatformService.BuildStartedAsync("b0");
await env.PlatformService.InsertPretranslationsAsync("e0", GetTestPretranslations());
await env.PlatformService.InsertPretranslationsAsync("e0", "b0", GetTestPretranslations());
await env.PlatformService.BuildCompletedAsync("b0", 0, 0.0);
Assert.That(env.Pretranslations.Count, Is.EqualTo(1));
Assert.That(
(await env.Builds.GetAsync(b => b.Id == "b0"))?.ExecutionData.AveragePretranslationConfidence,
Is.Zero
);
}

[Test]
Expand Down
Loading