Function Repository Resource:
Text Embedding Plot
Create a plot of the dimension-reduced text embeddings of a collection of strings
ResourceFunction["TextEmbeddingPlot"][{string1,string2,…},dim] computes embedding vectors for each of the stringi, reduces them to dimension dim, and plots the result. | |
ResourceFunction["TextEmbeddingPlot"][{list1,list2,…},dim] computes embedding vectors for each string in each of the listi, reduces them to dimension dim, and plots the result. |
Details and Options
Examples
Basic Examples (2) 
Plot the embeddings of a list of strings:
| In[1]:= |
| Out[1]= |
Compare sentence embeddings from different texts:
| In[2]:= |
| Out[2]= |
Scope (3) 
Prepare sentences from three different text sources:
| In[3]:= |
Create a labeled plot:
| In[4]:= |
| Out[4]= |
Present the same data with a different dimension reduction method:
| In[5]:= |
| Out[5]= |
Options (10) 
"EmbeddingFunction" (4) 
Define a custom embedding function using an external service, which also prints information on model and token use:
| In[6]:= |
Use the custom embedding function on the previously defined data:
| In[7]:= |
| Out[7]= |
The "EmbeddingFunction" should accept a list of strings as input. Use a naive embedding function that computes letter counts:
| In[8]:= |
| Out[8]= |
A function specified for "EmbeddingFunction" should output a corresponding list of vectors or NumericArray objects:
| In[9]:= |
| In[10]:= |
| Out[10]= |
"ReductionMethod" (3) 
Method options of DimensionReduction are supported:
| In[11]:= |
| Out[11]= |
Use a specific dimension reduction function:
| In[12]:= |
| Out[12]= |
| In[13]:= |
| Out[13]= |
Define an arbitrary function to perform the dimension reduction on embedding vectors:
| In[14]:= |
| Out[14]= |
Labeling Function (3) 
Use default behavior of ListPlot:
| In[15]:= |
| Out[15]= |
Use default behavior of ListPointPlot3D:
| In[16]:= |
| Out[16]= |
Define a custom LabelingFunction:
| In[17]:= |
| Out[17]= |
Possible Issues (1) 
A "ReductionMethod" that is not one of the supported options for DimensionReduction must accept vectors of the appropriate input and output dimensions:
| In[18]:= |
| Out[18]= |
| In[19]:= |
| Out[19]= |
| In[20]:= |
| Out[20]= |
| In[21]:= |
| Out[21]= |