instruction
stringclasses
100 values
code
stringlengths
78
193k
response
stringlengths
259
170k
file
stringlengths
59
203
Write docstrings for backend logic
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +r"""Parameter sets for training of model-based RL agents.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function @@ -135,6 +136...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/rl/trainer_model_based_params.py
Generate documentation strings for clarity
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Basic recurrent models for testing simple tasks.""" from __future__ import absolute_import from __future__ import division @@ -26,6 +27,7 @@ @registry.register_model class NextFra...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/models/video/basic_recurrent.py
Improve my code by adding docstrings
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Utilities for RL training.""" from __future__ import absolute_import from __future__ import division @@ -43,6 +44,7 @@ def compute_mean_reward(rollouts, clipped): + """Calcula...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/rl/rl_utils.py
Generate NumPy-style docstrings
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Param sets for deterministic basic next frame prediction model.""" from __future__ import division from __future__ import print_function @@ -24,6 +25,7 @@ @registry.register_hpar...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/models/video/basic_deterministic_params.py
Create structured documentation for my script
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,16 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Model architecture for video prediction model. + + based on following paper: + "Stochastic Video Generation with a Learned Prior" + https://arxiv.org/pdf/1802.07687.pdf + by E...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/models/video/emily.py
Add inline docstrings for readability
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Resnets.""" # Copied from cloud_tpu/models/resnet/resnet_model.py and modified from __future__ import absolute_import @@ -43,6 +44,20 @@ relu=True, ...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/models/resnet.py
Add inline docstrings for readability
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Utilities for interacting with Gym classes.""" from __future__ import absolute_import from __future__ import division @@ -28,6 +29,7 @@ class StickyActionEnv(gym.Wrapper): + "...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/rl/gym_utils.py
Create structured documentation for my script
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,16 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Model architecture for video prediction model. + +based on following paper: +"Hierarchical Long-term Video Prediction without Supervision" +http://web.eecs.umich.edu/~honglak/icml2018...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/models/video/epva.py
Add docstrings to clarify complex logic
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Utilities for player.py.""" from __future__ import absolute_import from __future__ import division @@ -42,9 +43,35 @@ class SimulatedGymEnv(gym.Env): + """Gym environment, run...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/rl/player_utils.py
Add docstrings for utility scripts
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,26 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Creates a RevNet with the bottleneck residual function. + +Implements the following equations described in the RevNet paper: +y1 = x1 + f(x2) +y2 = x2 + g(y1) + +However, in practice,...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/models/revnet.py
Help me write clear docstrings
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Connects dopamine to as the another rl traning framework.""" from __future__ import absolute_import from __future__ import division @@ -62,6 +63,11 @@ class _DQNAgent(dqn_agent...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/rl/dopamine_connector.py
Write docstrings for utility functions
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""PPO algorithm implementation. + +Based on: https://arxiv.org/abs/1707.06347 +""" from __future__ import absolute_import from __future__ import division from __future__ import print...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/rl/ppo.py
Add standardized docstrings across the file
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Basic models for testing simple tasks.""" from __future__ import absolute_import from __future__ import division @@ -39,8 +40,10 @@ class NextFrameBasicStochastic( basic_deter...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/models/video/basic_stochastic.py
Write docstrings describing each step
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Export a trained model for serving.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function @@ -50,6 +51,7 @@ def _get_hp...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/serving/export.py
Provide docstrings following PEP 257
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Attention models for VQA.""" from __future__ import absolute_import from __future__ import division @@ -38,6 +39,7 @@ @registry.register_model class VqaAttentionBaseline(t2t_mod...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/models/research/vqa_attention.py
Generate documentation strings for clarity
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Query an exported model. Py2 only. Install tensorflow-serving-api.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function @@...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/serving/query.py
Write docstrings describing functionality
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Experimental testbed for nfg.""" from __future__ import absolute_import from __future__ import division @@ -35,6 +36,7 @@ @registry.register_hparams def next_frame_glow_hparams(...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/models/video/next_frame_glow.py
Annotate my code with docstrings
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Utilities to assist in performing adversarial attack using Cleverhans.""" from cleverhans import attacks from cleverhans import model @@ -41,6 +42,7 @@ class T2TAttackModel(mod...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/utils/adv_attack_utils.py
Generate NumPy-style docstrings
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,15 @@ # See the License for the specific language governing permissions and # limitations under the License. +r"""Training of model-based RL agents. + +Example invocation: + +python -m tensor2tensor.rl.trainer_model_based \ + --output_dir=$HOME/t2t/rl_v1 \ + --loop_hparams_set=rlmb_base \ ...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/rl/trainer_model_based.py
Provide clean and structured docstrings
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Utilities for serving tensor2tensor.""" from __future__ import absolute_import from __future__ import division @@ -36,6 +37,20 @@ def _make_example(input_ids, problem, input_fe...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/serving/serving_utils.py
Write reusable docstrings
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,16 @@ # See the License for the specific language governing permissions and # limitations under the License. +r"""Evaluation script for RL agents. + +Example invocation: + +python -m tensor2tensor.rl.evaluator \ + --policy_dir=$HOME/t2t/rl_v1/policy \ + --eval_metrics_dir=$HOME/t2t/rl_v1/f...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/rl/evaluator.py
Add verbose docstrings with examples
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Launch on GCP's ML Engine.""" import datetime import os @@ -90,6 +91,7 @@ def flags_as_args(): + """Convert FLAGS to list of args suitable for passing on cmd line.""" if ha...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/utils/cloud_mlengine.py
Generate consistent documentation across files
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Restore hooks.""" from __future__ import absolute_import from __future__ import division @@ -25,6 +26,7 @@ class RestoreHook(tf.train.SessionRunHook): + """Restore variables f...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/utils/restore_hook.py
Add docstrings explaining edge cases
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -14,6 +14,11 @@ # limitations under the License. # coding=utf-8 +"""ROUGE metric implementation. + +This is a modified and slightly extended version of +https://github.com/miso-belica/sumy/blob/dev/sumy/evaluation/rouge.py. +""" from __future__ import absolute_import from __future__ import division @@...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/utils/rouge.py
Document functions with clear intent
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Data reader module.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function @@ -68,6 +69,7 @@ def _bucket_boundaries(max_...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/utils/data_reader.py
Add inline docstrings for readability
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Decoding utilities.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function @@ -46,6 +47,7 @@ def decode_hparams(override...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/utils/decoding.py
Document this module using docstrings
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Utils for metrics used in eval.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function @@ -32,6 +33,7 @@ class Metrics(o...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/utils/metrics.py
Add well-formatted docstrings
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,15 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Multi-step optimizers simulating large batches. + +Optimizer variants which make it possible to use very large batch sizes with +limited GPU memory. Optimizers in this module accumula...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/utils/multistep_optimizer.py
Generate consistent documentation across files
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""BLEU metric util used during eval for MT.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function @@ -37,6 +38,17 @@ def ...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/utils/bleu_hook.py
Generate docstrings for script automation
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Utility to load code from an external user-supplied directory.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function @@ -27...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/utils/usr_dir.py
Write beginner-friendly docstrings
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Implementation of beam search with penalties.""" from __future__ import absolute_import from __future__ import division @@ -34,6 +35,14 @@ def _merge_beam_dim(tensor): + """Re...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/utils/beam_search.py
Add docstrings with type hints explained
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Optimization.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function @@ -34,6 +35,7 @@ def _mixed_precision_is_enabled(h...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/utils/optimize.py
Add docstrings to existing functions
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Utilities related to using bfloat16 activations and/or parameters.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function @@...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/utils/quantization.py
Write documentation strings for class attributes
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,11 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Utilities for creating Sparsely-Gated Mixture-of-Experts Layers. + +See "Outrageously Large Neural Networks" +https://arxiv.org/abs/1701.06538 +""" from __future__ import absolute_...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/utils/expert_utils.py
Create Google-style docstrings for my code
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,14 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Diet variables are much more memory-efficient than regular variables. + +Using diet variables, we can reduce memory overhead per parameter from +16 bytes to 2 bytes, allowing for up t...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/utils/diet.py
Write reusable docstrings
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,55 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Object registration. + +Registries are instances of `Registry`. + +See `Registries` for a centralized list of object registries +(models, problems, hyperparameter sets, etc.). + +New ...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/utils/registry.py
Write docstrings for data processing functions
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Module for postprocessing and displaying transformer attentions. + +This module is designed to be called from an ipython notebook. +""" import json import os @@ -56,6 +60,7 @@ ...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/visualization/attention.py
Add docstrings for internal functions
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Summary-based SessionRunHooks.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function @@ -25,9 +26,29 @@ class MetricsBa...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/utils/metrics_hook.py
Write docstrings for data processing functions
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,24 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""SARI score for evaluating paraphrasing and other text generation models. + +The score is introduced in the following paper: + + Optimizing Statistical Machine Translation for Text S...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/utils/sari_hook.py
Create docstrings for each class method
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -26,6 +26,15 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +"""Multi-step optimizers simulating large batches. + +Optimizer variants which make it possible to use very larg...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/utils/multistep_with_adamoptimizer.py
Add docstrings following best practices
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Device placement and data parallelism.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function @@ -23,6 +24,25 @@ def dat...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/utils/devices.py
Create structured documentation for my script
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. from __future__ import (absolute_import, division, print_function) import ranger from ranger.core.linemode import LinemodeBase __all__ = ['ranger', 'LinemodeBase', 'hook_init', 'hook_ready', '...
--- +++ @@ -1,6 +1,7 @@ # This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. +"""Files in this module contain helper functions used in configuration files.""" from __future__ import (absolute_import, division, print_function) @@ -13,12 +14,34...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/api/__init__.py
Help me comply with documentation standards
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,21 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Scheduled Sampling. + +This module implemented scheduled sampling as described in (Bengio et al, 2015). +The entry points are two functions, + +`sequential_scheduled_sampling_for_t2tm...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/utils/scheduled_sampling.py
Generate NumPy-style docstrings
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Optimization.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function @@ -23,6 +24,7 @@ def learning_rate_factor(name, st...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/utils/learning_rate.py
Generate docstrings for each module
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""T2TModel Base Class.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function @@ -63,6 +64,18 @@ def _flatten_dict(origina...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/utils/t2t_model.py
Add minimal docstrings for each function
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -14,6 +14,7 @@ # limitations under the License. # Forked with minor changes from https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/training/python/training/hparam.py pylint: disable=line-too-long +"""Hyperparameter values.""" from __future__ import absolute_import from __future__ ...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/utils/hparam.py
Document this code for team use
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""T2T HParams handling.""" from __future__ import absolute_import from __future__ import division @@ -43,6 +44,7 @@ data_dir=None, problem_name...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/utils/hparams_lib.py
Add docstrings explaining edge cases
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Library for training. See t2t_trainer.py.""" from __future__ import absolute_import from __future__ import division @@ -46,6 +47,15 @@ def next_checkpoint(model_dir, timeout_mi...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/utils/trainer_lib.py
Generate docstrings for exported functions
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Computes the metrics for video prediction and generation.""" from __future__ import absolute_import from __future__ import division @@ -35,6 +36,20 @@ def load_videos(template,...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/utils/video_metrics.py
Improve my code by adding docstrings
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Hook to partially load a checkpoint.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function @@ -21,8 +22,24 @@ class Par...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/utils/partial_checkpoint_load_hook.py
Write docstrings for data processing functions
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Utilities to assist in pruning models.""" import numpy as np @@ -24,6 +25,7 @@ @registry.register_pruning_strategy def weight(w, sparsity): + """Weight-level magnitude pruning...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/utils/pruning_utils.py
Add detailed docstrings explaining each function
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. # TODO: Add an optional "!" to all commands and set a flag if it's there from __future__ import (absolute_import, division, print_function) import os import re import ranger from ranger import ...
--- +++ @@ -95,6 +95,7 @@ class Command(FileManagerAware): + """Abstract command class""" name = None allow_abbrev = True resolve_macros = True @@ -124,21 +125,27 @@ return cls.__name__ def execute(self): + """Override this""" def tab(self, tabnum): + """Overrid...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/api/commands.py
Add docstrings including usage examples
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""YellowFin for TensorFlow. Thanks Jian Zhang: zjian [@] stanford [.] edu.""" from __future__ import absolute_import from __future__ import division @@ -27,6 +28,10 @@ class Yell...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/utils/yellowfin.py
Expand my code with proper documentation strings
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Wrappers around tf.contrib to dynamically import contrib packages. + +This makes sure that libraries depending on T2T and TF2, do not crash at import. +""" from __future__ import a...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/utils/contrib.py
Add docstrings with type hints explained
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Shared code for visualizing transformer attentions.""" from __future__ import absolute_import from __future__ import division @@ -32,6 +33,7 @@ class AttentionVisualizer(object...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/visualization/visualization.py
Add docstrings to meet PEP guidelines
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -27,6 +27,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================== +"""Convenience function for logging compliance tags to stdout. +""" from __future__ import absolute_impo...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/utils/mlperf_log.py
Replace inline comments with docstrings
# coding=utf-8 # Copyright 2023 The Tensor2Tensor Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Mesh-Tensorflow Model in tensor2tensor.""" from __future__ import absolute_import @@ -34,6 +35,7 @@ class MtfModel(t2t_model.T2TModel): + """Toy model to test mesh_tensorflow...
https://raw.githubusercontent.com/tensorflow/tensor2tensor/HEAD/tensor2tensor/utils/mtf_model.py
Add professional docstrings to my codebase
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. from __future__ import (absolute_import, division, print_function) import string import re import os from io import open from ranger import PY3 from ranger.container import fsobject from ranger....
--- +++ @@ -16,6 +16,16 @@ class Bookmarks(FileManagerAware): + """Bookmarks is a container which associates keys with bookmarks. + + A key is a string with: len(key) == 1 and key in ALLOWED_KEYS. + + A bookmark is an object with: bookmark == bookmarktype(str(instance)) + Which is true for str or FileSy...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/container/bookmarks.py
Write docstrings for data processing functions
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. from __future__ import (absolute_import, division, print_function) import errno import os.path import select from collections import deque from io import open from subprocess import Popen, PIPE f...
--- +++ @@ -160,6 +160,12 @@ class CommandLoader( # pylint: disable=too-many-instance-attributes Loadable, SignalDispatcher, FileManagerAware): + """Run an external command with the loader. + + Output from stderr will be reported. Ensure that the process doesn't + ever ask for input, otherwise the...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/core/loader.py
Add return value explanations in docstrings
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. from __future__ import (absolute_import, division, print_function) import curses import signal _do_catch_interrupt = True # pylint: disable=invalid-name def catch_interrupt(boolean=True): ...
--- +++ @@ -1,6 +1,12 @@ # This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. +"""Interrupt Signal handler for curses + +This module can catch interrupt signals which would otherwise +rise a KeyboardInterrupt exception and handle it by pushing +a ...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/ext/curses_interrupt_handler.py
Add docstrings to improve code quality
# -*- coding: utf-8 -*- # This file is part of ranger, the console file manager. # This configuration file is licensed under the same terms as ranger. # =================================================================== # # NOTE: If you copied this file to /etc/ranger/commands_full.py or # ~/.config/ranger/commands_fu...
--- +++ @@ -103,6 +103,10 @@ class alias(Command): + """:alias <newcommand> <oldcommand> + + Copies the oldcommand as newcommand. + """ context = 'browser' resolve_macros = False @@ -116,12 +120,23 @@ class echo(Command): + """:echo <text> + + Display the text in the statusbar. + "...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/config/commands.py
Add well-formatted docstrings
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. from __future__ import (absolute_import, division, print_function) from os import listdir, environ, stat import platform import shlex from stat import S_IXOTH, S_IFREG from ranger.ext.iter_tools...
--- +++ @@ -15,6 +15,7 @@ def get_executables(): + """Return all executable files in $PATH. Cached version.""" global _cached_executables # pylint: disable=global-statement,invalid-name if _cached_executables is None: _cached_executables = get_executables_uncached() @@ -29,6 +30,10 @@ def...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/ext/get_executables.py
Generate consistent docstrings
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. # pylint: disable=too-many-lines,attribute-defined-outside-init from __future__ import (absolute_import, division, print_function) import codecs import os import re import shlex import shutil im...
--- +++ @@ -41,6 +41,7 @@ class _MacroTemplate(string.Template): + """A template for substituting macros in commands""" delimiter = ranger.MACRO_DELIMITER idpattern = r"[_a-z0-9]*" @@ -54,9 +55,17 @@ @staticmethod def exit(): + """:exit + + Exit the program. + """ ...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/core/actions.py
Add docstrings to improve readability
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. from __future__ import (absolute_import, division, print_function) import mimetypes import os.path import os import pwd import signal import socket import stat import sys from collections import...
--- +++ @@ -1,6 +1,7 @@ # This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. +"""The File Manager, putting the pieces together""" from __future__ import (absolute_import, division, print_function) @@ -85,6 +86,7 @@ _visual_move_cycles = N...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/core/fm.py
Annotate my code with docstrings
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. from __future__ import (absolute_import, division, print_function) from datetime import datetime from ranger.core.shared import SettingsAware def human_readable(byte_count, separator=' ', use_...
--- +++ @@ -9,6 +9,23 @@ def human_readable(byte_count, separator=' ', use_binary=None): + """Convert a large number of bytes to an easily readable format. + Output depends on the binary_size_prefix setting (which is False by default) + and on the use_binary argument. The latter has priority over the forme...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/ext/human_readable.py
Create documentation strings for testing functions
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. from __future__ import (absolute_import, division, print_function) import sys import copy import curses.ascii from ranger import PY3 digits = set(range(ord('0'), ord('9') + 1)) # pylint: disab...
--- +++ @@ -74,6 +74,21 @@ def parse_keybinding(obj): # pylint: disable=too-many-branches + """Translate a keybinding to a sequence of integers + + >>> tuple(parse_keybinding("lol<CR>")) + (108, 111, 108, 10) + + >>> out = tuple(parse_keybinding("x<A-Left>")) + >>> out # it's kind of dumb that you ...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/ext/keybinding_parser.py
Add docstrings for internal functions
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. from __future__ import (absolute_import, division, print_function) class FileManagerAware(object): # pylint: disable=too-few-public-methods @staticmethod def fm_set(fm): FileMa...
--- +++ @@ -1,17 +1,20 @@ # This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. +"""Shared objects contain singletons for shared use.""" from __future__ import (absolute_import, division, print_function) class FileManagerAware(object): # p...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/core/shared.py
Add well-formatted docstrings
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. from __future__ import (absolute_import, division, print_function) import math class Direction(dict): def __init__(self, dictionary=None, **keywords): if dictionary is not None: ...
--- +++ @@ -1,6 +1,22 @@ # This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. +"""This class provides convenient methods for movement operations. + +Direction objects are handled just like dicts but provide +methods like up() and down() which give...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/ext/direction.py
Fill in missing docstrings in my code
from __future__ import (absolute_import, division, print_function) import logging from collections import deque class QueueHandler(logging.Handler): def __init__(self, queue): logging.Handler.__init__(self) self.queue = queue def enqueue(self, record): self.queue.append(record) ...
--- +++ @@ -5,12 +5,21 @@ class QueueHandler(logging.Handler): + """ + This handler store logs events into a queue. + """ def __init__(self, queue): + """ + Initialize an instance, using the passed queue. + """ logging.Handler.__init__(self) self.queue = queue ...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/ext/logutils.py
Expand my code with proper documentation strings
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. from __future__ import (absolute_import, division, print_function) import atexit import locale import os.path import shutil import sys import tempfile import urllib from io import open from logg...
--- +++ @@ -1,6 +1,7 @@ # This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. +"""The main function responsible to initialize the FM object and stuff.""" from __future__ import (absolute_import, division, print_function) @@ -30,6 +31,7 @@ ...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/core/main.py
Add docstrings following best practices
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. from __future__ import (absolute_import, division, print_function) import os from os.path import abspath, normpath, join, expanduser, isdir, dirname from ranger import PY3 from ranger.container ...
--- +++ @@ -77,6 +77,12 @@ pointer = property(_get_pointer, _set_pointer) def at_level(self, level): + """Returns the FileSystemObject at the given level. + + level >0 => previews + level 0 => current file/directory + level <0 => parent directories + """ if level <...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/core/tab.py
Add professional docstrings to my codebase
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. from __future__ import (absolute_import, division, print_function) import re from grp import getgrgid from os import lstat, stat from os.path import abspath, basename, dirname, realpath, relpath,...
--- +++ @@ -206,14 +206,17 @@ "%s = lazy_property(lambda self: self.set_mimetype() or self.%s)" % (attr, attr)) def __str__(self): + """returns a string containing the absolute path""" return str(self.path) def use(self): + """Used in garbage-collecting. Override in Dir...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/container/fsobject.py
Generate missing documentation strings
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. # Author: Emanuel Guevel, 2013 # Author: Delisa Mason, 2015 from __future__ import (absolute_import, division, print_function) import base64 import curses import errno import fcntl import os imp...
--- +++ @@ -3,6 +3,11 @@ # Author: Emanuel Guevel, 2013 # Author: Delisa Mason, 2015 +"""Interface for drawing images into the console + +This module provides functions to draw images in the terminal using supported +implementations. +""" from __future__ import (absolute_import, division, print_function) @@ -54...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/ext/img_display.py
Create documentation strings for testing functions
# -*- coding: utf-8 -*- # This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. # Author: Wojciech Siewierski <wojciech.siewierski@onet.pl>, 2015 from __future__ import (absolute_import, division, print_function) from abc import abstractproperty, abst...
--- +++ @@ -17,6 +17,17 @@ class LinemodeBase(ABC): + """Supplies the file line contents for BrowserColumn. + + Attributes: + name (required!) - Name by which the linemode is referred to by the user + + uses_metadata - True if metadata should to be loaded for this linemode + + required_me...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/core/linemode.py
Add structured docstrings to improve clarity
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. # Author: David Barnett <davidbarnett2@gmail.com>, 2010 from __future__ import (absolute_import, division, print_function) import re from ranger.ext.widestring import WideString from ranger.gui...
--- +++ @@ -2,6 +2,7 @@ # License: GNU GPL version 3, see the file "AUTHORS" for details. # Author: David Barnett <davidbarnett2@gmail.com>, 2010 +"""A library to help to convert ANSI codes to curses instructions.""" from __future__ import (absolute_import, division, print_function) @@ -108,6 +109,19 @@ def...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/gui/ansi.py
Create docstrings for all classes and functions
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. from __future__ import (absolute_import, division, print_function) from collections import deque def flatten(lst): for elem in lst: if isinstance(elem, (tuple, list, set, deque)): ...
--- +++ @@ -7,6 +7,17 @@ def flatten(lst): + """Flatten an iterable. + + All contained tuples, lists, deques and sets are replaced by their + elements and flattened as well. + + >>> l = [1, 2, [3, [4], [5, 6]], 7] + >>> list(flatten(l)) + [1, 2, 3, 4, 5, 6, 7] + >>> list(flatten(())) + [] + ...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/ext/iter_tools.py
Document functions with detailed explanations
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. from __future__ import (absolute_import, division, print_function) import logging import os import sys from io import open from subprocess import PIPE, STDOUT from ranger.ext.get_executables im...
--- +++ @@ -1,6 +1,26 @@ # This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. +"""This module is an abstract layer over subprocess.Popen + +It gives you highlevel control about how processes are run. + +Example: +run = Runner(logfunc=print) +run('...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/core/runner.py
Document this script properly
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. from __future__ import (absolute_import, division, print_function) import locale import os.path from os import stat as os_stat, lstat as os_lstat import random import re from collections import d...
--- +++ @@ -25,14 +25,17 @@ def sort_by_basename(path): + """returns path.relative_path (for sorting)""" return path.relative_path def sort_by_basename_icase(path): + """returns case-insensitive path.relative_path (for sorting)""" return path.relative_path_lower def sort_by_directory(path)...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/container/directory.py
Fully document this Python code with docstrings
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. from __future__ import (absolute_import, division, print_function) import curses from ranger.core.shared import FileManagerAware from ranger.gui.curses_shortcuts import CursesShortcuts try: ...
--- +++ @@ -17,6 +17,39 @@ class Displayable( # pylint: disable=too-many-instance-attributes FileManagerAware, CursesShortcuts): + """Displayables are objects which are displayed on the screen. + + This is just the abstract class, defining basic operations + such as resizing, printing, changing col...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/gui/displayable.py
Write proper docstrings for these functions
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. from __future__ import (absolute_import, division, print_function) import os.path from abc import abstractmethod from curses import color_pair from io import open import ranger from ranger.gui....
--- +++ @@ -1,6 +1,28 @@ # This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. +"""Colorschemes define colors for specific contexts. + +Generally, this works by passing a set of keywords (strings) to +the colorscheme.get() method to receive the tup...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/gui/colorscheme.py
Write docstrings that follow conventions
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. from __future__ import (absolute_import, division, print_function) import curses DEFAULT_FOREGROUND = curses.COLOR_WHITE DEFAULT_BACKGROUND = curses.COLOR_BLACK # Color pair 0 is wired to white...
--- +++ @@ -1,6 +1,17 @@ # This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. +"""Contains abbreviations to curses color/attribute constants. + +Multiple attributes can be combined with the | (or) operator, toggled +with ^ (xor) and checked for wi...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/gui/color.py
Add docstrings for internal functions
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. from __future__ import (absolute_import, division, print_function) import sys import curses from ranger.gui.color import get_color from ranger.core.shared import SettingsAware REVERSE_ADDCH_ARG...
--- +++ @@ -18,6 +18,14 @@ class CursesShortcuts(SettingsAware): + """This class defines shortcuts to facilitate operations with curses. + + color(*keys) -- sets the color associated with the keys from + the current colorscheme. + color_at(y, x, wid, *keys) -- sets the color at the given position + ...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/gui/curses_shortcuts.py
Add docstrings to incomplete code
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. from __future__ import (absolute_import, division, print_function) import os import sys import threading import curses from subprocess import CalledProcessError from ranger.ext.get_executables i...
--- +++ @@ -102,6 +102,7 @@ DisplayableContainer.__init__(self, None) def initialize(self): + """initialize curses, then call setup (at the first time) and resize.""" self.win.leaveok(0) self.win.keypad(1) self.load_mode = False @@ -140,6 +141,7 @@ self.vcsth...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/gui/ui.py
Add docstrings to make code maintainable
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. from __future__ import (absolute_import, division, print_function) import curses class MouseEvent(object): PRESSED = [ 0, curses.BUTTON1_PRESSED, curses.BUTTON2_PRES...
--- +++ @@ -17,6 +17,7 @@ CTRL_SCROLLWHEEL_MULTIPLIER = 5 def __init__(self, getmouse): + """Creates a MouseEvent object from the result of win.getmouse()""" _, self.x, self.y, _, self.bstate = getmouse # x-values above ~220 suddenly became negative, apparently @@ -28,12 +29,14 @@ ...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/gui/mouse_event.py
Add verbose docstrings with examples
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. from __future__ import (absolute_import, division, print_function) from datetime import datetime import os import re from .vcs import Vcs, VcsError class Bzr(Vcs): HEAD = 'last:1' _s...
--- +++ @@ -1,6 +1,7 @@ # This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. +"""GNU Bazaar module""" from __future__ import (absolute_import, division, print_function) @@ -12,6 +13,7 @@ class Bzr(Vcs): + """VCS implementation for GNU ...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/ext/vcs/bzr.py
Improve documentation using docstrings
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. from __future__ import (absolute_import, division, print_function) from io import open from os import devnull from subprocess import PIPE, CalledProcessError from ranger.ext.popen23 import Popen...
--- +++ @@ -13,6 +13,19 @@ def check_output(popenargs, **kwargs): + """Runs a program, waits for its termination and returns its output + + This function is functionally identical to python 2.7's subprocess.check_output, + but is favored due to python 2.6 compatibility. + + Will be run through a shell i...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/ext/spawn.py
Document this module using docstrings
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. from __future__ import (absolute_import, division, print_function) from datetime import datetime import os from xml.etree import ElementTree as etree from .vcs import Vcs, VcsError class SVN(...
--- +++ @@ -1,6 +1,7 @@ # This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. +"""Subversion module""" from __future__ import (absolute_import, division, print_function) @@ -12,6 +13,7 @@ class SVN(Vcs): + """VCS implementation for Subv...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/ext/vcs/svn.py
Write reusable docstrings
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. from __future__ import (absolute_import, division, print_function) import weakref from types import MethodType class Signal(dict): stopped = False def __init__(self, **keywords): ...
--- +++ @@ -1,6 +1,68 @@ # This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. +"""An efficient and minimalistic signaling/hook module. + +To use this in a class, subclass SignalDispatcher and call +SignalDispatcher.__init__(self) in the __init__ f...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/ext/signals.py
Add docstrings that explain inputs and outputs
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. from __future__ import (absolute_import, division, print_function) import curses from ranger.ext.keybinding_parser import key_to_string from . import Widget from ..displayable import Displayable...
--- +++ @@ -1,6 +1,7 @@ # This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. +"""The base GUI element for views on the directory""" from __future__ import (absolute_import, division, print_function) @@ -124,6 +125,10 @@ populate_hints...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/gui/widgets/view_base.py
Write docstrings including parameters and return values
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. from __future__ import (absolute_import, division, print_function) import curses import os import re from collections import deque from io import open from ranger import PY3 from ranger.gui.wid...
--- +++ @@ -1,6 +1,7 @@ # This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. +"""The Console widget implements a vim-like console""" from __future__ import (absolute_import, division, print_function) @@ -319,6 +320,33 @@ @staticmethod ...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/gui/widgets/console.py
Improve my code by adding docstrings
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. from __future__ import (absolute_import, division, print_function) from datetime import datetime import os import re import unicodedata from .vcs import Vcs, VcsError def string_control_repla...
--- +++ @@ -1,6 +1,7 @@ # This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. +"""Git module""" from __future__ import (absolute_import, division, print_function) @@ -13,11 +14,13 @@ def string_control_replace(string, replacement): + ""...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/ext/vcs/git.py
Generate documentation strings for clarity
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. from __future__ import (absolute_import, division, print_function) import curses from ranger.container import settings from ranger.gui.widgets.view_base import ViewBase from .browsercolumn impo...
--- +++ @@ -1,6 +1,7 @@ # This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. +"""ViewMiller arranges the view in miller columns""" from __future__ import (absolute_import, division, print_function) @@ -205,6 +206,7 @@ return result ...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/gui/widgets/view_miller.py
Improve documentation using docstrings
# This file was taken from the python 2.7.13 standard library and has been # slightly modified to do a "yield" after every 16KB of copying from __future__ import (absolute_import, division, print_function) import os import stat import sys from shutil import (_samefile, rmtree, _basename, _destinsrc, Error, SpecialFil...
--- +++ @@ -17,6 +17,7 @@ if sys.version_info < (3, 3): def copystat(src, dst): + """Copy all stat info (mode bits, atime, mtime, flags) from src to dst""" st = os.stat(src) # pylint: disable=invalid-name mode = stat.S_IMODE(st.st_mode) if hasattr(os, 'utime'): @@ -38,6 +39,12 ...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/ext/shutil_generatorized.py
Help me write clear docstrings
# -*- encoding: utf-8 -*- # This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. from __future__ import (absolute_import, division, print_function) import sys from unicodedata import east_asian_width from ranger import PY3 ASCIIONLY = set(chr(c) fo...
--- +++ @@ -16,18 +16,21 @@ def uwid(string): + """Return the width of a string""" if not PY3: string = string.decode('utf-8', 'ignore') return sum(utf_char_width(c) for c in string) def utf_char_width(string): + """Return the width of a single character""" if east_asian_width(str...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/ext/widestring.py
Create simple docstrings for beginners
#!/usr/bin/python # This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. from __future__ import (absolute_import, division, print_function) from contextlib import contextmanager import os.path import re import shlex from subprocess import CalledProc...
--- +++ @@ -2,6 +2,17 @@ # This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. +"""rifle, the file executor/opener of ranger + +This can be used as a standalone program or can be embedded in python code. +When used together with ranger, it doesn't ...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/ext/rifle.py
Generate docstrings with parameter types
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. from __future__ import (absolute_import, division, print_function) import os import subprocess import threading import time from io import open from ranger.ext import spawn # Python 2 compatib...
--- +++ @@ -1,6 +1,7 @@ # This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. +"""VCS module""" from __future__ import (absolute_import, division, print_function) @@ -20,9 +21,22 @@ class VcsError(Exception): + """VCS exception""" ...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/ext/vcs/vcs.py
Add docstrings for production code
# -*- encoding: utf-8 -*- # This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. from __future__ import absolute_import import os import signal from contextlib import contextmanager @contextmanager def handle_signal(signum, handler): if handler...
--- +++ @@ -11,6 +11,8 @@ @contextmanager def handle_signal(signum, handler): + """Register a signal handler, + which will be active for the duration of the block""" if handler is None: # None handlers refer to C functions and can't be installed from Python raise ValueError("Can't instal...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/ext/posix_signals.py
Create simple docstrings for beginners
# This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. from __future__ import (absolute_import, division, print_function) import curses import stat from time import time from os.path import splitext from ranger.ext.widestring import WideString from...
--- +++ @@ -1,6 +1,7 @@ # This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. +"""The BrowserColumn widget displays the contents of a directory or file.""" from __future__ import (absolute_import, division, print_function) @@ -34,6 +35,15 @@ ...
https://raw.githubusercontent.com/ranger/ranger/HEAD/ranger/gui/widgets/browsercolumn.py
Document this module using docstrings
#!/usr/bin/env python # -*- encoding: utf-8 -*- # vim: set et sw=4 ts=4 sts=4 ff=unix fenc=utf8: # Author: Binux<roy@binux.me> # http://binux.me # Created on 2014-12-14 09:07:11 from requests.cookies import MockRequest class MockResponse(object): def __init__(self, headers): self._headers = head...
--- +++ @@ -17,9 +17,11 @@ return self def getheaders(self, name): + """make cookie python 2 version use this method to get cookie list""" return self._headers.get_list(name) def get_all(self, name, default=None): + """make cookie python 3 version use this instead of gethead...
https://raw.githubusercontent.com/binux/pyspider/HEAD/pyspider/fetcher/cookie_utils.py
Generate consistent docstrings
#!/usr/bin/env python # -*- encoding: utf-8 -*- # vim: set et sw=4 ts=4 sts=4 ff=unix fenc=utf8: # Author: Binux<i@binux.me> # http://binux.me # Created on 2012-11-02 11:16:02 import cgi import re import six import json import chardet import lxml.html import lxml.etree from tblib import Traceback from pyquery ...
--- +++ @@ -41,13 +41,16 @@ return u'<Response [%d]>' % self.status_code def __bool__(self): + """Returns true if `status_code` is 200 and no error""" return self.ok def __nonzero__(self): + """Returns true if `status_code` is 200 and no error.""" return self.ok ...
https://raw.githubusercontent.com/binux/pyspider/HEAD/pyspider/libs/response.py