TextCatalog.NormalizeText メソッド

定義

必要に応じて大文字と小文字を TextNormalizingEstimator変更し、分音記号、句読点、数値を削除して入力テキスト inputColumnName を正規化し、新しいテキストを次のように outputColumnName出力します。

public static Microsoft.ML.Transforms.Text.TextNormalizingEstimator NormalizeText (this Microsoft.ML.TransformsCatalog.TextTransforms catalog, string outputColumnName, string inputColumnName = default, Microsoft.ML.Transforms.Text.TextNormalizingEstimator.CaseMode caseMode = Microsoft.ML.Transforms.Text.TextNormalizingEstimator+CaseMode.Lower, bool keepDiacritics = false, bool keepPunctuations = true, bool keepNumbers = true);
static member NormalizeText : Microsoft.ML.TransformsCatalog.TextTransforms * string * string * Microsoft.ML.Transforms.Text.TextNormalizingEstimator.CaseMode * bool * bool * bool -> Microsoft.ML.Transforms.Text.TextNormalizingEstimator
<Extension()>
Public Function NormalizeText (catalog As TransformsCatalog.TextTransforms, outputColumnName As String, Optional inputColumnName As String = Nothing, Optional caseMode As TextNormalizingEstimator.CaseMode = Microsoft.ML.Transforms.Text.TextNormalizingEstimator+CaseMode.Lower, Optional keepDiacritics As Boolean = false, Optional keepPunctuations As Boolean = true, Optional keepNumbers As Boolean = true) As TextNormalizingEstimator

パラメーター

catalog
TransformsCatalog.TextTransforms

テキスト関連の変換のカタログ。

outputColumnName
String

の変換の結果として得られる列の inputColumnName名前。 この列のデータ型は、入力列のデータ型に応じて、スカラーまたはテキストのベクターです。

inputColumnName
String

変換する列の名前。 に null設定すると、その値が outputColumnName ソースとして使用されます。 このエスティメーターは、テキストデータ型のテキストまたはベクトルに対して動作します。

caseMode
TextNormalizingEstimator.CaseMode

インバリアント カルチャのルールを使用してテキストを大文字と小文字を区別します。

keepDiacritics
Boolean

分音記号を保持するか、削除するかを指定します。

keepPunctuations
Boolean

句読点を保持するか、削除するか。

keepNumbers
Boolean

数値を保持するか、削除するか。

戻り値

using System;
using System.Collections.Generic;
using Microsoft.ML;
using Microsoft.ML.Transforms.Text;

namespace Samples.Dynamic
{
    public static class NormalizeText
    {
        public static void Example()
        {
            // Create a new ML context, for ML.NET operations. It can be used for
            // exception tracking and logging, as well as the source of randomness.
            var mlContext = new MLContext();

            // Create an empty list as the dataset. The 'NormalizeText' API does not
            // require training data as the estimator ('TextNormalizingEstimator')
            // created by 'NormalizeText' API is not a trainable estimator. The
            // empty list is only needed to pass input schema to the pipeline.
            var emptySamples = new List<TextData>();

            // Convert sample list to an empty IDataView.
            var emptyDataView = mlContext.Data.LoadFromEnumerable(emptySamples);

            // A pipeline for normalizing text.
            var normTextPipeline = mlContext.Transforms.Text.NormalizeText(
                "NormalizedText", "Text", TextNormalizingEstimator.CaseMode.Lower,
                keepDiacritics: false,
                keepPunctuations: false,
                keepNumbers: false);

            // Fit to data.
            var normTextTransformer = normTextPipeline.Fit(emptyDataView);

            // Create the prediction engine to get the normalized text from the
            // input text/string.
            var predictionEngine = mlContext.Model.CreatePredictionEngine<TextData,
                TransformedTextData>(normTextTransformer);

            // Call the prediction API.
            var data = new TextData()
            {
                Text = "ML.NET's NormalizeText API " +
                "changes the case of the TEXT and removes/keeps diâcrîtîcs, " +
                "punctuations, and/or numbers (123)."
            };

            var prediction = predictionEngine.Predict(data);

            // Print the normalized text.
            Console.WriteLine($"Normalized Text: {prediction.NormalizedText}");

            //  Expected output:
            //   Normalized Text: mlnets normalizetext api changes the case of the text and removeskeeps diacritics punctuations andor numbers
        }

        private class TextData
        {
            public string Text { get; set; }
        }

        private class TransformedTextData : TextData
        {
            public string NormalizedText { get; set; }
        }
    }
}

適用対象