معالجة اللغة الطبيعية · NLP
تجهيز النصوص بـ Text Analytics Toolbox
Text Preprocessing with Text Analytics Toolbox
تقطيع وتنظيف وتجذيع ثم حقيبة كلمات ومصنف خطي.
textData = ["The battery life is excellent"; "Terrible screen, broke in a week"; ...
"Great value and fast delivery"; "Worst purchase ever"];
labels = categorical(["pos"; "neg"; "pos"; "neg"]);
docs = tokenizedDocument(lower(textData));
docs = erasePunctuation(docs);
docs = removeWords(docs, setdiff(stopWords, ["not" "no"]));
docs = normalizeWords(docs, 'Style', 'stem');
bag = bagOfWords(docs);
X = tfidf(bag);
mdl = fitcecoc(X, labels, 'Learners', 'linear');
newDocs = normalizeWords(erasePunctuation(tokenizedDocument(lower("excellent delivery"))), 'Style', 'stem');
predict(mdl, tfidf(bag, newDocs))شرح الخطوات
- tokenizedDocument يقطع النص.
- نحتفظ بكلمات النفي خارج قائمة الحذف.
- tfidf(bag, newDocs) يستخدم IDF التدريب للنص الجديد.
المخرجات المتوقعة
الفئة المتوقعة للنص الجديد (categorical). أربعة أمثلة للتوضيح فقط؛ النموذج الحقيقي يحتاج آلاف المراجعات.
لم يُشغّل في بيئة إعداد المكتبة لأنه يحتاج: Text Analytics Toolbox، Statistics and Machine Learning Toolbox. المخرجات أدناه وصف لما يجب أن تراه، لا أرقام فعلية.
