為了"讓機器聽的懂人話", 我們可以透過神經網路讓程式去學習人類說話的方式, 進而理解對話中的意圖, 而整個學習的過程, 可以簡化成文字前處理 > 學習 > 驗證 以往在前處理階段, 通常都是使用NLTK作分詞, 算N-Gram, Normalize 等等... 現在 Tensorflow.Text(TF.Text) 出來後, 除了NLTK之外我們也可以使用 TF.Text 來處理文字 分詞 tokenizer = text.WhitespaceTokenizer() tokens = tokenizer.tokenize([ 'The cat sat on the mat.' , 'i like cats' ]) print(tokens.to_list()) [[b'The', b'cat', b'sat', b'on', b'the', b'mat.'], [b'i', b'like', b'cats']] N-grams tokenizer = text.WhitespaceTokenizer() tokens = tokenizer.tokenize([ 'The cat sat on the mat.' , 'i like cats' ]) # Ngrams, in this case bi-gram (n = 2) bigrams = text.ngrams(tokens, 2, reduction_type=text.Reduction.STRING_JOIN) print(bigrams.to_list()) [[b'The cat', b'cat sat', b'sat on', b'on the', b'the mat.'], [b'i like', b'like cats']] 結論 大家若想嘗鮮的話, 可以使用以下指令來安...