├── .coveragerc ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── experiments └── BigARTM_run_example.ipynb ├── library.md ├── presentation ├── article meeting.pdf ├── article meeting.tex ├── bibl.bib └── imgs │ ├── nade black.png │ ├── nade.png │ ├── rnn-encoder-decoder white.png │ └── rnn-encoder-decoder.png ├── requirements.txt ├── setup.py └── snippet_ranger ├── __init__.py ├── __main__.py ├── data ├── matplotlib_dependent_reps.txt ├── numpy_dependent_reps.txt ├── pandas_dependent_reps.txt ├── tensorflow_dependent_reps.txt └── tqdm_dependent_reps.txt ├── librariesio_fetcher.py ├── model2 ├── __init__.py ├── base_split.py ├── snippet2bow.py ├── snippet2df.py └── source2func.py ├── models ├── __init__.py └── snippet.py ├── pylib2uast.py ├── tests ├── __init__.py ├── data │ ├── snippet_test_repo.asdf │ ├── source_test_repo.asdf │ ├── test_lib.asdf │ ├── test_lib │ │ ├── __init__.py │ │ └── example.py │ ├── test_librariesio_data │ │ ├── projects-1.0.0-2017-06-15.csv │ │ └── repository_dependencies-1.0.0-2017-06-15.csv │ └── test_repo │ │ └── example.py ├── models.py ├── test_librariesio_fetcher.py ├── test_main.py ├── test_snippet.py ├── test_source2func.py └── test_utils.py └── utils.py /.coveragerc: -------------------------------------------------------------------------------- 1 | 2 | [run] 3 | branch = True 4 | source = snippet_ranger 5 | 6 | [report] 7 | exclude_lines = 8 | no cover 9 | raise NotImplementedError 10 | if __name__ == "__main__": 11 | ignore_errors = True 12 | omit = 13 | snippet_ranger/tests/* 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Mac specific 2 | *.DS_Store 3 | 4 | # Python 5 | */__pycache__/* 6 | *.pyc 7 | 8 | # tex files 9 | *.aux 10 | *.bbl 11 | *.blg 12 | *.fdb_latexmk 13 | *.fls 14 | *.log 15 | *.nav 16 | *.out 17 | *.snm 18 | *.synctex.gz 19 | *.toc 20 | *.vrb 21 | 22 | # jupyter notebooks 23 | *.ipynb_checkpoints/ 24 | 25 | # pycharm 26 | .idea 27 | 28 | #LibraryIO data 29 | data/Libraries/* -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | sudo: false 3 | dist: trusty 4 | services: 5 | - docker 6 | cache: 7 | directories: 8 | - "$HOME/.cache/pip" 9 | _install: &_install 10 | - gimme 1.8 11 | - source ~/.gimme/envs/latest.env 12 | - pip install --upgrade pip 13 | - pip install -r requirements.txt codecov 14 | - pip install -e . 15 | _coverage: &_coverage 16 | - SCRIPT="coverage run --concurrency=multiprocessing -m unittest discover && coverage combine" 17 | matrix: 18 | include: 19 | - python: 3.4 20 | env: *_coverage 21 | install: *_install 22 | - python: 3.5 23 | env: *_coverage 24 | install: *_install 25 | - python: 3.6 26 | env: SCRIPT="pep8 --max-line-length=99 ." 27 | install: pip install pep8 28 | - python: 3.6 29 | env: *_coverage 30 | install: *_install 31 | after_success: 32 | - codecov 33 | fast_finish: true 34 | script: 35 | - (eval "$SCRIPT") 36 | notifications: 37 | email: false 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Snippet ranger 2 | 3 | [![Build Status](https://travis-ci.org/src-d/snippet-ranger.svg)](https://travis-ci.org/src-d/snippet-ranger) 4 | [![codecov](https://codecov.io/github/src-d/snippet-ranger/coverage.svg)](https://codecov.io/gh/src-d/snippet-ranger) 5 | 6 | This tool is built on top of [ast2vec](https://github.com/src-d/ast2vec) Machine Learning models. 7 | 8 | Provides API and tools to train and use models for ecosystem exploratory snippet mining. 9 | It can help you to learn new libraries faster and speed up coding speed. 10 | The module allows you to train and use hierarchical topic model on top of 11 | [babelfish](https://github.com/bblfsh) UAST for any library you want. 12 | 13 | Now Snippet ranger is under **active development**. 14 | 15 | ## Install 16 | 17 | ``` 18 | pip3 install git+https://github.com/src-d/snippet-ranger 19 | ``` 20 | 21 | ## Usage 22 | 23 | The project exposes two interfaces: API and command line. The command line is 24 | 25 | ``` 26 | snippet_ranger --help 27 | ``` 28 | 29 | ## Pipeline for dataset collection 30 | 31 | **1. Get list of dependent repositories.** 32 | 33 | You should have libraries.io (v1.0.0) dataset on your disk. 34 | You can download it here: https://libraries.io/data 35 | 36 | Example for `numpy` library: 37 | ``` 38 | snippet_ranger dependent_reps --librariesio_data ../libio/ -o . --libraries numpy:https://github.com/numpy/numpy 39 | ``` 40 | 41 | There are examples of output files in [data folder](https://github.com/src-d/snippet-ranger/tree/master/data). 42 | You can use it to try snippet_ranger without a need to download libraries.io dataset. 43 | 44 | **2. Clone repositories** 45 | 46 | Use `ast2vec clone` for it. It requires enry. Install it via `ast2vec enry` if you do not have. 47 | Example: 48 | ``` 49 | ast2vec clone --ignore -o data/repos/numpy -t 16 --languages Python --linguist ./enry numpy.txt 50 | ``` 51 | 52 | You can skip the second step if you do not want to store repositories. 53 | But enry installation is necessary. 54 | 55 | **3. Convert to Source [modelforge](https://github.com/src-d/modelforge) models** 56 | 57 | Use `ast2vec repos2source` for it. 58 | You should have bblfsh server running. 59 | Please use v0.7.0 and v0.8.2. of python driver: 60 | ``` 61 | BBLFSH_DRIVER_IMAGES="python=docker://bblfsh/python-driver:v0.8.2" docker run -e BBLFSH_DRIVER_IMAGES --rm --privileged -d -p 9432:9432 --name bblfsh bblfsh/server:v0.7.0 --log-level DEBUG 62 | ``` 63 | 64 | Example: 65 | ``` 66 | ast2vec repos2source -p 2 -t 8 --organize-files 2 -o data/sources $( find data/repos/numpy -maxdepth 1 -mindepth 1 -type d | xargs) 67 | ``` 68 | If you skip second step replace `data/repos/numpy` with `data/numpy_dependent_reps.txt`: 69 | ``` 70 | ast2vec repos2source -p 2 -t 8 --organize-files 2 -o data/sources data/numpy_dependent_reps.txt 71 | ``` 72 | 73 | Check [ast2vec topic modeling instructions](https://github.com/src-d/ast2vec/blob/master/topic_modeling.md#fetch-repositories-and-save-them-as-source-models) 74 | to learn more about parameters. 75 | 76 | **4. Get UAST for the library** 77 | 78 | If you use the library for Python, first you should install it to avoid autogenerated files losing. 79 | UAST is builded from installation directory: 80 | ``` 81 | snippet_ranger pylib2uast -p 1 -o ./data/libraries_uasts numpy 82 | ``` 83 | 84 | You can use other languages which are supported by [bblfsh](doc.bblf.sh). 85 | Just download the library sources and run `ast2vec repo2uast` for it. 86 | 87 | **5. Extract snippets from Source model** 88 | 89 | Use `snippet_ranger source2func` for it. 90 | 91 | This command does the following: 92 | * Filter files without library usage. 93 | * Split files to functions or take full file if there are no functions (just script). 94 | * Filter split result without library function calls. 95 | 96 | More ways of snippet extraction can be added later. 97 | 98 | Example: 99 | ``` 100 | snippet_ranger source2func -p 8 --library_name numpy --library_uast ./data/libraries_uasts/numpy.asdf -o ./data/funcs/numpy/ ./data/sources/numpy 101 | ``` 102 | 103 | If you have several `All functions are filtered and you get empty model.` errors it is ok. 104 | 105 | **6. Create vowpal wabbit dataset** 106 | 107 | Here you have two way. Default one is use all simple identifiers as tokens for document modeling, 108 | as described in 3-4 points in 109 | [ast2vec topic modeling instructions](https://github.com/src-d/ast2vec/blob/master/topic_modeling.md). 110 | 111 | Another one, use only specific identifiers, which can be found in the library UAST. 112 | For now, it is only about function calls (fc). 113 | Use `snippet2fc_df` and `snippet2fc_bow` for the second approach. 114 | 115 | Example: 116 | ``` 117 | mkdir ./data/dfs_fc 118 | snippet_ranger snippet2fc_df -p 8 --library_name numpy --library_uast ./data/libraries_uasts/numpy.asdf ./data/funcs/numpy/ ./data/dfs_fc/numpy.asdf 119 | snippet_ranger snippet2fc_bow -p 8 --df ./data/dfs_fc/numpy.asdf -v 1000000 ./data/funcs/numpy/ ./data/bows_fc/numpy 120 | ``` 121 | 122 | Then you need to do the same as in 5-7 points in 123 | [ast2vec topic modeling](https://github.com/src-d/ast2vec/blob/master/topic_modeling.md): 124 | 125 | ``` 126 | python3 -m ast2vec join-bow -p 16 --bow ./data/bows_fc/numpy ./data/bows_fc/numpy.asdf 127 | python3 -m ast2vec bow2vw --bow ./data/bows_fc/numpy.asdf -o ./data/vowpal_wabbit/numpy_fc.txt 128 | ``` 129 | 130 | ## Fit shallow and hierarchical topic model 131 | 132 | **On going** 133 | 134 | You should install BigARTM library. 135 | Easy way is to use `ast2vec bigartm` command (not implemented yet). 136 | 137 | You can checkout 138 | [simple draft experiment using BigARTM Python API notebook](https://github.com/src-d/snippet-ranger/blob/master/experiments/BigARTM_run_example.ipynb). 139 | 140 | ## Contributions 141 | [![PEP8](https://img.shields.io/badge/code%20style-pep8-orange.svg)](https://www.python.org/dev/peps/pep-0008/) 142 | 143 | We use [PEP8](https://www.python.org/dev/peps/pep-0008/) with line length 99 and ". All the tests 144 | must pass: 145 | 146 | ``` 147 | unittest discover /path/to/ast2vec 148 | ``` 149 | 150 | ## License 151 | 152 | Apache 2.0. 153 | -------------------------------------------------------------------------------- /library.md: -------------------------------------------------------------------------------- 1 | 2 | # Topic modeling 3 | 4 | ## BigARTM 5 | * [BigARTM](http://bigartm.org) main site 6 | * BigARTM [Tutorial on Probabilistic Topic Modeling: Additive Regularization for Stochastic Matrix Factorization](http://www.machinelearning.ru/wiki/images/1/1f/Voron14aist.pdf) 7 | * BigARTM [Additive Regularization for Topic Models of Text Collections](http://www.machinelearning.ru/wiki/images/2/21/Voron14dan-eng.pdf) 8 | * Main idea: Additive Regularization of Topic Models 9 | * hARTM for hierarchical topic modeling. [presentation](http://www.machinelearning.ru/wiki/images/d/dc/2.Chirkova.pdf) 10 | 11 | ## Other 12 | * [Collaborative deep learning for recommender systems](https://arxiv.org/pdf/1409.2944.pdf). [code](https://github.com/js05212/MXNet-for-CDL/blob/master/collaborative-dl.ipynb). 13 | > We generalize recent advances in deep learning from i.i.d. input to non-i.i.d. (CF-based) input and propose in this paper a hierarchical Bayesian model called collaborative deep learning (CDL), which jointly performs deep representation learning for the content information and collaborative filtering for the ratings (feedback) matrix. Extensive experiments on three real-world datasets from different domains show that CDL can significantly advance the state of the art. 14 | * [Scalable Deep Poisson Factor Analysis for Topic Modeling](http://proceedings.mlr.press/v37/gan15.pdf), [matlab code](https://github.com/zhegan27/dpfa_icml2015) 15 | 16 | # DocNADE for document representation 17 | 18 | * [DocNADE](http://proceedings.mlr.press/v15/larochelle11a/larochelle11a.pdf) and [post how to use it](http://blog.aylien.com/tensorflow-implementation-neural-autoregressive-topic-model-docnade/) to get document representation. 19 | 20 | # Deep learning way 21 | 22 | Another way to solve similar task 23 | 24 | * [Deep API learning, Xiaodong Gu, Hongyu Zhang, Dongmei Zhang, and Sunghun Kim](https://arxiv.org/pdf/1605.08535v1.pdf) 25 | > We propose DeepAPI, a deep learning based approach to generate API usage sequences for a given natural language query. DeepAPI adapts a neural language model named RNN Encoder-Decoder. It encodes a word sequence (user query) into a fixed-length context vector, and generates an API sequence based on the context vector. We also augment the RNN Encoder-Decoder by considering the importance of individual APIs. We empirically evaluate our approach with more than 7 million annotated code snippets collected from GitHub. The results show that our approach generates largely accurate API sequences and outperforms the related approaches. 26 | 27 | * RNN Encoder-Decoder 28 | > the API learning problem as a machine translation problem: given a natural language query x = x1 , ..., xn where xt is a key word, we aim to translate it into an API sequence y = y1,...,ym where yt is an API 29 | * Learns on 30 | > a corpus of annotated API sequences, i.e., ⟨API sequence, annotation⟩ pairs, 31 | 32 | # Probabilistic way. Interesting Sequence Mining 33 | 34 | * [MAST-group.](https://mast-group.github.io/) Probabilistic API Miner. [github](https://github.com/mast-group/api-mining), article [Parameter-Free Probabilistic API Mining across GitHub](https://arxiv.org/pdf/1512.05558.pdf). 35 | > PAM is a near parameter-free probabilistic algorithm for mining the most interesting API patterns from a list of API call sequences. PAM largely avoids returning redundant and spurious sequences, unlike API mining approaches based on frequent pattern mining. 36 | 37 | > the hand-written examples actually have limited coverage of real API usages. 38 | 39 | * [MAST-group.](https://mast-group.github.io/) Interesting Sequence Miner [github](https://github.com/mast-group/sequence-mining), article [A Subsequence Interleaving Model for Sequential Pattern Mining](https://arxiv.org/pdf/1602.05012.pdf) 40 | > ISM is a novel algorithm that mines the subsequences that are most interesting under a probabilistic model of a sequence database. Our model is able to efficiently infer interesting subsequences directly from the database. 41 | 42 | ### Related works from articles 43 | * MAPO 44 | * Use code search engines for finding snippets. 45 | * Clustering by method according to a distance metric, computed as an average of the similarity of method names, class names, and the called API methods themselves. 46 | * For each cluster, MAPO mines the most frequent API calls using SPAM 47 | * UP-Miner 48 | * extends MAPO 49 | * use BIDE algorithm. It returns only the frequent sequences that have no subsequences with the same frequency 50 | * clustering distance metric based on the set of all API call sequence n-grams 51 | * SNIFF 52 | * finds abstract code examples relevant to a natural language query expressing a desired task. 53 | * annotates publicly available source code with API documentation and the annotated code is then indexed for searching. 54 | 55 | # Can be useful 56 | 57 | * [Searching and Skimming: An Exploratory Study. Jamie Starke, Chris Luce, Jonathan Sillito University of Calgary 58 | Calgary, Canada](http://people.ucalgary.ca/~sillito/work/icsm2009.pdf) 59 | > We conducted a formative study in which programmers were asked to perform corrective tasks to a system they were initially unfamiliar with. Our analysis focused specifically on how programmers decide what to search for, and how they decide which results are relevant to their task. Based on our analysis, we present five observations about our participant’s approach to finding information and some of the challenges they faced. We also discuss the implications these observations have for the design of source code search tools. 60 | 61 | # Others articles 62 | 63 | * [Code Search via Topic-Enriched Dependence Graph Matching](http://ink.library.smu.edu.sg/cgi/viewcontent.cgi?article=2396&context=sis_research) 64 | > In this paper, we propose a semantic dependence search engine that integrates both kinds of techniques and can retrieve code snippets based on expressive user queries describing both topics and dependencies. Users can specify their search targets in a free form format describing desired topics (i.e., high-level semantic or functionality of the target code); a specialized graph query language allows users to describe low-level data and control dependencies in code and thus helps to refine the queries described in the free format. Our empirical evaluation on a number of software maintenance tasks shows that our search engine can efficiently locate desired code fragments accurately. 65 | 66 | * Use LDA and structural and semantic representations (system dependence graphs (SDGs)) of code. 67 | * Have special and overcomplicated query language 68 | 69 | * [Improving Topic Model Source Code Summarization Paul W. McBurney, Cheng Liu, Collin McMillan, and Tim Weninger](https://www3.nd.edu/~cmc/papers/mcburney_icpcera_2014.pdf) 70 | > In this paper, we present an emerging source code summarization technique that uses topic modeling to select keywords and topics as summaries for source code. Our approach organizes the topics in source code into a hierarchy, with more general topics near the top of the hierarchy. In this way, we present the software’s highest-level functionality first, before lower-level details. This is an advantage over previous approaches based on topic models, that only present groups of related keywords without a hierarchy. We conducted a preliminary user study that found our approach selects keywords and topics that the participants found to be accurate in a majority of cases. 71 | 72 | * Topic modeling for code summarization task. Task of creating a brief description of a section of source code. 73 | 74 | * It uses HDTM algorithm, which analyses graph of documents. 75 | > Our technique employs the HDTM algorithm described by Weninger et. al [29] to extract a topic hierarchy for a software system, then we display the hierarchy to programmers in a navigable web interface. 76 | 77 | * We can use this approach to extract names and keywords in themes 78 | > Code summarization techniques based on topic models are described extensively in software engineering literature [19]. But as a recent study by Panichella et. al points out, these techniques often “have rather low performance when applied on software data” [19]. 79 | 80 | * [API usage pattern recommendation for software development](http://www.sciencedirect.com/science/article/pii/S0164121216301200) 81 | > Our approach represents the source code as a network of object usages where an object usage is a set of method calls invoked on a single API class. We automatically extract usage patterns by clustering the data based on the co-existence relations between object usages. We conduct an empirical study using a corpus of 11,510 Android applications. The results demonstrate that our approach can effectively mine API usage patterns with high completeness and low redundancy. We observe 18% and 38% improvement on F-measure and response time respectively comparing to usage pattern extraction using frequent-sequence mining. 82 | 83 | > Specifically, we show that our approach outperforms the baseline in mining less frequently used API usage patterns. In addition, the ranking quality of our approach is better than Codota which is an online commercial usage pattern recommendation service for Android development. 84 | 85 | * [Multimodal Code Search by Shaowei Wang](http://ink.library.smu.edu.sg/cgi/viewcontent.cgi?article=1118&context=etd_coll) 86 | > In this dissertation, we propose a multimodal code search engine, which employs novel techniques that allow developers to effectively find code elements of interest by processing developers’ inputs in various input forms including free-form texts, an SQL-like domain-specific language, code examples, execution traces, and user feedback. Our evaluations show that our approaches improve over state-of-the-art approaches significantly. 87 | 88 | It is a big work. Interesting Literature Review. I think it can be helpful. 89 | 90 | # Libs & Tools 91 | 92 | * https://libraries.io/data 93 | 94 | Can be useful to get libraries list and projects, that use specific library. 95 | -------------------------------------------------------------------------------- /presentation/article meeting.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/src-d/snippet-ranger/06247e0492d59b859fe48dea0428171b252770ef/presentation/article meeting.pdf -------------------------------------------------------------------------------- /presentation/article meeting.tex: -------------------------------------------------------------------------------- 1 | \documentclass[10pt,aspectratio=1610]{beamer} 2 | 3 | \usetheme[progressbar=frametitle,sectionpage=none,background=light]{metropolis} 4 | 5 | %%–––––––––––––––––––––––––––––––––––––––––––––––– 6 | % Define styles 7 | %%–––––––––––––––––––––––––––––––––––––––––––––––– 8 | 9 | %%–––––––––––––––––––––––––––––––––––––––––––––––– 10 | % Setting up colors 11 | \definecolor{logoblue1}{RGB}{35, 121, 181} 12 | \definecolor{logoblue2}{RGB}{88, 145, 202} 13 | \definecolor{darkblue}{RGB}{25, 41, 54} 14 | \definecolor{lightgrey}{RGB}{134, 143, 161} 15 | \definecolor{greytext}{RGB}{102, 118, 128} 16 | \definecolor{darktext}{RGB}{29, 43, 52} 17 | \definecolor{green}{RGB}{0, 184, 44} 18 | \definecolor{vividblue}{RGB}{15, 117, 183} 19 | \definecolor{orange}{RGB}{246, 177, 70} 20 | \definecolor{lightblue}{RGB}{244, 247, 251} 21 | \definecolor{white}{RGB}{255, 255, 255} 22 | \definecolor{red}{RGB}{183, 25, 29} 23 | 24 | \setbeamercolor{frametitle}{bg=darkblue, fg=lightblue} 25 | \setbeamercolor{background canvas}{bg=black} 26 | \setbeamercolor{normal text}{fg=lightblue} 27 | %%–––––––––––––––––––––––––––––––––––––––––––––––– 28 | 29 | %%–––––––––––––––––––––––––––––––––––––––––––––––– 30 | % Setting up fonts 31 | \usepackage{lato} 32 | \usepackage{roboto} 33 | \usepackage{montserrat} 34 | 35 | \setbeamerfont{frametitle}{family=\flafamily, size*={18}{18}} 36 | % \setbeamerfont{footline}{family=\fontfamily{montserrat}} 37 | % \setbeamerfont{normal text}{family=\roboto, size*={16}{18}} 38 | 39 | % Setting up fonts for bibliography style 40 | \setbeamerfont{bibliography entry author}{size=\small} 41 | \setbeamerfont{bibliography entry title}{size=\small} 42 | \setbeamerfont{bibliography entry location}{size=\small} 43 | \setbeamerfont{bibliography entry note}{size=\small} 44 | \setbeamerfont{bibliography item}{size=\small} 45 | %%–––––––––––––––––––––––––––––––––––––––––––––––– 46 | 47 | \usepackage{appendixnumberbeamer} 48 | 49 | \usepackage{booktabs} 50 | \usepackage[scale=2]{ccicons} 51 | 52 | \usepackage{pgfplots} 53 | \usepgfplotslibrary{dateplot} 54 | 55 | \usepackage{xspace} 56 | \newcommand{\themename}{\textbf{\textsc{metropolis}}\xspace} 57 | 58 | \usepackage{hyperref} 59 | \hypersetup{ 60 | colorlinks, 61 | urlcolor=vividblue, 62 | citecolor=lightblue, 63 | linkcolor=lightblue 64 | } 65 | 66 | \setbeamertemplate{frame footer}{{\large\textcolor{logoblue1}{source}\textcolor{logoblue2}{\{d\}}}} 67 | 68 | 69 | \title{Exploratory code search and snippet suggestion} 70 | \subtitle{Article review} 71 | \date{\today} 72 | \author{Slavnov Konstantin\\konstantin@sourced.tech} 73 | %\titlegraphic{\hfill\includegraphics[height=1.5cm]{logo.png}} 74 | 75 | \begin{document} 76 | 77 | \maketitle 78 | 79 | \section{Introduction} 80 | 81 | 82 | 83 | \begin{frame}[fragile]{Introduction} 84 | 85 | What is the \textbf{fastest} way to learn a new library? 86 | 87 | New framework investigation ways: 88 | \begin{itemize} 89 | \item Documentation reading; 90 | \item Ask stackoverflow; 91 | \item \alert<2>{Just start to use it;} 92 | \item \alert<2>{Search code examples;} 93 | \item etc 94 | \end{itemize} 95 | 96 | \vfill 97 | \pause 98 | \textbf{Insights} from Searching and Skimming: An Exploratory Study \cite{starke2009searching}. 99 | 100 | \end{frame} 101 | \begin{frame}[fragile]{Ways to solve} 102 | Let's build a machine learning assistant! 103 | 104 | Approaches: 105 | \begin{itemize} 106 | \item \alert<2>{Topic modeling} 107 | \item Hierarchical clustering 108 | \item Deep learning way 109 | \item Probabilistic way 110 | \end{itemize} 111 | \end{frame} 112 | 113 | 114 | \section{Approaches} 115 | 116 | \begin{frame}{Topic modeling} 117 | Scheme 118 | \begin{itemize} 119 | \item Get a codebase of library usage 120 | \item Build a hierarchical topic modeling for codebase 121 | \item Show it for user API query 122 | \item ??? 123 | \item PROFIT! 124 | \end{itemize} 125 | \end{frame} 126 | 127 | \begin{frame}{Flat topic model. Reminder} 128 | \begin{itemize} 129 | \item Documents $d \in D$ 130 | \item Tokens (words) $w \in W$ 131 | \item Topics $t \in T$ 132 | \item Document-token counters $n_{dw}$\\[3mm] 133 | \end{itemize} 134 | Flat topic model:\\[-1mm] 135 | $$ 136 | P_{wd} = \dfrac{n_{dw}}{\sum_{w' \in W} n_{dw'}} = p(w \mid d) \approx \sum_{t \in T} p(w \mid t)\, p(t \mid d) = \sum_{tin} \phi_{wt} \theta_{td} = \{\Phi \Theta\}_{wd} 137 | $$ 138 | or just 139 | $$ 140 | P \approx \Phi \Theta 141 | $$ 142 | \pause 143 | Applying MLE: 144 | $$ 145 | L(\Psi, \Theta) = \sum_{d\in D} 146 | \sum_{w \in d} n_{dw} \ln 147 | \sum_t \psi_{wt} \theta_{td} \quad 148 | \longrightarrow \max_{\Psi, \Theta \text{ -- stochastic}} 149 | $$ 150 | 151 | EM-algorithm is used for training. 152 | \end{frame} 153 | 154 | \begin{frame}{Flat topic model.} 155 | 156 | \href{http://bigartm.org}{BigARTM} is good tool for it. 157 | 158 | What we can do: 159 | \begin{itemize} 160 | \item Add regularisers: \quad 161 | $$ L(\Psi, \Theta) + R(\Psi, \Theta) 162 | \longrightarrow \max $$ 163 | \item Add modalities $m \in M$. 164 | $$W = \bigsqcup_{m \in M} W_m \text{ and } \Phi = [\Phi_1 | \cdots | \Phi_n ]$$ 165 | \end{itemize} 166 | \vspace{5mm} 167 | \pause 168 | Let's build \textbf{topic hierarchies}. 169 | \begin{itemize} 170 | \item Each level is a topic model. 171 | \item Next level is learned with \textbf{specific regulariser} to find 172 | parent topics from previous level. 173 | \end{itemize} 174 | \vspace{5mm} 175 | Check out \cite{vorontsov2014additive, vorontsov2014tutorial}. 176 | \end{frame} 177 | 178 | \begin{frame}{Topic hierarchies.} 179 | \begin{itemize} 180 | \item \textbf{Learned} parent level: topics $a \in A$ with $\Phi' \in \mathbb{R}^{|W| \times |A|} $ and $\Theta' \in \mathbb{R}^{|A| \times |D|} $. 181 | \item \textbf{To learn:} \\ 182 | \quad New level with topics $t \in T$ and $\Phi \in \mathbb{R}^{|W| \times |T|} $ and $\Theta \in \mathbb{R}^{|T| \times |D|} $.\\ 183 | \quad Parent-child relations $\Psi_{ta}$ -- $t$ is a child of $a$. 184 | \pause 185 | \item \textbf{Assumption:} parent topic is a mixture of children's: \\[2mm] 186 | \qquad\qquad 187 | $\displaystyle 188 | p(w \mid a) \approx \sum_{t \in T} \; p(w \mid t) p(t \mid a) 189 | $ 190 | \qquad or just \qquad 191 | $ 192 | \Phi^l \approx \Phi \Psi 193 | $ 194 | \pause 195 | \item We can just add $|A|$ pseudo documents with $n_{wa}$ counters 196 | \pause 197 | \item The same point with $\Theta$ regularisation. 198 | $ 199 | \Theta^l \approx \tilde \Psi \Theta 200 | $ 201 | It is like add new modality with tokens corresponding to $a \in A$. 202 | \end{itemize} 203 | 204 | \end{frame} 205 | 206 | \begin{frame}{Hierarchy sparsing} 207 | \textbf{The goal:}\quad Topics should have small number of parents. \\[5mm] 208 | 209 | $p(a \mid t)$ should be sparse. 210 | 211 | Similar to LDA regulariser: 212 | $$ 213 | R(\Psi) 214 | = \dfrac{1}{|A|} \sum_a \sum_t \ln p(a \mid t) 215 | = \dfrac{1}{|A|} \sum_a \sum_t \ln 216 | \dfrac{\psi_{ta} \; p(a)}{\sum_{a'} \psi_{ta'} \; p(a')} 217 | $$ 218 | 219 | To apply we need just to update M-step of EM-algorithm. 220 | 221 | The same approach for $\Theta$ regularisation. 222 | \end{frame} 223 | 224 | \begin{frame}{Hierarchical clustering approach} 225 | Scheme 226 | \begin{itemize} 227 | \item Get a codebase of library usage 228 | \item \alert<2>{Somehow get a document representations in $\mathbb{R}^{d}$} 229 | \item Build a hierarchical clusterization 230 | \item Show it for user API query 231 | \item ??? 232 | \item PROFIT! 233 | \end{itemize} 234 | \end{frame} 235 | 236 | \begin{frame}{DocNADE} 237 | \begin{columns}[T,onlytextwidth] 238 | \column{0.7\textwidth} 239 | \textbf{NADE} -- Neural Autoregressive Distribution Estimator \cite{larochelle2011neural}.\\[2mm] 240 | 241 | Based on fact that \qquad 242 | $ \displaystyle 243 | p(v) = 244 | \prod_{d=1}^D p(v_d \mid v_{