-
Notifications
You must be signed in to change notification settings - Fork 827
Add reporting tests that show NLP results. #6574
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
32e53fe
Add reporting tests that show NLP results.
peterwald b597474
Cleanup analyzer errors.
peterwald 02d472c
Add global tags for NLP
peterwald 84ecf9b
Add more precision to the evaluator timing
peterwald f353a5d
More tags
peterwald 4988168
Add another partial match test
peterwald 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
162 changes: 162 additions & 0 deletions
162
test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/NLPEvaluatorTests.cs
This file contains hidden or 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,162 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#pragma warning disable CA2016 // Forward the 'CancellationToken' parameter to methods that take it. | ||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. | ||
|
||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.AI.Evaluation.NLP; | ||
using Microsoft.Extensions.AI.Evaluation.Reporting; | ||
using Microsoft.Extensions.AI.Evaluation.Reporting.Storage; | ||
using Microsoft.TestUtilities; | ||
using Xunit; | ||
|
||
namespace Microsoft.Extensions.AI.Evaluation.Integration.Tests; | ||
|
||
[Experimental("AIEVAL001")] | ||
public class NLPEvaluatorTests | ||
{ | ||
private static readonly ReportingConfiguration? _nlpReportingConfiguration; | ||
|
||
static NLPEvaluatorTests() | ||
{ | ||
if (Settings.Current.Configured) | ||
{ | ||
string version = $"Product Version: {Constants.Version}"; | ||
string date = $"Date: {DateTime.UtcNow:dddd, dd MMMM yyyy}"; | ||
string projectName = $"Project: Integration Tests"; | ||
string testClass = $"Test Class: {nameof(NLPEvaluatorTests)}"; | ||
peterwald marked this conversation as resolved.
Show resolved
Hide resolved
|
||
string usesContext = $"Feature: Context"; | ||
|
||
IEvaluator bleuEvaluator = new BLEUEvaluator(); | ||
IEvaluator gleuEvaluator = new GLEUEvaluator(); | ||
IEvaluator f1Evaluator = new F1Evaluator(); | ||
|
||
_nlpReportingConfiguration = | ||
DiskBasedReportingConfiguration.Create( | ||
storageRootPath: Settings.Current.StorageRootPath, | ||
evaluators: [bleuEvaluator, gleuEvaluator, f1Evaluator], | ||
executionName: Constants.Version, | ||
tags: [version, date, projectName, testClass, usesContext]); | ||
} | ||
} | ||
|
||
[ConditionalFact] | ||
public async Task ExactMatch() | ||
{ | ||
SkipIfNotConfigured(); | ||
|
||
await using ScenarioRun scenarioRun = | ||
await _nlpReportingConfiguration.CreateScenarioRunAsync( | ||
scenarioName: $"Microsoft.Extensions.AI.Evaluation.Integration.Tests.{nameof(NLPEvaluatorTests)}.{nameof(ExactMatch)}"); | ||
|
||
var referenceText = "The quick brown fox jumps over the lazy dog."; | ||
var bleuContext = new BLEUEvaluatorContext(referenceText); | ||
var gleuContext = new GLEUEvaluatorContext(referenceText); | ||
var f1Context = new F1EvaluatorContext(referenceText); | ||
|
||
EvaluationResult result = await scenarioRun.EvaluateAsync(referenceText, [bleuContext, gleuContext, f1Context]); | ||
|
||
Assert.False( | ||
result.ContainsDiagnostics(d => d.Severity >= EvaluationDiagnosticSeverity.Warning), | ||
string.Join("\r\n\r\n", result.Metrics.Values.SelectMany(m => m.Diagnostics ?? []).Select(d => d.ToString()))); | ||
|
||
Assert.Equal(3, result.Metrics.Count); | ||
Assert.True(result.TryGet(BLEUEvaluator.BLEUMetricName, out NumericMetric? _)); | ||
Assert.True(result.TryGet(GLEUEvaluator.GLEUMetricName, out NumericMetric? _)); | ||
Assert.True(result.TryGet(F1Evaluator.F1MetricName, out NumericMetric? _)); | ||
} | ||
|
||
[ConditionalFact] | ||
public async Task PartialMatch() | ||
{ | ||
SkipIfNotConfigured(); | ||
|
||
await using ScenarioRun scenarioRun = | ||
await _nlpReportingConfiguration.CreateScenarioRunAsync( | ||
scenarioName: $"Microsoft.Extensions.AI.Evaluation.Integration.Tests.{nameof(NLPEvaluatorTests)}.{nameof(PartialMatch)}"); | ||
|
||
var referenceText = "The quick brown fox jumps over the lazy dog."; | ||
var bleuContext = new BLEUEvaluatorContext(referenceText); | ||
var gleuContext = new GLEUEvaluatorContext(referenceText); | ||
var f1Context = new F1EvaluatorContext(referenceText); | ||
|
||
var similarText = "The brown fox quickly jumps over a lazy dog."; | ||
EvaluationResult result = await scenarioRun.EvaluateAsync(similarText, [bleuContext, gleuContext, f1Context]); | ||
|
||
Assert.False( | ||
result.ContainsDiagnostics(d => d.Severity >= EvaluationDiagnosticSeverity.Warning), | ||
string.Join("\r\n\r\n", result.Metrics.Values.SelectMany(m => m.Diagnostics ?? []).Select(d => d.ToString()))); | ||
|
||
Assert.Equal(3, result.Metrics.Count); | ||
Assert.True(result.TryGet(BLEUEvaluator.BLEUMetricName, out NumericMetric? _)); | ||
Assert.True(result.TryGet(GLEUEvaluator.GLEUMetricName, out NumericMetric? _)); | ||
Assert.True(result.TryGet(F1Evaluator.F1MetricName, out NumericMetric? _)); | ||
} | ||
|
||
[ConditionalFact] | ||
public async Task Unmatched() | ||
{ | ||
SkipIfNotConfigured(); | ||
|
||
await using ScenarioRun scenarioRun = | ||
await _nlpReportingConfiguration.CreateScenarioRunAsync( | ||
scenarioName: $"Microsoft.Extensions.AI.Evaluation.Integration.Tests.{nameof(NLPEvaluatorTests)}.{nameof(Unmatched)}"); | ||
|
||
var referenceText = "The quick brown fox jumps over the lazy dog."; | ||
var bleuContext = new BLEUEvaluatorContext(referenceText); | ||
var gleuContext = new GLEUEvaluatorContext(referenceText); | ||
var f1Context = new F1EvaluatorContext(referenceText); | ||
|
||
EvaluationResult result = await scenarioRun.EvaluateAsync("What is life's meaning?", [bleuContext, gleuContext, f1Context]); | ||
|
||
Assert.False( | ||
result.ContainsDiagnostics(d => d.Severity >= EvaluationDiagnosticSeverity.Warning), | ||
string.Join("\r\n\r\n", result.Metrics.Values.SelectMany(m => m.Diagnostics ?? []).Select(d => d.ToString()))); | ||
|
||
Assert.Equal(3, result.Metrics.Count); | ||
Assert.True(result.TryGet(BLEUEvaluator.BLEUMetricName, out NumericMetric? _)); | ||
Assert.True(result.TryGet(GLEUEvaluator.GLEUMetricName, out NumericMetric? _)); | ||
Assert.True(result.TryGet(F1Evaluator.F1MetricName, out NumericMetric? _)); | ||
} | ||
|
||
[ConditionalFact] | ||
public async Task AdditionalContextIsNotPassed() | ||
{ | ||
SkipIfNotConfigured(); | ||
|
||
await using ScenarioRun scenarioRun = | ||
await _nlpReportingConfiguration.CreateScenarioRunAsync( | ||
scenarioName: $"Microsoft.Extensions.AI.Evaluation.Integration.Tests.{nameof(NLPEvaluatorTests)}.{nameof(AdditionalContextIsNotPassed)}"); | ||
|
||
EvaluationResult result = await scenarioRun.EvaluateAsync("What is the meaning of life?"); | ||
|
||
Assert.True( | ||
result.Metrics.Values.All(m => m.ContainsDiagnostics(d => d.Severity is EvaluationDiagnosticSeverity.Error)), | ||
string.Join("\r\n\r\n", result.Metrics.Values.SelectMany(m => m.Diagnostics ?? []).Select(d => d.ToString()))); | ||
|
||
Assert.Equal(3, result.Metrics.Count); | ||
Assert.True(result.TryGet(BLEUEvaluator.BLEUMetricName, out NumericMetric? bleu)); | ||
Assert.True(result.TryGet(GLEUEvaluator.GLEUMetricName, out NumericMetric? gleu)); | ||
Assert.True(result.TryGet(F1Evaluator.F1MetricName, out NumericMetric? f1)); | ||
|
||
Assert.Null(bleu.Context); | ||
Assert.Null(gleu.Context); | ||
Assert.Null(f1.Context); | ||
|
||
} | ||
|
||
[MemberNotNull(nameof(_nlpReportingConfiguration))] | ||
private static void SkipIfNotConfigured() | ||
{ | ||
if (!Settings.Current.Configured) | ||
{ | ||
throw new SkipTestException("Test is not configured"); | ||
} | ||
|
||
Assert.NotNull(_nlpReportingConfiguration); | ||
} | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.