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
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
source | Any | Yes | — | UTF-8 text filename or tokenizedDocument object. |
NameValue | Any | Variadic | — | Name-value options controlling local deterministic embedding training. |
Returns
| Name | Type | Description |
|---|---|---|
emb | Any | Word embedding compatibility object. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:trainWordEmbedding:InvalidInput | Inputs do not match a supported trainWordEmbedding form. | trainWordEmbedding received invalid input |
How trainWordEmbedding works
filenamemay be a string scalar, character vector, scalar string array, or 1-by-1 cell containing a text filename.documentsmust be a RunMattokenizedDocumentcompatibility object.Dimension,Window,Model,DiscardFactor,LossFunction,NumNegativeSamples,NumEpochs,MinCount,NGramRange,InitialLearnRate,UpdateRate, andVerboseare parsed and validated using the documented MATLAB option names.MinCountfilters vocabulary words before model construction. Vocabulary order is descending frequency with first-seen order as the tie-breaker.- The returned object exposes
DimensionandVocabularyand stores dense vectors in the same implementation-detail property used byword2vecandvec2word. - 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.
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 · 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
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how trainWordEmbedding is executed, line by line, in Rust.
- View the source for trainWordEmbedding 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.