Skip to main content

Python utilities used by Deep Procedural Intelligence

Project description

DPU Utilities

Build Status

This contains a set of utilities used across projects of the DPU team.

Installation

pip install dpu-utils

Overview of Utilities:

Generic Utilities:

  • dpu_utils.utils.RichPath a convenient way of using both paths and Azure paths in your code.
  • dpu_utils.utils.*Iterator iterator wrappers that can parallelize their iteration in other threads/processes.
  • dpu_utils.utils.{load,save}_json[l]_gz convenience methods for loading .json[l].gz from the filesystem.
  • dpu_utils.utils.git_tag_run that tags the current working directory git the state of the code.
  • dpu_utils.utils.run_and_debug when an exception happens, start a debug session. Usually a wrapper of __main__.
  • dpu_utils.utils.ChunkWriter that helps writing chunks to the output.

TensorFlow Utilities:

  • dpu_utils.tfutils.GradRatioLoggingOptimizer a wrapper around optimizers that logs the ratios of grad norms to parameter norms.
  • dpu_utils.tfutils.unsorted_segment_logsumexp
  • dpu_utils.tfutils.unsorted_segment_log_softmax
  • dpu_utils.tfutils.TFVariableSaver save TF variables in an object that can be pickled.

General Machine Learning Utilities:

  • dpu_utils.mlutils.CharTensorizer for character-level tensorization.
  • dpu_utils.mlutils.Vocabulary a str to int vocabulary for machine learning models

TensorFlow Models:

  • dpu_utils.tfmodels.SparseGGNN a sparse GGNN implementation.
  • dpu_utils.tfmodels.AsyncGGNN an asynchronous GGNN implementation.

Code-related Utilities

  • dpu_utils.codeutils.split_identifier_into_parts() split identifiers into subtokens on CamelCase and snake_case.
  • dpu_utils.codeutils.{Lattice, CSharpLattice} represent lattices and some useful operations in Python.
  • dpu_utils.codeutils.get_language_keywords() that retrieves the keyword tokens for many programming languages.
  • dpu_utils.codeutils.deduplication.DuplicateDetector that detects duplicates in codebases.

Command-line tools

Approximate Duplicate Code Detection

You can use the deduplicationcli command to detect duplicates in pre-processed source code, by invoking

 $ deduplicationcli DATA_PATH OUT_JSON

where DATA_PATH is a file containing tokenized .jsonl.gz files and OUT_JSON is the target output file. For more options look at --help.

An exact (but usually slower) version of this can be found here along with code to tokenize Java, C#, Python and JavaScript into the relevant formats.

Tests

Run the unit tests

python setup.py test

Generate code coverage reports

# pip install coverage
coverage run --source dpu_utils/ setup.py test && \
  coverage html

The resulting HTML file will be in htmlcov/index.html.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dpu_utils-0.1.26.tar.gz (28.2 kB view details)

Uploaded Source

Built Distribution

dpu_utils-0.1.26-py2.py3-none-any.whl (39.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file dpu_utils-0.1.26.tar.gz.

File metadata

  • Download URL: dpu_utils-0.1.26.tar.gz
  • Upload date:
  • Size: 28.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

File hashes

Hashes for dpu_utils-0.1.26.tar.gz
Algorithm Hash digest
SHA256 3f07490f216fbc4dbdbd3d9cabd73b12350c4bf5da923694a5feb6bd83cd26fe
MD5 c51107d3ed0bb29aaf9e9df7d1d3b43a
BLAKE2b-256 79415a15c1fd2020d407fdba31864867416cfdee54ab0f45a54c543482631a6b

See more details on using hashes here.

File details

Details for the file dpu_utils-0.1.26-py2.py3-none-any.whl.

File metadata

  • Download URL: dpu_utils-0.1.26-py2.py3-none-any.whl
  • Upload date:
  • Size: 39.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

File hashes

Hashes for dpu_utils-0.1.26-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e9867d29b80e1f7abd4ab79e9e8fe8db4da9d4620e474186de005fa4771b98f2
MD5 e853cce485ccd51f41a75bd7348926bf
BLAKE2b-256 a4f24eee35d98017b7028c1e8e4eae12fadbfc453028df326a27bc6a5f56ed33

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page