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

NameTypeRequiredDefaultDescription
documentsOrBagAnyYestokenizedDocument or bagOfWords object.
wordsOrIdxAnyYesWords to remove or indices into the object's Vocabulary.
NameValueAnyVariadicName-value options: IgnoreCase.

Returns

NameTypeDescription
newDocumentsOrBagAnyFiltered tokenizedDocument or bagOfWords object.

Errors

IdentifierWhenMessage
RunMat:removeWords:InvalidInputInputs do not match a supported removeWords form.removeWords: invalid input

How removeWords works

  • documents must be a RunMat tokenizedDocument object created by tokenizedDocument.
  • bag must be a RunMat bagOfWords object created by bagOfWords.
  • words can be a string vector, character vector, or cell array of character vectors. A character vector is treated as one word.
  • idx can be a numeric vector of positive integer vocabulary positions or a logical array whose length matches the object's Vocabulary.
  • 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, and Language metadata 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.

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how removeWords is executed, line by line, in Rust.

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.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.