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

vec2word — Map embedding vectors to nearest vocabulary words.

vec2word(emb, M) returns the nearest vocabulary word for each row of M. [words, dist] = vec2word(emb, M, k) returns the k nearest words and distances.

Syntax

words = vec2word(emb, M)
[words, dist] = vec2word(emb, M, k, 'Distance', distance)

Inputs

NameTypeRequiredDefaultDescription
embAnyYes—wordEmbedding object.
MNumericArrayYes—Embedding vectors, one vector per row.
kNumericScalarNo1Number of nearest words.
NameValueAnyVariadic—Name-value options: Distance ('cosine' or 'euclidean').

Returns

NameTypeDescription
wordsAnyClosest vocabulary words.
distNumericArrayDistances to input vectors.

Returned values from vec2word depend on how many outputs the caller requests.

Errors

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

How vec2word works

  • emb must be a RunMat wordEmbedding compatibility object.
  • M must be an n-by-emb.Dimension numeric matrix.
  • k is an optional positive integer from 1 through the vocabulary size. The default is 1.
  • Native integer storage for M and native integer storage for k are independent RunMat language extensions. Integer query values must be exactly representable as double before distance calculation, while k is decoded as an exact structural value.
  • The default distance metric is cosine distance. vec2word(___, 'Distance', 'euclidean') uses Euclidean distance.
  • words is an n-by-k string array. dist is an n-by-k numeric matrix.
  • For zero-norm query or vocabulary vectors under cosine distance, RunMat reports infinite distance so finite matches sort ahead of them.

GPU memory and residency

vec2word compares host text-model storage and has no provider kernel. Supported resident query data may gather automatically through its owning provider.

Examples

Find Nearest Words

emb = readWordEmbedding('vectors.vec');
M = word2vec(emb, ["king" "queen"]);
words = vec2word(emb, M)

Expected output:

`words` contains the nearest vocabulary word for each vector row.

Return Multiple Neighbors

[words, dist] = vec2word(emb, M, 3, "Distance", "cosine")

Expected output:

`words` and `dist` have three columns.

Using vec2word with coding agents

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

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

FAQ

Which distances are supported?⌄

RunMat supports "cosine" and "euclidean".

Does vec2word execute on the GPU?⌄

No. It compares the host-resident embedding model.

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 · 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

Related guides

  • MATLAB Language Extensions

Open-source implementation

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

  • View the source for vec2word 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 vec2word works
  • GPU memory and residency
  • Examples
  • Find Nearest Words
  • Return Multiple Neighbors
  • Using vec2word with coding agents
  • FAQ
  • Related Strings functions
  • Text Analytics
  • Transform
  • Core
  • Search
  • Pattern
  • Regex
  • Related guides
  • Open-source implementation
  • About RunMat