Doc2Vec is a machine learning algorithm that generates fixed-length document vectors by treating document IDs as special words during training. It learns both word vectors and document vectors simultaneously, enabling you to compare semantic relationships between documents by measuring distances in vector space.
Use Doc2Vec when you need to:
Rank documents by similarity to a query document
Build content recommendation systems
Cluster documents by topic
The algorithm takes a vocabulary table as input and produces up to three outputs: a document vector table, a word vector table, and an optional vocabulary table.
Limitations
Doc2Vec runs on MaxCompute computing resources only.
Configure the Doc2Vec component
Two configuration methods are available: the PAI console (Machine Learning Designer) and PAI commands via SQL scripts.
Configure in the PAI console
On the pipeline page of Machine Learning Designer, configure the Doc2Vec component using the parameters described below.
Fields Setting tab
| Parameter | Description |
|---|---|
| Document ID Column | The name of the document column used for training. |
| Document Content | The words used for training. Separate words with spaces. |
Parameters Setting tab
| Parameter | Description |
|---|---|
| Dimensions of Word Features | The number of dimensions for word vectors. Valid values: 0–1000. Default value: 100. |
| Language Model | The training model. Valid values: Skip-gram Model (default) and CBOW Model. |
| Word Window Size | The context window size. Must be a positive integer. Default value: 5. |
| Minimum Frequency of Words | The minimum word frequency for inclusion in training. Words appearing fewer times than this threshold are excluded. Must be a positive integer. Default value: 5. |
| Hierarchical Softmax | Whether to use hierarchical softmax for training optimization. Selected by default. |
| Negative Sampling | The negative sampling window size. Must be a positive integer. Default value: 5. Set to 0 to disable negative sampling. |
| Downsampling Threshold | The threshold for downsampling frequent words. Valid values: 1e-3 to 1e-5. Default value: 1e-3. Set to 0 to disable downsampling. |
| Initial Learning Rate | The starting learning rate. Must be greater than 0. Default value: 0.025. |
| Training Iterations | The number of training iterations. Must be greater than or equal to 1. Default value: 1. |
| Use Random Window | The word window mode. Valid values: A Random Value Between 1 to 5 and Specified by the Window Parameter (default). |
Tuning tab
| Parameter | Description |
|---|---|
| Number of Computing Cores | The number of computing cores to use. The system determines the value automatically by default. |
| Memory Size per Core (MB) | The memory allocated per core. The system determines the value automatically by default. |
Configure using PAI commands
Call the Doc2Vec component with PAI commands. For information on running PAI commands in SQL scripts, see SQL Script.
The following example shows a minimal configuration:
PAI -name pai_doc2vec
-project algo_public
-DinputTableName="d2v_input"
-DdocIdColName="docid"
-DdocColName="text_seg"
-DoutputWordTableName="d2v_word_output"
-DoutputDocTableName="d2v_doc_output";The input table must contain at least two columns: a document ID column (such as docid) and a document content column (such as text_seg) where words are separated by spaces.
The full parameter reference is as follows.
| Parameter | Required | Default | Description |
|---|---|---|---|
inputTableName | Yes | — | The name of the input vocabulary table. |
inputTablePartitions | No | — | The partitions to use from the input table. Format: partition_name=value. For multiple partitions, use name1=value1/name2=value2, and separate partition sets with commas (,). |
docIdColName | Yes | — | The name of the document ID column used for training. |
docColName | Yes | — | The name of the document content column used for training. Words must be separated by spaces. |
layerSize | No | 100 | The number of dimensions for word vectors. Valid values: 0–1000. |
cbow | No | 0 | The training model. 0 = Skip-gram model; 1 = CBOW model. |
window | No | 5 | The context window size. Must be a positive integer. |
minCount | No | 5 | The minimum word frequency for inclusion in training. Must be a positive integer. |
hs | No | 1 | Whether to use hierarchical softmax. 0 = disabled; 1 = enabled. |
negative | No | 5 | The negative sampling window size. Must be a positive integer. Set to 0 to disable negative sampling. |
sample | No | 1e-3 | The downsampling threshold for frequent words. Valid values: 1e-3 to 1e-5. Set to 0 to disable downsampling. |
alpha | No | 0.025 | The initial learning rate. Must be greater than 0. |
iterTrain | No | 1 | The number of training iterations. Must be greater than or equal to 1. |
randomWindow | No | 1 | The word window mode. 0 = use the value specified by window; 1 = use a random value from 1 to 5. |
outVocabularyTableName | No | — | The name of the output vocabulary table. |
outputWordTableName | Yes | — | The name of the output word vector table. |
outputDocTableName | Yes | — | The name of the output document vector table. |
lifecycle | No | — | The lifecycle of the output tables. Must be a positive integer. |
coreNum | No | Auto | The number of computing cores. Takes effect only when both coreNum and memSizePerCore are set. Must be a positive integer. |
memSizePerCore | No | Auto | The memory size per core in MB. Takes effect only when both coreNum and memSizePerCore are set. Must be a positive integer. |
References
For an overview of Machine Learning Designer, see Overview of Machine Learning Designer.