All Products
Search
Document Center

Platform For AI:Doc2Vec

Last Updated:Apr 01, 2026

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

ParameterDescription
Document ID ColumnThe name of the document column used for training.
Document ContentThe words used for training. Separate words with spaces.

Parameters Setting tab

ParameterDescription
Dimensions of Word FeaturesThe number of dimensions for word vectors. Valid values: 0–1000. Default value: 100.
Language ModelThe training model. Valid values: Skip-gram Model (default) and CBOW Model.
Word Window SizeThe context window size. Must be a positive integer. Default value: 5.
Minimum Frequency of WordsThe 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 SoftmaxWhether to use hierarchical softmax for training optimization. Selected by default.
Negative SamplingThe negative sampling window size. Must be a positive integer. Default value: 5. Set to 0 to disable negative sampling.
Downsampling ThresholdThe threshold for downsampling frequent words. Valid values: 1e-3 to 1e-5. Default value: 1e-3. Set to 0 to disable downsampling.
Initial Learning RateThe starting learning rate. Must be greater than 0. Default value: 0.025.
Training IterationsThe number of training iterations. Must be greater than or equal to 1. Default value: 1.
Use Random WindowThe word window mode. Valid values: A Random Value Between 1 to 5 and Specified by the Window Parameter (default).

Tuning tab

ParameterDescription
Number of Computing CoresThe 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.

ParameterRequiredDefaultDescription
inputTableNameYesThe name of the input vocabulary table.
inputTablePartitionsNoThe 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 (,).
docIdColNameYesThe name of the document ID column used for training.
docColNameYesThe name of the document content column used for training. Words must be separated by spaces.
layerSizeNo100The number of dimensions for word vectors. Valid values: 0–1000.
cbowNo0The training model. 0 = Skip-gram model; 1 = CBOW model.
windowNo5The context window size. Must be a positive integer.
minCountNo5The minimum word frequency for inclusion in training. Must be a positive integer.
hsNo1Whether to use hierarchical softmax. 0 = disabled; 1 = enabled.
negativeNo5The negative sampling window size. Must be a positive integer. Set to 0 to disable negative sampling.
sampleNo1e-3The downsampling threshold for frequent words. Valid values: 1e-3 to 1e-5. Set to 0 to disable downsampling.
alphaNo0.025The initial learning rate. Must be greater than 0.
iterTrainNo1The number of training iterations. Must be greater than or equal to 1.
randomWindowNo1The word window mode. 0 = use the value specified by window; 1 = use a random value from 1 to 5.
outVocabularyTableNameNoThe name of the output vocabulary table.
outputWordTableNameYesThe name of the output word vector table.
outputDocTableNameYesThe name of the output document vector table.
lifecycleNoThe lifecycle of the output tables. Must be a positive integer.
coreNumNoAutoThe number of computing cores. Takes effect only when both coreNum and memSizePerCore are set. Must be a positive integer.
memSizePerCoreNoAutoThe 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.