-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathTextClassificationIntegrationTests.cs
More file actions
38 lines (28 loc) · 1.34 KB
/
TextClassificationIntegrationTests.cs
File metadata and controls
38 lines (28 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using FAI.NLP.PipelineBatchExecutors;
namespace FAI.IntegrationTests;
public class TextClassificationIntegrationTests
{
[Fact]
public async Task FullPipeline_ShouldClassifyText()
{
// Arrange
var services = new ServiceCollection();
var options = new ClassificationOptions<bool>([false, true]);
services.AddSingleton(options);
services.AddPipeline<TokenizedText, ClassificationResult<bool, float>>()
.Use<TokenizerBatchExecutor<TokenizedText, ClassificationResult<bool, float>>>();
var tokenizer = DummyTokenizerFactory.Create();
services.AddSingleton(tokenizer);
// Mock model: always returns high probability for 'true' (index 1)
services.AddSingleton<IModelExecutor<long, float>>(new LogicalMockModelExecutor([[0.1f, 0.9f]]));
services.AddSingleton<IInferenceSteps<TokenizedText, ClassificationResult<bool, float>>, TextClassification<bool>>();
var provider = services.BuildServiceProvider();
var pipeline = provider.GetRequiredService<IPipeline<TokenizedText, ClassificationResult<bool, float>>>();
// Act
var input = new TokenizedText("hello");
var results = await pipeline.BatchPredict(new[] { input });
// Assert
results.Should().HaveCount(1);
results[0].Choice.Should().BeTrue();
}
}