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

doc2sequence — Convert tokenized documents to word-vector or word-index sequences.

doc2sequence(emb, documents) returns a cell array whose i-th cell contains the embedding-vector sequence for the i-th tokenized document. doc2sequence(enc, documents) returns word-index sequences from a wordEncoding object.

Syntax

sequences = doc2sequence(emb, documents)
sequences = doc2sequence(enc, documents)
sequences = doc2sequence(emb, documents, Name, Value)
sequences = doc2sequence(enc, documents, Name, Value)

Inputs

NameTypeRequiredDefaultDescription
embOrEncAnyYes—wordEmbedding or wordEncoding object.
documentsAnyYes—tokenizedDocument object.
NameValueAnyVariadic—Name-value options: UnknownWord, PaddingDirection, PaddingValue, Length.

Returns

NameTypeDescription
sequencesAnyCell array of document embedding-vector or word-index sequences.

Errors

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

How doc2sequence works

  • The first input must be a RunMat wordEmbedding or wordEncoding compatibility object.
  • documents must be a RunMat tokenizedDocument compatibility object.
  • For embedding input, each output cell contains a D-by-S numeric matrix, where D is the embedding dimension and S is the sequence length.
  • For encoding input, each output cell contains a 1-by-S numeric vector of 1-based word encoding indices.
  • Unknown words are discarded by default. Set UnknownWord to "nan" to include NaN vector columns for embedding inputs or NaN index elements for encoding inputs.
  • PaddingDirection accepts "left", "right", and "none". The default is left padding.
  • PaddingValue accepts single, double, or any of the eight integer scalar classes and defaults to 0. Typed storage crosses explicitly to the floating output class. MATLAB warns against NaN padding for deep learning workflows, but RunMat accepts numeric NaN for compatibility.
  • Length accepts "longest", "shortest", or a positive integer in single, double, or any of the eight integer classes. Typed integer scalars are validated exactly; positive fixed lengths truncate sequences on the right.
  • When PaddingDirection is "none", output cells keep per-document sequence lengths, except that fixed or shortest Length values still truncate longer documents.
  • Very large padded dense outputs are rejected with a controlled error to avoid accidental memory explosions.
  • Resident tensors are rejected recursively before provider access, including tensors nested inside compatibility objects such as the __Vectors storage of a wordEmbedding.

GPU memory and residency

doc2sequence performs host text/object sequence construction and has no provider kernel. Top-level and recursively nested resident arguments are rejected before any gather or provider access.

Examples

Convert Documents To Word Vectors

emb = fastTextWordEmbedding;
documents = tokenizedDocument(["alpha beta"; "beta"]);
sequences = doc2sequence(emb, documents)

Expected output:

`sequences` is a cell array of D-by-S matrices.

Convert Documents To Word Indices

documents = tokenizedDocument(["alpha beta"; "beta"]);
enc = wordEncoding(documents);
sequences = doc2sequence(enc, documents)

Expected output:

`sequences` is a cell array of 1-by-S index vectors.

Avoid Padding

sequences = doc2sequence(emb, documents, "PaddingDirection", "none")

Expected output:

Each cell keeps the sequence length of the corresponding document.

Control Padding And Unknown Words

sequences = doc2sequence(emb, documents, "UnknownWord", "nan", "PaddingDirection", "right", "PaddingValue", -1, "Length", 100)

Expected output:

Sequences are right-padded or right-truncated to length 100.

Using doc2sequence with coding agents

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

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

FAQ

Does RunMat support doc2sequence(enc, documents) for wordEncoding?⌄

Yes. RunMat returns one 1-by-S numeric index vector per tokenized document.

Does doc2sequence return single precision like MATLAB examples?⌄

RunMat numeric tensors currently use host f64 storage, so the compatibility output is numeric but not MATLAB's exact single-precision storage.

Does doc2sequence execute on the GPU?⌄

No. The current public documentation does not list a GPU-array capability. RunMat recursively rejects top-level or object-nested resident inputs before provider access and maps host text/object metadata to host cell and tensor outputs.

Related Strings functions

Text Analytics

addDependencyDetails · addEntityDetails · addLemmaDetails · addPartOfSpeechDetails · addSentenceDetails · addTypeDetails · bagOfNgrams · bagOfWords · cosineSimilarity · 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

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

Open-source implementation

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

  • View the source for doc2sequence 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 doc2sequence works
  • GPU memory and residency
  • Examples
  • Convert Documents To Word Vectors
  • Convert Documents To Word Indices
  • Avoid Padding
  • Control Padding And Unknown Words
  • Using doc2sequence with coding agents
  • FAQ
  • Related Strings functions
  • Text Analytics
  • Transform
  • Core
  • Search
  • Pattern
  • Regex
  • Open-source implementation
  • About RunMat