Skip to content

Commit

Permalink
Update docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
cschaefer26 committed Jun 22, 2021
1 parent 8194d9a commit 57444a9
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 27 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ You may look through the [GitHub issues](https://github.com/as-ideas/DeepPhonemi
- Make sure any new function or class you introduce has proper docstrings.

## Testing
- We use [pytest](https://docs.pytest.org/en/latest/) for our testing. Make sure to write tests for any new feature and/or bug fixes.
- We use [unittest](https://docs.python.org/3/library/unittest.html) for our testing. Make sure to write tests for any new feature and/or bug fixes.

## Main Contributor List
We maintain a list of main contributors to appreciate all the contributions.
2 changes: 1 addition & 1 deletion dp/model/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, d_model: int, dropout=0.1, max_len=5000) -> None:
max_len: Max length of precalculated position sequence.
"""

super(PositionalEncoding, self).__init__()
super().__init__()
self.dropout = torch.nn.Dropout(p=dropout)
self.scale = torch.nn.Parameter(torch.ones(1))

Expand Down
51 changes: 28 additions & 23 deletions dp/utils/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,84 +8,89 @@

def read_config(path: str) -> Dict[str, Any]:
"""
Reads the config dictionary from the yaml file.
Args:
path: str:
path (str): Path to the .yaml file.
Returns:
Dict[str, Any]: Configuration.
"""

with open(path, 'r') as stream:
config = yaml.load(stream, Loader=yaml.FullLoader)
return config


def save_config(config: Dict[str, Any], path: str) -> None:
"""
Saves the config as a yaml file.
Args:
config: Dict[str:
Any]:
path: str:
Returns:
config (Dict[str, Any]): Configuration.
path (str): Path to save the dictionary to (.yaml).
"""

with open(path, 'w+', encoding='utf-8') as stream:
yaml.dump(config, stream, default_flow_style=False)


def get_files(path: str, extension='.wav') -> List[Path]:
def get_files(path: str, extension: str = '.wav') -> List[Path]:
"""
Recursively retrieves all files with a given extension from a folder.
Args:
path: str:
extension: (Default value = '.wav')
path (str): Path to the folder to retrieve files from.
extension (str): Extension of files to be retrieved (Default value = '.wav').
Returns:
List[Path]: List of paths to the found files.
"""

return list(Path(path).expanduser().resolve().rglob(f'*{extension}'))


def pickle_binary(data: object, file: Union[str, Path]) -> None:
"""
Pickles a given object to a binary file.
Args:
data: object:
file: Union[str:
Path]:
Returns:
data (object): Object to be pickled.
file (Union[str, Path]): Path to destination file (use the .pkl extension).
"""

with open(str(file), 'wb') as f:
pickle.dump(data, f)


def unpickle_binary(file: Union[str, Path]) -> Any:
def unpickle_binary(file: Union[str, Path]) -> object:
"""
Unpickles a given binary file to an object
Args:
file: Union[str:
Path]:
file (nion[str, Path]): Path to the file.
Returns:
object: Unpickled object.
"""

with open(str(file), 'rb') as f:
return pickle.load(f)


def to_device(batch: Dict[str, torch.Tensor], device: torch.device) -> Dict[str, torch.Tensor]:
"""
Sends a batch of data to the given torch devicee (cpu or cuda).
Args:
batch: Dict[str:
torch.Tensor]:
device: torch.device:
batch (Dict[str, torch.Tensor]): Batch to be send to the device.
device (torch.device): Device (either torch.device('cpu') or torch.device('cuda').
Returns:
Dict[str, torch.Tensor]: The batch at the given device.
"""

return {key: val.to(device) for key, val in batch.items()}
6 changes: 4 additions & 2 deletions dp/utils/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@

def get_logger(name: str) -> Logger:
"""
Creates a logger object for a given name.
Args:
name: str:
name (str): Name of the logger.
Returns:
Logger: Logger object with given name.
"""

logger = getLogger(name)
return logger
1 change: 1 addition & 0 deletions mkdocs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ site_author: Axel Springer AI

nav:
- Home: index.md
- Contributing: CONTRIBUTING.md
- Documentation:
- Phonemizer: phonemizer.md
- Result: result.md
Expand Down

0 comments on commit 57444a9

Please sign in to comment.