Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

__init__.py 1.6 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  1. # Copyright (c) 2022, NVIDIA CORPORATION.
  2. # SPDX-License-Identifier: Apache-2.0
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from pathlib import Path
  15. from collections import defaultdict
  16. from dataclasses import asdict
  17. from nemo.utils import logging
  18. def update_dataclass_config(cfg, dataset_config_class):
  19. """Update a dataset configuration with existing defaults"""
  20. default_cfg = asdict(dataset_config_class())
  21. default_cfg.update(cfg)
  22. return default_cfg
  23. def recursive_make_dirs(directory):
  24. """Recursively create required directory structure"""
  25. logging.info(f'Creating directory {str(directory)}...')
  26. if isinstance(directory, str):
  27. directory = Path(directory)
  28. directory.mkdir(parents=True, exist_ok=True)
  29. def flatten_dict(list_of_dicts):
  30. """Flatten a list of dictionaries to list without assuming all keys are identical"""
  31. flattened_dict = defaultdict(list)
  32. for metric_dict in list_of_dicts:
  33. for metric_name, metric_value in metric_dict.items():
  34. flattened_dict[metric_name].append(metric_value)
  35. return flattened_dict
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...