removeWords — Remove selected words from tokenized documents or bag-of-words models.
removeWords(documents, words) removes selected tokens from RunMat tokenizedDocument compatibility objects. removeWords(bag, words) removes matching vocabulary columns from RunMat bagOfWords objects. words can also be numeric 1-based vocabulary indices or a logical mask the same length as the object's vocabulary.
Syntax
newDocumentsOrBag = removeWords(documentsOrBag, words)
newDocumentsOrBag = removeWords(documentsOrBag, idx)
newDocumentsOrBag = removeWords(___, 'IgnoreCase', tf)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
documentsOrBag | Any | Yes | — | tokenizedDocument or bagOfWords object. |
wordsOrIdx | Any | Yes | — | Words to remove or indices into the object's Vocabulary. |
NameValue | Any | Variadic | — | Name-value options: IgnoreCase. |
Returns
| Name | Type | Description |
|---|---|---|
newDocumentsOrBag | Any | Filtered tokenizedDocument or bagOfWords object. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:removeWords:InvalidInput | Inputs do not match a supported removeWords form. | removeWords: invalid input |
How removeWords works
documentsmust be a RunMattokenizedDocumentobject created bytokenizedDocument.bagmust be a RunMatbagOfWordsobject created bybagOfWords.wordscan be a string vector, character vector, or cell array of character vectors. A character vector is treated as one word.idxcan be a numeric vector of positive integer vocabulary positions or a logical array whose length matches the object'sVocabulary.removeWords(___, 'IgnoreCase', true)removes string-selected or index-selected vocabulary words without case sensitivity. The default is case-sensitive.- For tokenized documents, the result preserves
Shape,TokenizeMethod, andLanguagemetadata while recomputing document lengths and vocabulary. - For bag-of-words models, the result preserves document row count and removes matching count columns.
GPU memory and residency
removeWords filters host text/model objects and has no provider kernel.
Examples
Remove Words From Documents
documents = tokenizedDocument(["an example of a short sentence"; "a second short sentence"]);
newDocuments = removeWords(documents, ["short" "second"])Expected output:
`newDocuments` contains `an example of a sentence` and `a sentence`.Remove Words By Vocabulary Index
documents = tokenizedDocument(["I love MATLAB"; "I love MathWorks"]);
newDocuments = removeWords(documents, [1 3])Expected output:
`newDocuments` removes the first and third vocabulary entries.Remove Words From A Bag
documents = tokenizedDocument(["an example of a short sentence"; "a second short sentence"]);
bag = bagOfWords(documents);
newBag = removeWords(bag, stopWords)Expected output:
`newBag` removes count columns for the selected vocabulary words.Using removeWords with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how removeWords changes the result.
Run a small removeWords example, explain the result, then change one input and compare the output.
FAQ
Is removeWords case-sensitive?⌄
Yes by default. Use removeWords(___, 'IgnoreCase', true) for case-insensitive matching.
Does a logical index mask need to match the vocabulary length?⌄
Yes. RunMat rejects logical masks whose length differs from the object's vocabulary length.
Does removeWords execute on the GPU?⌄
No. It filters host text/model metadata and has no runmat-accelerate provider path.
Related Strings functions
Text Analytics
addDependencyDetails · addEntityDetails · addLemmaDetails · addPartOfSpeechDetails · addSentenceDetails · addTypeDetails · bagOfNgrams · bagOfWords · cosineSimilarity · doc2sequence · encode · extractFileText · extractHTMLText · fastTextWordEmbedding · findElement · getAttribute · htmlTree · ind2word · isVocabularyWord · normalizeWords · readWordEmbedding · removeLongWords · removeShortWords · removeStopWords · stopWords · tokenDetails · tokenizedDocument · trainWordEmbedding · vaderSentimentScores · vec2word · word2ind · word2vec · wordEncoding · writeWordEmbedding
Transform
append · deblank · erase · eraseBetween · erasePunctuation · eraseURLs · extractAfter · extractBefore · extractBetween · insertAfter · insertBefore · join · lower · pad · replace · replaceBetween · reverse · split · splitlines · strcat · strip · strjoin · strjust · strrep · strsplit · strtrim · upper
Core
blanks · char · compose · convertCharsToStrings · convertContainedStringsToChars · convertStringsToChars · genvarname · int2str · isletter · isspace · isStringScalar · isstrprop · mat2str · native2unicode · newline · num2str · sprintf · sscanf · str2double · str2num · strcmp · strcmpi · string · string.empty · strings · strlength · strncmp · strncmpi · strtok · unicode2native
Search
contains · endsWith · matches · startsWith · strfind
Pattern
digitsPattern · lettersPattern · pattern · regexpPattern · textBoundary · wildcardPattern
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how removeWords is executed, line by line, in Rust.
- View the source for removeWords in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.