readWordEmbedding — Read a word embedding model from a UTF-8 text file or zip archive.
readWordEmbedding(filename) reads UTF-8 word2vec or GloVe text embedding data. Zip archives are supported when they contain an embedding text file.
Syntax
emb = readWordEmbedding(filename)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
filename | Any | Yes | — | UTF-8 word2vec/GloVe text file or zip file containing one. |
Returns
| Name | Type | Description |
|---|---|---|
emb | Any | Word embedding compatibility object. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:readWordEmbedding:InvalidInput | Inputs do not match a supported readWordEmbedding form. | readWordEmbedding received invalid input |
RunMat:readWordEmbedding:IOError | The requested word embedding file cannot be read. | Unable to read word embedding file |
How readWordEmbedding works
filenamemay be a string scalar, character vector, or a 1-by-1 cell array containing a character vector.- Plain text files may use GloVe-style rows (
word value value ...) or word2vec text rows with a leadingnumWords dimensionheader. - Zip archives are scanned for a text-like embedding entry (
.txt,.vec,.glove, or.emb); otherwise the first file entry is parsed as UTF-8 text. - Duplicate words are collapsed so the last duplicate row supplies the vector, matching MATLAB's documented duplicate-word behavior.
- The returned RunMat
wordEmbeddingcompatibility object exposesDimensionandVocabulary. Vector storage is kept in an implementation-detail property used byword2vecandvec2word. - Binary word2vec files, compressed formats other than zip, full pretrained model download helpers, the full fastText support-package corpus, and exact fastText optimizer parity for
trainWordEmbeddingremain tracked in the broader Text Analytics compatibility issue.
GPU memory and residency
readWordEmbedding performs host file IO and has no provider kernel.
Examples
Read An Embedding File
emb = readWordEmbedding('vectors.vec')Expected output:
`emb` is a RunMat `wordEmbedding` compatibility object.Inspect Metadata
emb.Dimension
emb.VocabularyExpected output:
`Dimension` is the vector length, and `Vocabulary` is a string row vector of words.Using readWordEmbedding with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how readWordEmbedding changes the result.
Run a small readWordEmbedding example, explain the result, then change one input and compare the output.
FAQ
Does readWordEmbedding support zip files?⌄
Yes. RunMat reads a UTF-8 embedding text file from a zip archive.
Does readWordEmbedding download pretrained embeddings?⌄
No. This helper reads local UTF-8 text or zip files. Pretrained download helpers remain separate Text Analytics work.
Does readWordEmbedding execute on the GPU?⌄
No. It is host file parsing and object construction.
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 · 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
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how readWordEmbedding is executed, line by line, in Rust.
- View the source for readWordEmbedding 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.