Skip to main content

Text Decomposition

Original integration-test class: DecompositionText in 4.2.1.ML.Decomposition.Text.cs. This is a direct SDK operation, not a PipelineClient workflow.

13 recorded job or prediction directories matched by module and scenario path. 12 have completed/success status and a saved result. These are API execution records, not confirmed xUnit pass counts. Partition jobs are counted separately.

Prerequisites​

Use the original SDK test project, its xUnit dependencies, helper classes and any upstream cache entries referenced in the source. See configuration.

Required environment variable names referenced in the source: PARALLELMODEL_MODEL_ID, PARALLELMODEL_COMPUTE_SIZE, PARALLELMODEL_ENCRYPTION_KEY_1, PARALLELMODEL_REGION, PARALLELMODEL_CLIENT_ID, PARALLELMODEL_CLIENT_SECRET.

SDK calls used​

ClientMethods in the source
DecompositionClientDownloadBytesAsync, ExtractAsync, LogAsync, ResultAsync, SendAsync, StatusAsync

Execution workflow​

  1. Initialise the client and output paths.
  2. Read the exact cached imputed training artifact.
  3. Send the original strongly typed request and save the SDK response.
  4. Poll status and save every response until the job reaches a terminal state.
  5. Retrieve logs once successfully, following ModelSelection.
  6. Retrieve and save the original result response.
  7. Extract and download every artifact returned for this partition.
  8. Atomically replace the completed training-source cache entry.

Recorded operation examples​

OperationRecorded jobsResult recorded
DictionaryLearning11
FactorAnalysis11
FastICA11
IncrementalPCA11
KernelPCA10
LatentDirichletAllocation11
MiniBatchDictionaryLearning11
MiniBatchNMF11
MiniBatchSparsePCA11
NMF11
PCA11
SparsePCA11
TruncatedSVD11

Run the original integration test​

This filter selects the class and its parameterized scenarios; it does not select only a single recorded job.

dotnet test --filter "FullyQualifiedName~ParallelModel.Sdk.UnitTests.DecompositionText.Run"

Full C# source​

The supplied test logic is preserved. The method signature is:

Run(string datasetName, string selectionName, string impute, string name)
using ParallelModel.Sdk.Authentication;
using ParallelModel.Sdk.Exceptions;
using ParallelModel.Sdk.ML.Decomposition.Models.Requests;
using ParallelModel.Sdk.UnitTests.Attributes;
using ParallelModel.Sdk.UnitTests.Cache;
using ParallelModel.Sdk.UnitTests.Helpers;
using System.Text.Json;

namespace ParallelModel.Sdk.UnitTests;

[Collection("Decomposition")]
public sealed class DecompositionText
{
private static readonly SharedSendThrottle sendThrottle = new(TimeSpan.FromSeconds(12));
private static readonly TimeSpan ApiTimeout = TimeSpan.FromSeconds(300);

private static readonly string[] Algorithms = { "DictionaryLearning", "FactorAnalysis", "FastICA",
"IncrementalPCA", "KernelPCA", "LatentDirichletAllocation", "MiniBatchDictionaryLearning",
"MiniBatchNMF", "MiniBatchSparsePCA", "NMF", "PCA", "SparsePCA", "TruncatedSVD" };

public static TheoryData<string, string, string, string> DecompositionRequests =>
ImputeAttribute.GetRequests(typeof(DecompositionText), nameof(Run), DecompositionAlgorithmsFor);

private static string[] DecompositionAlgorithmsFor(string datasetName) => Algorithms;

[Theory]
[Trait("Category", "Integration")]
[MemberData(nameof(DecompositionRequests))]
[Impute("Fetch20Newsgroups", "TrainTestSplit", "SimpleImputer")]
public async Task Run(string datasetName, string selectionName, string impute, string name)
{
// 1. Initialise the client and output paths.
SharedEnvironmentHelper.LoadEnvIfAvailable();
CancellationToken cancellationToken = TestContext.Current.CancellationToken;
Guid modelId = SharedEnvironmentHelper.RequiredGuid("PARALLELMODEL_MODEL_ID");
string computeSize = SharedEnvironmentHelper.Required("PARALLELMODEL_COMPUTE_SIZE");
string encryptionKey = SharedEnvironmentHelper.Required("PARALLELMODEL_ENCRYPTION_KEY_1");
TimeSpan apiRequestTimeout = ApiTimeout;
TimeSpan pollingInterval = TimeSpan.FromSeconds(30);
ParallelModelClient parallelModelClient = new(new DefaultParallelModelAuthenticationOptions
{
Region = SharedEnvironmentHelper.Required("PARALLELMODEL_REGION"),
ClientId = SharedEnvironmentHelper.Required("PARALLELMODEL_CLIENT_ID"),
ClientSecret = SharedEnvironmentHelper.Required("PARALLELMODEL_CLIENT_SECRET"),
Timeout = TimeSpan.FromSeconds(90)
});

string runId = Guid.NewGuid().ToString("N");
string cacheDirectory = SharedEnvironmentHelper.CacheDirectory;

// 2. Read the exact cached imputed training artifact.
// The single-input text SDK makes its own evaluation split; never submit the external test blob.
MLDecompositionHelper.ImputedArtifact source = await MLDecompositionHelper.LoadImputedArtifactAsync(
datasetName, selectionName, impute, "train", cacheDirectory, ImputeCacheEntry.TextFileName,
cancellationToken);
string outputDirectory = Path.Combine(SharedEnvironmentHelper.OutputDirectory, "decomposition.text",
datasetName, selectionName, impute, name, runId, source.Partition);
Directory.CreateDirectory(Path.Combine(outputDirectory, "artifacts"));
int responseFileNumber = 0;

// 3. Send the original strongly typed request and save the SDK response.
await sendThrottle.WaitForSendSlotAsync(cancellationToken);
string requestFileName = NextFileName("request");
JsonElement sendResponse = await RequestAsync("send",
() => SendDecompositionAsync(name, parallelModelClient, modelId, source, datasetName, selectionName, impute,
computeSize, encryptionKey, apiRequestTimeout, outputDirectory,
requestFileName, cancellationToken));
Guid jobId = ReadRequiredGuid(sendResponse, "job_id", "jobId", "JobId");

// 4. Poll status and save every response until the job reaches a terminal state.
DateTimeOffset statusDeadline = DateTimeOffset.UtcNow.AddMinutes(10);
for (int attempt = 1; ; attempt++)
{
JsonElement statusResponse = await RequestAsync(
$"status-{attempt:000}", () => parallelModelClient.DecompositionClient.StatusAsync(
modelId, jobId, computeSize, apiRequestTimeout, cancellationToken),
maximumAttempts: int.MaxValue, retryDeadline: statusDeadline);
string jobStatus = ReadRequiredString(statusResponse, "status", "Status").ToLowerInvariant();
if (jobStatus is "success" or "succeeded" or "completed")
break;
if (jobStatus is "error" or "failed" or "cancelled" or "canceled" or "deadletter" or
"dead-lettered" or "deadlettered" or "dead_letter" or "dead-letter")
{
try
{
await RequestAsync("logs", () => parallelModelClient.DecompositionClient.LogAsync(
modelId, jobId, computeSize, apiRequestTimeout, cancellationToken));
}
catch (Exception exception) when (!cancellationToken.IsCancellationRequested &&
exception is not OperationCanceledException)
{
// RequestAsync already saved the error; retain the terminal job failure.
}
throw new InvalidOperationException($"Job {jobId} ended with status '{jobStatus}'. See saved response.");
}
if (DateTimeOffset.UtcNow >= statusDeadline)
throw new TimeoutException($"Status polling expired for job {jobId}.");
await Task.Delay(pollingInterval, cancellationToken);
}

// 5. Retrieve logs once successfully, following ModelSelection.
try
{
await RequestAsync("logs", () => parallelModelClient.DecompositionClient.LogAsync(
modelId, jobId, computeSize, apiRequestTimeout, cancellationToken), maximumAttempts: 10);
}
catch (Exception exception) when (!cancellationToken.IsCancellationRequested &&
IsTransient(exception))
{
// Logs may be temporarily unavailable; the result can still be retrieved.
}

// 6. Retrieve and save the original result response.
JsonElement result = await RequestAsync("result",
() => parallelModelClient.DecompositionClient.ResultAsync(modelId: modelId, jobId: jobId,
computeSize: computeSize, inputEncryptionKey: encryptionKey, timeout: apiRequestTimeout,
cancellationToken: cancellationToken), maximumAttempts: int.MaxValue,
retryDeadline: DateTimeOffset.UtcNow.AddMinutes(5));

// 7. Extract and download every artifact returned for this partition.
IReadOnlyList<string> artifactFiles = MLDecompositionHelper.GetArtifactPaths(result);
List<DecompositionArtifactCacheEntry> artifacts = new();
for (int index = 0; index < artifactFiles.Count; index++)
{
string artifactPath = artifactFiles[index];
JsonElement extractResponse = await RequestAsync(
$"extract-{index + 1:000}", () => parallelModelClient.DecompositionClient.ExtractAsync(
modelId: modelId, jobId: jobId, fileName: artifactPath, computeSize: computeSize,
inputEncryptionKey: encryptionKey, outputEncryptionKey: encryptionKey,
timeout: apiRequestTimeout, cancellationToken: cancellationToken), maximumAttempts: 5);
Guid blobId = ReadRequiredGuid(extractResponse, "uploaded_blob_id", "uploadedBlobId", "UploadedBlobId");
byte[] bytes = await RequestAsync($"download-{index + 1:000}",
() => parallelModelClient.DecompositionClient.DownloadBytesAsync(
modelId: modelId, jobId: jobId, blobId: blobId, computeSize: computeSize,
inputEncryptionKey: encryptionKey, timeout: apiRequestTimeout,
cancellationToken: cancellationToken), maximumAttempts: 5, saveJson: false);
await SharedArtifactHelper.SaveAsync(outputDirectory, index + 1, artifactPath, bytes, cancellationToken);
artifacts.Add(new DecompositionArtifactCacheEntry(artifactPath, blobId));
}
// 8. Atomically replace the completed training-source cache entry.
DecompositionCacheEntry cacheEntry = new(datasetName, selectionName, impute, name, source.Partition,
source.BlobId, jobId, runId, artifacts.OrderBy(artifact => artifact.ArtifactPath,
StringComparer.Ordinal).ToList());
await SharedCacheHelper.UpdateAsync<List<DecompositionCacheEntry>>(cacheDirectory,
DecompositionCacheEntry.TextFileName, existingEntries =>
{
List<DecompositionCacheEntry> entries = existingEntries ?? new();
entries.RemoveAll(entry => string.Equals(entry.Dataset, datasetName, StringComparison.OrdinalIgnoreCase) &&
string.Equals(entry.ModelSelection, selectionName, StringComparison.OrdinalIgnoreCase) &&
string.Equals(entry.Impute, impute, StringComparison.OrdinalIgnoreCase) &&
string.Equals(entry.Algorithm, name, StringComparison.OrdinalIgnoreCase) &&
string.Equals(entry.Partition, source.Partition, StringComparison.OrdinalIgnoreCase));
entries.Add(cacheEntry);
return entries.OrderBy(entry => entry.Dataset, StringComparer.Ordinal)
.ThenBy(entry => entry.ModelSelection, StringComparer.Ordinal)
.ThenBy(entry => entry.Impute, StringComparer.Ordinal)
.ThenBy(entry => entry.Algorithm, StringComparer.Ordinal)
.ThenBy(entry => entry.Partition, StringComparer.Ordinal).ToList();
}, cancellationToken);

// Local request execution, scoped to this run.
string NextFileName(string stage, string extension = "json") =>
$"{++responseFileNumber:000}-{stage}.{extension}";

async Task<T> RequestAsync<T>(string stage, Func<Task<T>> request,
int maximumAttempts = 1, bool saveJson = true, DateTimeOffset? retryDeadline = null)
{
for (int attempt = 1; ; attempt++)
{
T response;
try
{
response = await request();
}
catch (Exception exception) when (!cancellationToken.IsCancellationRequested)
{
await SharedResponseHelper.SaveExceptionAsync(outputDirectory,
NextFileName($"{stage}-attempt-{attempt:000}-error", "txt"), exception, cancellationToken);
if (attempt >= maximumAttempts || !IsTransient(exception) ||
(retryDeadline.HasValue && DateTimeOffset.UtcNow >= retryDeadline.Value))
throw;
TimeSpan delay = pollingInterval;
if (retryDeadline.HasValue)
{
TimeSpan remaining = retryDeadline.Value - DateTimeOffset.UtcNow;
if (remaining <= TimeSpan.Zero)
throw;
if (remaining < delay)
delay = remaining;
}
await Task.Delay(delay, cancellationToken);
if (retryDeadline.HasValue && DateTimeOffset.UtcNow >= retryDeadline.Value)
throw;
continue;
}
if (saveJson)
await SharedResponseHelper.SaveAsync(outputDirectory, NextFileName(stage), response, cancellationToken);
return response;
}
}

static bool IsTransient(Exception exception) => exception is ParallelModelApiException apiException
? (int)apiException.StatusCode == 404
? !(apiException.Detail ?? string.Empty).Contains("job failed", StringComparison.OrdinalIgnoreCase)
: (int)apiException.StatusCode is 408 or 409 or 429 or >= 500
: exception is System.Net.Http.HttpRequestException or TimeoutException or TaskCanceledException;

// Raw Decomposition SDK responses are JsonElement, not the typed Impute response models.
static string ReadRequiredString(JsonElement response, params string[] propertyNames)
{
if (response.ValueKind == JsonValueKind.Object)
{
foreach (string propertyName in propertyNames)
if (response.TryGetProperty(propertyName, out JsonElement value) &&
value.ValueKind == JsonValueKind.String && value.GetString() is string text &&
!string.IsNullOrWhiteSpace(text))
return text;
if (response.TryGetProperty("response", out JsonElement nested))
return ReadRequiredString(nested, propertyNames);
}
throw new InvalidOperationException($"Missing {propertyNames[0]} in SDK response. See saved response.");
}

static Guid ReadRequiredGuid(JsonElement response, params string[] propertyNames) =>
Guid.Parse(ReadRequiredString(response, propertyNames));
}

private static ParallelModelDecompositionOutputModel CreateDecompositionOutput(
string datasetName, string selectionName, string impute, string algorithm) => new()
{
Name = $"{datasetName}-{selectionName}-{impute}-{algorithm}.zip",
Description = "Decomposition integration test using the cached imputed text training partition",
RecordType = "Generic",
AccessTier = "Hot",
Tags = ["decomposition", "text", datasetName, algorithm]
};

private static async Task<JsonElement> SendDecompositionAsync(
string algorithm, ParallelModelClient client, Guid modelId, MLDecompositionHelper.ImputedArtifact source,
string datasetName, string selectionName, string impute, string size, string key, TimeSpan timeout,
string outputDirectory, string requestFileName, CancellationToken token)
{
ParallelModelDecompositionOutputModel parallelModelDecompositionOutputModel =
CreateDecompositionOutput(datasetName, selectionName, impute, algorithm);

return algorithm switch
{
"DictionaryLearning" => await SendTypedAsync(new DictionaryLearningJobSendRequestModel
{
Input = new DictionaryLearningJobSendRequestModel.DictionaryLearningInputModel
{
InputBlobId = source.BlobId,
ClassifierType = "DictionaryLearning",
ClassifierParams = new DictionaryLearningJobSendRequestModel.DictionaryLearningClassifierParamsModel
{
NComponents = 3,
Alpha = 0.1,
MaxIter = 40,
},
TextColumn = "text",
FileFormat = source.FileFormat,
VectorizerParams = new DictionaryLearningJobSendRequestModel.DictionaryLearningVectorizerParamsModel
{
NgramRange = [1, 2],
MaxFeatures = 120,
MinDf = 1,
},
Evaluation = new DictionaryLearningJobSendRequestModel.DictionaryLearningEvaluationModel
{
TestSize = 0.2,
RandomState = 42,
Shuffle = true,
},
GenerateGraphs = true
},
Output = parallelModelDecompositionOutputModel,
RequestTimeoutSeconds = 300
}),
"FactorAnalysis" => await SendTypedAsync(new FactorAnalysisJobSendRequestModel
{
Input = new FactorAnalysisJobSendRequestModel.FactorAnalysisInputModel
{
InputBlobId = source.BlobId,
ClassifierType = "FactorAnalysis",
ClassifierParams = new FactorAnalysisJobSendRequestModel.FactorAnalysisClassifierParamsModel
{
NComponents = 3,
MaxIter = 200,
},
TextColumn = "text",
FileFormat = source.FileFormat,
VectorizerParams = new FactorAnalysisJobSendRequestModel.FactorAnalysisVectorizerParamsModel
{
NgramRange = [1, 2],
MaxFeatures = 120,
MinDf = 1,
},
Evaluation = new FactorAnalysisJobSendRequestModel.FactorAnalysisEvaluationModel
{
TestSize = 0.2,
RandomState = 42,
Shuffle = true,
},
GenerateGraphs = true
},
Output = parallelModelDecompositionOutputModel,
RequestTimeoutSeconds = 300
}),
"FastICA" => await SendTypedAsync(new FastICAJobSendRequestModel
{
Input = new FastICAJobSendRequestModel.FastICAInputModel
{
InputBlobId = source.BlobId,
ClassifierType = "FastICA",
ClassifierParams = new FastICAJobSendRequestModel.FastICAClassifierParamsModel
{
NComponents = 3,
MaxIter = 400,
},
TextColumn = "text",
FileFormat = source.FileFormat,
VectorizerParams = new FastICAJobSendRequestModel.FastICAVectorizerParamsModel
{
NgramRange = [1, 2],
MaxFeatures = 120,
MinDf = 1,
},
Evaluation = new FastICAJobSendRequestModel.FastICAEvaluationModel
{
TestSize = 0.2,
RandomState = 42,
Shuffle = true,
},
GenerateGraphs = true
},
Output = parallelModelDecompositionOutputModel,
RequestTimeoutSeconds = 300
}),
"IncrementalPCA" => await SendTypedAsync(new IncrementalPCAJobSendRequestModel
{
Input = new IncrementalPCAJobSendRequestModel.IncrementalPCAInputModel
{
InputBlobId = source.BlobId,
ClassifierType = "IncrementalPCA",
ClassifierParams = new IncrementalPCAJobSendRequestModel.IncrementalPCAClassifierParamsModel
{
NComponents = 3,
BatchSize = 16,
},
TextColumn = "text",
FileFormat = source.FileFormat,
VectorizerParams = new IncrementalPCAJobSendRequestModel.IncrementalPCAVectorizerParamsModel
{
NgramRange = [1, 2],
MaxFeatures = 120,
MinDf = 1,
},
Evaluation = new IncrementalPCAJobSendRequestModel.IncrementalPCAEvaluationModel
{
TestSize = 0.2,
RandomState = 42,
Shuffle = true,
},
GenerateGraphs = true
},
Output = parallelModelDecompositionOutputModel,
RequestTimeoutSeconds = 300
}),
"KernelPCA" => await SendTypedAsync(new KernelPCAJobSendRequestModel
{
Input = new KernelPCAJobSendRequestModel.KernelPCAInputModel
{
InputBlobId = source.BlobId,
ClassifierType = "KernelPCA",
ClassifierParams = new KernelPCAJobSendRequestModel.KernelPCAClassifierParamsModel
{
NComponents = 3,
Kernel = "rbf",
},
TextColumn = "text",
FileFormat = source.FileFormat,
VectorizerParams = new KernelPCAJobSendRequestModel.KernelPCAVectorizerParamsModel
{
NgramRange = [1, 2],
MaxFeatures = 120,
MinDf = 1,
},
Evaluation = new KernelPCAJobSendRequestModel.KernelPCAEvaluationModel
{
TestSize = 0.2,
RandomState = 42,
Shuffle = true,
},
GenerateGraphs = true
},
Output = parallelModelDecompositionOutputModel,
RequestTimeoutSeconds = 300
}),
"LatentDirichletAllocation" => await SendTypedAsync(new LatentDirichletAllocationJobSendRequestModel
{
Input = new LatentDirichletAllocationJobSendRequestModel.LatentDirichletAllocationInputModel
{
InputBlobId = source.BlobId,
ClassifierType = "LatentDirichletAllocation",
ClassifierParams = new LatentDirichletAllocationJobSendRequestModel.LatentDirichletAllocationClassifierParamsModel
{
NComponents = 3,
MaxIter = 15,
},
TextColumn = "text",
FileFormat = source.FileFormat,
VectorizerParams = new LatentDirichletAllocationJobSendRequestModel.LatentDirichletAllocationVectorizerParamsModel
{
NgramRange = [1, 2],
MaxFeatures = 120,
MinDf = 1,
},
Evaluation = new LatentDirichletAllocationJobSendRequestModel.LatentDirichletAllocationEvaluationModel
{
TestSize = 0.2,
RandomState = 42,
Shuffle = true,
},
GenerateGraphs = true
},
Output = parallelModelDecompositionOutputModel,
RequestTimeoutSeconds = 300
}),
"MiniBatchDictionaryLearning" => await SendTypedAsync(new MiniBatchDictionaryLearningJobSendRequestModel
{
Input = new MiniBatchDictionaryLearningJobSendRequestModel.MiniBatchDictionaryLearningInputModel
{
InputBlobId = source.BlobId,
ClassifierType = "MiniBatchDictionaryLearning",
ClassifierParams = new MiniBatchDictionaryLearningJobSendRequestModel.MiniBatchDictionaryLearningClassifierParamsModel
{
NComponents = 3,
MaxIter = 40,
},
TextColumn = "text",
FileFormat = source.FileFormat,
VectorizerParams = new MiniBatchDictionaryLearningJobSendRequestModel.MiniBatchDictionaryLearningVectorizerParamsModel
{
NgramRange = [1, 2],
MaxFeatures = 120,
MinDf = 1,
},
Evaluation = new MiniBatchDictionaryLearningJobSendRequestModel.MiniBatchDictionaryLearningEvaluationModel
{
TestSize = 0.2,
RandomState = 42,
Shuffle = true,
},
GenerateGraphs = true
},
Output = parallelModelDecompositionOutputModel,
RequestTimeoutSeconds = 300
}),
"MiniBatchNMF" => await SendTypedAsync(new MiniBatchNMFJobSendRequestModel
{
Input = new MiniBatchNMFJobSendRequestModel.MiniBatchNMFInputModel
{
InputBlobId = source.BlobId,
ClassifierType = "MiniBatchNMF",
ClassifierParams = new MiniBatchNMFJobSendRequestModel.MiniBatchNMFClassifierParamsModel
{
NComponents = 3,
MaxIter = 100,
},
TextColumn = "text",
FileFormat = source.FileFormat,
VectorizerParams = new MiniBatchNMFJobSendRequestModel.MiniBatchNMFVectorizerParamsModel
{
NgramRange = [1, 2],
MaxFeatures = 120,
MinDf = 1,
},
Evaluation = new MiniBatchNMFJobSendRequestModel.MiniBatchNMFEvaluationModel
{
TestSize = 0.2,
RandomState = 42,
Shuffle = true,
},
GenerateGraphs = true
},
Output = parallelModelDecompositionOutputModel,
RequestTimeoutSeconds = 300
}),
"MiniBatchSparsePCA" => await SendTypedAsync(new MiniBatchSparsePCAJobSendRequestModel
{
Input = new MiniBatchSparsePCAJobSendRequestModel.MiniBatchSparsePCAInputModel
{
InputBlobId = source.BlobId,
ClassifierType = "MiniBatchSparsePCA",
ClassifierParams = new MiniBatchSparsePCAJobSendRequestModel.MiniBatchSparsePCAClassifierParamsModel
{
NComponents = 3,
MaxIter = 40,
},
TextColumn = "text",
FileFormat = source.FileFormat,
VectorizerParams = new MiniBatchSparsePCAJobSendRequestModel.MiniBatchSparsePCAVectorizerParamsModel
{
NgramRange = [1, 2],
MaxFeatures = 120,
MinDf = 1,
},
Evaluation = new MiniBatchSparsePCAJobSendRequestModel.MiniBatchSparsePCAEvaluationModel
{
TestSize = 0.2,
RandomState = 42,
Shuffle = true,
},
GenerateGraphs = true
},
Output = parallelModelDecompositionOutputModel,
RequestTimeoutSeconds = 300
}),
"NMF" => await SendTypedAsync(new NMFJobSendRequestModel
{
Input = new NMFJobSendRequestModel.NMFInputModel
{
InputBlobId = source.BlobId,
ClassifierType = "NMF",
ClassifierParams = new NMFJobSendRequestModel.NMFClassifierParamsModel
{
NComponents = 3,
MaxIter = 200,
},
TextColumn = "text",
FileFormat = source.FileFormat,
VectorizerParams = new NMFJobSendRequestModel.NMFVectorizerParamsModel
{
NgramRange = [1, 2],
MaxFeatures = 120,
MinDf = 1,
},
Evaluation = new NMFJobSendRequestModel.NMFEvaluationModel
{
TestSize = 0.2,
RandomState = 42,
Shuffle = true,
},
GenerateGraphs = true
},
Output = parallelModelDecompositionOutputModel,
RequestTimeoutSeconds = 300
}),
"PCA" => await SendTypedAsync(new PCAJobSendRequestModel
{
Input = new PCAJobSendRequestModel.PCAInputModel
{
InputBlobId = source.BlobId,
ClassifierType = "PCA",
ClassifierParams = new PCAJobSendRequestModel.PCAClassifierParamsModel
{
NComponents = 3,
SvdSolver = "auto",
},
TextColumn = "text",
FileFormat = source.FileFormat,
VectorizerParams = new PCAJobSendRequestModel.PCAVectorizerParamsModel
{
NgramRange = [1, 2],
MaxFeatures = 120,
MinDf = 1,
},
Evaluation = new PCAJobSendRequestModel.PCAEvaluationModel
{
TestSize = 0.2,
RandomState = 42,
Shuffle = true,
},
GenerateGraphs = true
},
Output = parallelModelDecompositionOutputModel,
RequestTimeoutSeconds = 300
}),
"SparsePCA" => await SendTypedAsync(new SparsePCAJobSendRequestModel
{
Input = new SparsePCAJobSendRequestModel.SparsePCAInputModel
{
InputBlobId = source.BlobId,
ClassifierType = "SparsePCA",
ClassifierParams = new SparsePCAJobSendRequestModel.SparsePCAClassifierParamsModel
{
NComponents = 3,
MaxIter = 40,
},
TextColumn = "text",
FileFormat = source.FileFormat,
VectorizerParams = new SparsePCAJobSendRequestModel.SparsePCAVectorizerParamsModel
{
NgramRange = [1, 2],
MaxFeatures = 120,
MinDf = 1,
},
Evaluation = new SparsePCAJobSendRequestModel.SparsePCAEvaluationModel
{
TestSize = 0.2,
RandomState = 42,
Shuffle = true,
},
GenerateGraphs = true
},
Output = parallelModelDecompositionOutputModel,
RequestTimeoutSeconds = 300
}),
"TruncatedSVD" => await SendTypedAsync(new TruncatedSVDJobSendRequestModel
{
Input = new TruncatedSVDJobSendRequestModel.TruncatedSVDInputModel
{
InputBlobId = source.BlobId,
ClassifierType = "TruncatedSVD",
ClassifierParams = new TruncatedSVDJobSendRequestModel.TruncatedSVDClassifierParamsModel
{
NComponents = 3,
Algorithm = "randomized",
},
TextColumn = "text",
FileFormat = source.FileFormat,
VectorizerParams = new TruncatedSVDJobSendRequestModel.TruncatedSVDVectorizerParamsModel
{
NgramRange = [1, 2],
MaxFeatures = 120,
MinDf = 1,
},
Evaluation = new TruncatedSVDJobSendRequestModel.TruncatedSVDEvaluationModel
{
TestSize = 0.2,
RandomState = 42,
Shuffle = true,
},
GenerateGraphs = true
},
Output = parallelModelDecompositionOutputModel,
RequestTimeoutSeconds = 300
}),
_ => throw new NotSupportedException(algorithm)
};

async Task<JsonElement> SendTypedAsync<TRequest>(TRequest request)
where TRequest : class, IParallelModelDecompositionSendRequest
{
await SharedResponseHelper.SaveAsync(outputDirectory, requestFileName, request, token);
return await client.DecompositionClient.SendAsync(modelId, request, size, key, key, timeout, token);
}
}
}