trainWordEmbedding — Train a local word embedding compatibility model.

trainWordEmbedding(filename) and trainWordEmbedding(documents) return a RunMat wordEmbedding compatibility object trained from local text. File input is UTF-8 text with one document per line and whitespace-separated words. tokenizedDocument input uses the stored document tokens.

Syntax

emb = trainWordEmbedding(filename)
emb = trainWordEmbedding(documents)
emb = trainWordEmbedding(___, Name, Value)

Inputs

NameTypeRequiredDefaultDescription
sourceAnyYesUTF-8 text filename or tokenizedDocument object.
NameValueAnyVariadicName-value options controlling local deterministic embedding training.

Returns

NameTypeDescription
embAnyWord embedding compatibility object.

Errors

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

How trainWordEmbedding works

  • filename may be a string scalar, character vector, scalar string array, or 1-by-1 cell containing a text filename.
  • documents must be a RunMat tokenizedDocument compatibility object.
  • Dimension, Window, Model, DiscardFactor, LossFunction, NumNegativeSamples, NumEpochs, MinCount, NGramRange, InitialLearnRate, UpdateRate, and Verbose are parsed and validated using the documented MATLAB option names.
  • MinCount filters vocabulary words before model construction. Vocabulary order is descending frequency with first-seen order as the tie-breaker.
  • The returned object exposes Dimension and Vocabulary and stores dense vectors in the same implementation-detail property used by word2vec and vec2word.
  • RunMat uses a deterministic local compatibility trainer based on lexical/subword hashing and windowed co-occurrence features. This is suitable for repeatable scripts and downstream embedding lookup, but it is not MATLAB's exact fastText optimizer.
  • Very large dense embedding outputs are rejected with a controlled error until sparse/model-storage infrastructure is added.

GPU memory and residency

trainWordEmbedding performs host text processing and model construction and has no provider kernel.

Examples

Train From File

emb = trainWordEmbedding("training.txt", "Dimension", 50, "MinCount", 1)

Expected output:

`emb` is a RunMat `wordEmbedding` compatibility object.

Train From Tokenized Documents

documents = tokenizedDocument(["alpha beta"; "beta gamma"]);
emb = trainWordEmbedding(documents, "Window", 2)

Expected output:

`emb.Vocabulary` contains the retained document tokens.

Using trainWordEmbedding with coding agents

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

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

FAQ

Does RunMat implement MATLAB's exact fastText training algorithm?

Not yet. This slice implements a deterministic local compatibility trainer and keeps exact optimizer parity in the broader Text Analytics queue.

Can the trained model be used with word2vec and vec2word?

Yes. The output is the same RunMat wordEmbedding compatibility object used by the existing embedding lookup builtins.

Does trainWordEmbedding execute on the GPU?

No. It reads host text/model data and builds host vectors.

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how trainWordEmbedding 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.