-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Multilingual Domain Classifier (#363)
* initial commit Signed-off-by: Sarah Yurick <[email protected]> * run black Signed-off-by: Sarah Yurick <[email protected]> * combine with DomainClassifier Signed-off-by: Sarah Yurick <[email protected]> * isort Signed-off-by: Sarah Yurick <[email protected]> * add links Signed-off-by: Sarah Yurick <[email protected]> * add praateek's suggestion Signed-off-by: Sarah Yurick <[email protected]> * add ryan's suggestion Signed-off-by: Sarah Yurick <[email protected]> * update readmes Signed-off-by: Sarah Yurick <[email protected]> * create MultilingualDomainClassifier Signed-off-by: Sarah Yurick <[email protected]> * add api Signed-off-by: Sarah Yurick <[email protected]> --------- Signed-off-by: Sarah Yurick <[email protected]>
- Loading branch information
1 parent
edd6262
commit 7272ca0
Showing
11 changed files
with
370 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved. | ||
# | ||
# 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 law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# 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. | ||
|
||
import argparse | ||
import time | ||
|
||
from nemo_curator.classifiers import MultilingualDomainClassifier | ||
from nemo_curator.datasets import DocumentDataset | ||
from nemo_curator.utils.distributed_utils import get_client | ||
from nemo_curator.utils.script_utils import ArgumentHelper | ||
|
||
|
||
def main(args): | ||
global_st = time.time() | ||
|
||
# Input can be a string or list | ||
input_file_path = "/path/to/data" | ||
output_file_path = "./" | ||
|
||
client_args = ArgumentHelper.parse_client_args(args) | ||
client_args["cluster_type"] = "gpu" | ||
client = get_client(**client_args) | ||
|
||
input_dataset = DocumentDataset.read_json( | ||
input_file_path, backend="cudf", add_filename=True | ||
) | ||
|
||
multilingual_domain_classifier = MultilingualDomainClassifier( | ||
filter_by=["Games", "Sports"] | ||
) | ||
result_dataset = multilingual_domain_classifier(dataset=input_dataset) | ||
|
||
result_dataset.to_json(output_file_dir=output_file_path, write_to_filename=True) | ||
|
||
global_et = time.time() | ||
print( | ||
f"Total time taken for multilingual domain classifier inference: {global_et-global_st} s", | ||
flush=True, | ||
) | ||
|
||
client.close() | ||
|
||
|
||
def attach_args( | ||
parser=argparse.ArgumentParser( | ||
formatter_class=argparse.ArgumentDefaultsHelpFormatter | ||
), | ||
): | ||
argumentHelper = ArgumentHelper(parser) | ||
argumentHelper.add_distributed_classifier_cluster_args() | ||
|
||
return argumentHelper.parser | ||
|
||
|
||
if __name__ == "__main__": | ||
main(attach_args().parse_args()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.