RunMat
  • Pricing
RunMat
GitHub
GitHub
DownloadSign InTry in Browser
DesktopRuntimeServer
RunMat

Run math blazing fast

GitHubX (Twitter)LinkedIn

Company

  • About
  • Pricing
  • Contact

Explore

  • RunMat for academia
  • RunMat vs MATLAB Online
  • Benchmarks

Get product updates and release notes from the RunMat team.

© 2026 Dystr · Made withfor the scientific community.

RunMat™ is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

LicensePrivacy
/
See all docs
Builtin Reference
    • addDependencyDetails
    • addEntityDetails
    • addLemmaDetails
    • addPartOfSpeechDetails
    • addSentenceDetails
    • addTypeDetails
    • bagOfNgrams
    • bagOfWords
    • cosineSimilarity
    • doc2sequence
    • encode
    • extractFileText
    • extractHTMLText
    • fastTextWordEmbedding
    • findElement
    • getAttribute
    • htmlTree
    • ind2word
    • isVocabularyWord
    • normalizeWords
    • readWordEmbedding
    • removeLongWords
    • removeShortWords
    • removeStopWords
    • removeWords
    • stopWords
    • tokenDetails
    • tokenizedDocument
    • trainWordEmbedding
    • vaderSentimentScores
    • vec2word
    • word2ind
    • word2vec
    • wordEncoding
    • writeWordEmbedding

wordEncoding — Create a word encoding object that maps words to indices and back.

wordEncoding(documents) creates a wordEncoding object from tokenized documents. wordEncoding(words) creates one from a word vector.

Syntax

enc = wordEncoding(documents)
enc = wordEncoding(words)
enc = wordEncoding(documents, Name, Value)

Inputs

NameTypeRequiredDefaultDescription
documentsOrWordsAnyYes—tokenizedDocument object or word vector.
NameValueAnyVariadic—Name-value options: Order, MaxNumWords.

Returns

NameTypeDescription
encAnyWord encoding compatibility object.

Errors

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

How wordEncoding works

  • documents must be a tokenizedDocument object.
  • words may be a string scalar, string array, character vector, character matrix, or cell array of scalar text. A character vector is treated as one word.
  • The returned object exposes NumWords and Vocabulary. Vocabulary is a 1-by-NumWords string array.
  • Order accepts "first-seen" and "frequency" for tokenizedDocument input. The default is first-seen order.
  • For frequency ordering, RunMat sorts by descending total count and uses first-seen order as a deterministic tie-breaker.
  • MaxNumWords accepts a positive integer-valued double or Inf for tokenizedDocument input. The option is applied after ordering.
  • A native integer scalar for MaxNumWords is a RunMat language extension. It is accepted in runmat mode and decoded exactly as a positive structural count.
  • RunMat rejects Order and MaxNumWords when the first input is a word vector, matching the documented MATLAB syntax.
  • First-class MATLAB object-array identity semantics are not required for this scalar model object and remain covered by the broader object infrastructure work.

GPU memory and residency

wordEncoding constructs host text and object metadata and does not launch provider kernels.

Examples

Create Encoding From Documents

documents = tokenizedDocument(["alpha beta alpha"; "gamma beta"]);
enc = wordEncoding(documents)

Expected output:

`enc.Vocabulary` is `["alpha" "beta" "gamma"]` for first-seen order.

Sort By Frequency

enc = wordEncoding(documents, "Order", "frequency", "MaxNumWords", 2)

Expected output:

`enc.Vocabulary` contains the two most frequent words.

Using wordEncoding with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how wordEncoding changes the result.

Run a small wordEncoding example, explain the result, then change one input and compare the output.

FAQ

Can the result be used with doc2sequence?⌄

Yes. doc2sequence(enc, documents) returns cell arrays of 1-by-S word-index vectors.

Does wordEncoding execute on the GPU?⌄

No. It constructs host text metadata and does not use provider kernels.

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 · removeWords · stopWords · tokenDetails · tokenizedDocument · trainWordEmbedding · vaderSentimentScores · vec2word · word2ind · word2vec · 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

Regex

regexp · regexpi · regexprep

Related guides

  • MATLAB language extensions

Open-source implementation

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

  • View the source for wordEncoding 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.

Getting started · Benchmarks · Pricing

Download RunMat

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

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • How wordEncoding works
  • GPU memory and residency
  • Examples
  • Create Encoding From Documents
  • Sort By Frequency
  • Using wordEncoding with coding agents
  • FAQ
  • Related Strings functions
  • Text Analytics
  • Transform
  • Core
  • Search
  • Pattern
  • Regex
  • Related guides
  • Open-source implementation
  • About RunMat