stopwordsDefault:機器學習文字轉換

可在定型模型之前對資料執行的文字轉換。

使用方式

  stopwordsDefault()

  stopwordsCustom(dataFile = "")

  termDictionary(terms = "", dataFile = "", sort = "occurrence")

  featurizeText(vars, language = "English", stopwordsRemover = NULL,
    case = "lower", keepDiacritics = FALSE, keepPunctuations = TRUE,
    keepNumbers = TRUE, dictionary = NULL,
    wordFeatureExtractor = ngramCount(), charFeatureExtractor = NULL,
    vectorNormalizer = "l2", ...)

引數

dataFile

字元:<字串>。 包含字詞的資料檔案 (簡短格式資料)。

terms

字詞或類別的選擇性字元向量。

sort

指定在向量化時排序項目的方式。 支援兩種排序:

  • "occurrence":項目依遇到的順序顯示。
  • "value":項目根據其預設比較來排序。 例如,文字排序會區分大小寫 (例如依序為 'A'、'Z'、'a')。

vars

輸入變數名稱和輸出變數名稱的字元向量具名清單。 請注意,輸入變數必須為相同類型。 對於輸入與輸出變數之間的一對一對應,可以使用具名字元向量。

language

指定資料集中使用的語言。 支援下列值:

  • "AutoDetect":用於自動語言偵測。
  • "English".
  • "French".
  • "German".
  • "Dutch".
  • "Italian".
  • "Spanish".
  • "Japanese".

stopwordsRemover

指定要使用的停用字詞移除器。 支援三個選項:

  • NULL 不使用停用字詞移除器。
  • stopwordsDefault:使用先行編譯的語言特定停用字詞清單,其中包含 Microsoft Office 中最常見的單字。
  • stopwordsCustom:使用者定義的停用字詞清單。 可接受的選項如下:dataFile
    預設值是 NULL

case

使用「不因文化特性而異」規則的文字大小寫。 採用下列值:

  • "lower".
  • "upper".
  • "none".
    預設值是 "lower"

keepDiacritics

FALSE 會移除變音符號;TRUE 會保留變音符號。 預設值是 FALSE

keepPunctuations

FALSE 會移除標點符號;TRUE 會保留標點符號。 預設值是 TRUE

keepNumbers

FALSE 會移除數字;TRUE 會保留數字。 預設值是 TRUE

dictionary

已加入允許清單之字詞的 termDictionary,可接受下列選項:

  • terms,
  • dataFile,以及
  • sort.
    預設值是 NULL。 請注意,停用字詞清單的優先權高於字典允許清單,因為在將字典字詞加入允許清單之前已移除停用字詞。

wordFeatureExtractor

指定單字特徵擷取引數。 有兩種不同的特徵擷取機制:

  • ngramCount:以計數為基礎的特徵擷取 (相當於 WordBag)。 可接受的選項如下:maxNumTermsweighting
  • ngramHash:以雜湊為基礎的特徵擷取 (相當於 WordHashBag)。 可接受的選項如下:hashBitsseedorderedinvertHash
    預設值是 ngramCount

charFeatureExtractor

指定字元特徵擷取引數。 有兩種不同的特徵擷取機制:

  • ngramCount:以計數為基礎的特徵擷取 (相當於 WordBag)。 可接受的選項如下:maxNumTermsweighting
  • ngramHash:以雜湊為基礎的特徵擷取 (相當於 WordHashBag)。 可接受的選項如下:hashBitsseedorderedinvertHash
    預設值是 NULL

vectorNormalizer

藉由將向量 (資料列) 調整為單位範數,個別將其正規化。 採用下列其中一個值:

  • "none".
  • "l2".
  • "l1".
  • "linf". 預設值是 "l2"

...

傳送至計算引擎的其他引數。

詳細資料

featurizeText 轉換
會從指定的文字主體產生一組連續單字序列 (稱為 n-gram)。 有兩種方式可完成此作業:

建置 n-gram 的字典,並使用字典中的識別碼作為包中的索引;

對每個 n-gram 進行雜湊處理,並使用雜湊值作為包中的索引。

雜湊的目的是將可變長度的文字文件轉換成等長數值特徵向量,以支援維度縮減並加速查閱特徵權數。

文字轉換會套用到文字輸入資料行。 這可提供語言偵測、Token 化、停用字詞移除、文字正規化及特徵產生。 其預設支援下列語言:英文、法文、德文、荷蘭文、義大利文、西班牙文和日文。

n-gram 以計數向量表示,其中向量詞槽對應於 n-gram (使用 ngramCount 建立) 或對應於其雜湊 (使用 ngramHash 建立)。 在向量空間中內嵌 ngram 可讓其內容以有效率的方式進行比較。 向量中的詞槽值可透過下列因素進行加權:

字詞頻率 - 詞槽在文字中的出現次數

反向文件頻率 - 一種比率 (反向相對詞槽頻率的對數),藉由判斷詞槽出現在整體文字中的頻率高低程度來測量詞槽提供的資訊。

字詞頻率/反向文件頻率 - 字詞頻率與反向文件頻率的乘積。

定義轉換的 maml 物件。

作者

Microsoft Corporation Microsoft Technical Support

另請參閱

ngramCountngramHashrxFastTreesrxFastForestrxNeuralNetrxOneClassSvmrxLogisticRegression

範例


 trainReviews <- data.frame(review = c( 
         "This is great",
         "I hate it",
         "Love it",
         "Do not like it",
         "Really like it",
         "I hate it",
         "I like it a lot",
         "I kind of hate it",
         "I do like it",
         "I really hate it",
         "It is very good",
         "I hate it a bunch",
         "I love it a bunch",
         "I hate it",
         "I like it very much",
         "I hate it very much.",
         "I really do love it",
         "I really do hate it",
         "Love it!",
         "Hate it!",
         "I love it",
         "I hate it",
         "I love it",
         "I hate it",
         "I love it"),
      like = c(TRUE, FALSE, TRUE, FALSE, TRUE,
         FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE,
         FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, 
         FALSE, TRUE, FALSE, TRUE), stringsAsFactors = FALSE
     )

     testReviews <- data.frame(review = c(
         "This is great",
         "I hate it",
         "Love it",
         "Really like it",
         "I hate it",
         "I like it a lot",
         "I love it",
         "I do like it",
         "I really hate it",
         "I love it"), stringsAsFactors = FALSE)


 outModel <- rxLogisticRegression(like ~ reviewTran, data = trainReviews,
     mlTransforms = list(featurizeText(vars = c(reviewTran = "review"),
     stopwordsRemover = stopwordsDefault(), keepPunctuations = FALSE)))
 # 'hate' and 'love' have non-zero weights
 summary(outModel)

 # Use the model to score
 scoreOutDF5 <- rxPredict(outModel, data = testReviews, 
     extraVarsToWrite = "review")
 scoreOutDF5