The second letter in the Hebrew alphabet is the ב bet/beit. Its meaning is "house". In the ancient pictographic Hebrew it was a symbol resembling a tent on a landscape.
Note: Pre-release packages are distributed via feedz.io.
This goal of this repo is to create ML.NET self contained ML.NET nuget
package that can be used with production DotNetCore
applications for Sentiment
prediction.
If you like or are using this project to learn or start your solution, please give it a star. Thanks!
dotnet add package Bet.Extensions.ML.Sentiment
For complete examples please refer to sample projects:
Bet.AspNetCore.Sample
-AspNetCore
Web App with spam prediction models.Bet.Hosting.Sample
-DotNetCore
Worker based scheduled job for generating ML.NET Models.
// 1. register
services.AddSentimentModelBuilder();
services.AddTimedHostedService<ModelBuilderHostedService>(options =>
{
options.Interval = TimeSpan.FromMinutes(30);
options.FailMode = FailMode.LogAndRetry;
options.RetryInterval = TimeSpan.FromSeconds(30);
});
// 2. build model
public class ModelBuilderHostedService : TimedHostedService
{
private readonly IEnumerable<IModelBuilderService> _modelBuilders;
public ModelBuilderHostedService(
IEnumerable<IModelBuilderService> modelBuilders,
IOptionsMonitor<TimedHostedServiceOptions> options,
IEnumerable<ITimedHostedLifeCycleHook> lifeCycleHooks,
ILogger<ITimedHostedService> logger) : base(options, lifeCycleHooks, logger)
{
TaskToExecuteAsync = (token) => RunModelGenertorsAsync(token);
_modelBuilders = modelBuilders ?? throw new ArgumentNullException(nameof(modelBuilders));
}
public async Task RunModelGenertorsAsync(CancellationToken cancellationToken)
{
foreach (var modelBuilder in _modelBuilders)
{
try
{
await modelBuilder.TrainModelAsync(cancellationToken);
await modelBuilder.ClassifyTestAsync(cancellationToken);
await modelBuilder.SaveModelAsync(cancellationToken);
}
catch (Exception ex)
{
Logger.LogError("{modelBuilder} failed with exception: {message}", modelBuilder.GetType(), ex.Message);
}
}
}
}
// 3. predict
[Route("api/[controller]")]
[ApiController]
public class PredictionController : ControllerBase
{
private readonly IModelPredictionEngine<SentimentIssue, SentimentPrediction> _sentimentModel;
public PredictionController(
IModelPredictionEngine<SentimentIssue, SentimentPrediction> sentimentModel)
{
_sentimentModel = sentimentModel ?? throw new ArgumentNullException(nameof(sentimentModel));
}
[HttpPost()]
public ActionResult<SentimentPrediction> GetSentiment(SentimentIssue input)
{
return _sentimentModel.Predict(input);
}
}