The source code used for self-supervised taxonomy expansion method TaxoExpan, published in WWW 2020.
From following page: https://www.dgl.ai/pages/start.html
conda install -c dglteam dgl-cuda10.0
For dataset used in our WWW paper, you can directly download all input files from Google Drive and skip this section.
For expanding new input taxonomies, you need to read this section and format your datasets accordingly.
1.
taxon1_id \t taxon1_surface_name
taxon2_id \t taxon2_surface_name
taxon3_id \t taxon3_surface_name
...
2.
parent_taxon1_id \t child_taxon1_id
parent_taxon2_id \t child_taxon2_id
parent_taxon3_id \t child_taxon3_id
...
3.
<VOCAB_SIZE> <EMBED_DIM>
taxon1_id taxon1_embedding
taxon2_id taxon2_embedding
taxon3_id taxon3_embedding
...
The embedding file follows the gensim word2vec format.
Notes:
You can generate your desired train/validation/test parition files by creating another 3 separated files (named
These three partition files are of the same format -- each line includes one taxon_id that appears in the above
python generate_dataset_binary.py \
--taxon_name <TAXONOMY_NAME> \
--data_dir <DATASET_NAME> \
--embed_suffix <EMBED_SUFFIX> \
--existing_partition 0
This script will first load the existing taxonomy (along with initial node features indicated by embed_suffix
) from the previous three required files.
Then, if existing_partition
is 0, it will generate a random train/validation/test partitions, otherwise, it will load the existing train/validation/test partition files.
Finally, it saves the generated dataset (along with all initial node features) in one pickle file for fast loading next time.
Write all the parameters in ./config_files/config.universal.json and start training.
python train.py --config config_files/config.universal.json
For example, you can indicate the architectures of graph propagation module, graph readout module, and matching module as follow:
python train.py --config config_files/config.universal.json --pm PGAT --rm WMR --mm LBM --device 0
Please check ./train.py for all configurable parameters.
python test_fast.py --resume <MODEL_CHECKPOINT.pth> --device 0
python test_fast.py --resume <MODEL_CHECKPOINT.pth> --test_data <TEST_DATA.bin> --device 0
python test_fast.py --resume <MODEL_CHECKPOINT.pth> --case <OUTPUT_CASE_FILE.tsv> --device 0
Note: test with case study saving will almost double the running time, so if you don't really need to see the predicted parents, disable this functionality.
python test_fast.py --resume <MODEL_CHECKPOINT.pth> --batch_size 30000 --device 0
Predict on completely new taxons.
We assume the input taxon list is of the following format:
term1 \t embeddings of term1
term2 \t embeddings of term2
term3 \t embeddings of term3
...
The term can be either a unigram or a phrase, as long as it doesn't contain "\t" character. The embedding is space-sperated and of the same dimension of trained model. An input example is provided: ./data/mag_cs_new637.txt. An output example is provided: ./case_studies/infer_results_637_20191111.txt.
python infer.py --resume <MODEL_CHECKPOINT.pth> --taxon <INPUT_TAXON_LIST.txt> --save <OUTPUT_RESULT.tsv> --device 0
The model prediction results are saved in OUTPUT_RESULT.tsv.
Pretained models for MAG-CS and MAG-Full datasets can be downloaded from Google Drive.
MAG-CS: ./case_studies/mag_cs_case_study_20191111.tsv
MAG-Full: ./case_studies/mag_full_case_study_20191111.tsv
The detailed preprocessing code please refer to ./data_preprocessing/semeval-task14.ipython.
Other possible choices include: (1) general sentence embedding, (2) other bert/xlnet-based embedding, and (3) definition encoder.
For SemEval data, after training the model and running the test script with case study output, you need to read the script /scripts/parse_to_semeval_format.py
to generate a tsv that satisfies the format requirements in original SemEval completition as follows:
python ./scripts/parse_to_semeval_format.py \
--input <CASE_FILE.tsv> \
--output <SEMEVAL_FILE.tsv>
For our own TaxoExpan implementation, we follow the project organization in pytorch-template.