Skip to content

JetBrains-Research/embeddings-for-trees

Repository files navigation

JetBrains Research Github action: build Code style: black Checked with mypy

Embeddings for trees

Set of PyTorch modules for developing and evaluating different algorithms for embedding trees.

Requirements

You can install the dependencies by using the requirement list

pip install -r requirements.txt

Although it's better to install PyTorch and DGL manually for correct CUDA support.

Data preprocessing

List of some useful tools for preprocessing source code into a dataset with ASTs:

  • ASTMiner - tool for mining raw ASTs and path-based representation of code using ANTLR, GumTree and other grammars.
  • PSIMiner - tool for processing PSI trees from IntelliJ IDEA and creating labeled dataset from them.

Model zoo

This section contains information about implemented models.

TreeLSTM

PyTorch reimplementation of ChildSum version of TreeLSTM presented by Tai et al. in "Improved Semantic Representations From Tree-Structured Long Short-Term Memory Networks".

There are 3 different variantions of these model:

  1. Classic — ChildSum TreeLSTM model for code AST with LSTM+attention decoder that was wisely used in other works To train or test model use:
python -m embeddings_for_trees.treelstm train/test -c $CONFIG_PATH
  1. Typed TreeLSTM — the same classic model, but works with typed AST that were introduced in PSIMiner To train or test model use:
python -m embeddings_for_trees.typed_treelstm train/test -c $CONFIG_PATH
  1. TreeLSTM with pointers — ChildSum TreeLSTM model with pointer network to AST leaves for decoding To train or test model use:
python -m embeddings_for_trees.treelstm_ptr train/test -c $CONFIG_PATH

For config examples see config directory. Classic model and model with pointer network share configurations, while typed model requires specification for token types vocabulary.

Contribution

Supporting different algorithms of encoding and decoding trees is the key area of improvement for this framework. If you have any suggestions or questions, feel free to open issues and create pull requests.