Spaces:
Sleeping
Sleeping
Delete data_loader_factory.py
Browse files- data_loader_factory.py +0 -58
data_loader_factory.py
DELETED
|
@@ -1,58 +0,0 @@
|
|
| 1 |
-
# Copyright 2024 The TensorFlow Authors. All Rights Reserved.
|
| 2 |
-
#
|
| 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 |
-
|
| 15 |
-
"""A global factory to access NLP registered data loaders."""
|
| 16 |
-
|
| 17 |
-
from official.core import registry
|
| 18 |
-
|
| 19 |
-
_REGISTERED_DATA_LOADER_CLS = {}
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
def register_data_loader_cls(data_config_cls):
|
| 23 |
-
"""Decorates a factory of DataLoader for lookup by a subclass of DataConfig.
|
| 24 |
-
|
| 25 |
-
This decorator supports registration of data loaders as follows:
|
| 26 |
-
|
| 27 |
-
```
|
| 28 |
-
@dataclasses.dataclass
|
| 29 |
-
class MyDataConfig(DataConfig):
|
| 30 |
-
# Add fields here.
|
| 31 |
-
pass
|
| 32 |
-
|
| 33 |
-
@register_data_loader_cls(MyDataConfig)
|
| 34 |
-
class MyDataLoader:
|
| 35 |
-
# Inherits def __init__(self, data_config).
|
| 36 |
-
pass
|
| 37 |
-
|
| 38 |
-
my_data_config = MyDataConfig()
|
| 39 |
-
|
| 40 |
-
# Returns MyDataLoader(my_data_config).
|
| 41 |
-
my_loader = get_data_loader(my_data_config)
|
| 42 |
-
```
|
| 43 |
-
|
| 44 |
-
Args:
|
| 45 |
-
data_config_cls: a subclass of DataConfig (*not* an instance
|
| 46 |
-
of DataConfig).
|
| 47 |
-
|
| 48 |
-
Returns:
|
| 49 |
-
A callable for use as class decorator that registers the decorated class
|
| 50 |
-
for creation from an instance of data_config_cls.
|
| 51 |
-
"""
|
| 52 |
-
return registry.register(_REGISTERED_DATA_LOADER_CLS, data_config_cls)
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
def get_data_loader(data_config):
|
| 56 |
-
"""Creates a data_loader from data_config."""
|
| 57 |
-
return registry.lookup(_REGISTERED_DATA_LOADER_CLS, data_config.__class__)(
|
| 58 |
-
data_config)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|