-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
samples: NLP import and predict samples for SDK (#276)
* samples: NLP import and predict samples for SDK * fix: mismatched region tags * samples: add more import data samples * samples: adds prediction NLP samples * fix: lint * samples: prediction tests * samples: adds endpoint fixtures * fix: lint * Update all MBSDK Dataset sample test mocks, fix NLP sample tests * Remove reference to ipdb Co-authored-by: Vinny Senthil <vinnysenthil@gmail.com>
- Loading branch information
1 parent
38eb76f
commit a1819b2
Showing
18 changed files
with
666 additions
and
33 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
43 changes: 43 additions & 0 deletions
43
samples/model-builder/create_and_import_dataset_text_sample.py
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,43 @@ | ||
# Copyright 2021 Google LLC | ||
# | ||
# 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 | ||
# | ||
# https://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. | ||
|
||
from typing import List, Union | ||
|
||
from google.cloud import aiplatform | ||
|
||
# [START aiplatform_sdk_create_and_import_dataset_text_sample] | ||
def create_and_import_dataset_text_sample( | ||
project: str, | ||
location: str, | ||
display_name: str, | ||
src_uris: Union[str, List[str]], | ||
sync: bool = True, | ||
): | ||
aiplatform.init(project=project, location=location) | ||
|
||
ds = aiplatform.TextDataset.create( | ||
display_name=display_name, | ||
gcs_source=src_uris, | ||
import_schema_uri=aiplatform.schema.dataset.ioformat.text.single_label_classification, | ||
sync=sync, | ||
) | ||
|
||
ds.wait() | ||
|
||
print(ds.display_name) | ||
print(ds.resource_name) | ||
return ds | ||
|
||
|
||
# [END aiplatform_sdk_create_and_import_dataset_text_sample] |
39 changes: 39 additions & 0 deletions
39
samples/model-builder/create_and_import_dataset_text_sample_test.py
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,39 @@ | ||
# Copyright 2021 Google LLC | ||
# | ||
# 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 | ||
# | ||
# https://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 test_constants as constants | ||
import create_and_import_dataset_text_sample | ||
|
||
from google.cloud.aiplatform import schema | ||
|
||
|
||
def test_create_and_import_dataset_text_sample(mock_sdk_init, mock_create_text_dataset): | ||
|
||
create_and_import_dataset_text_sample.create_and_import_dataset_text_sample( | ||
project=constants.PROJECT, | ||
location=constants.LOCATION, | ||
src_uris=constants.GCS_SOURCES, | ||
display_name=constants.DISPLAY_NAME, | ||
) | ||
|
||
mock_sdk_init.assert_called_once_with( | ||
project=constants.PROJECT, location=constants.LOCATION | ||
) | ||
mock_create_text_dataset.assert_called_once_with( | ||
display_name=constants.DISPLAY_NAME, | ||
gcs_source=constants.GCS_SOURCES, | ||
import_schema_uri=schema.dataset.ioformat.text.single_label_classification, | ||
sync=True, | ||
) |
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
43 changes: 43 additions & 0 deletions
43
samples/model-builder/import_data_text_classification_single_label_sample.py
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,43 @@ | ||
# Copyright 2021 Google LLC | ||
# | ||
# 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 | ||
# | ||
# https://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. | ||
|
||
from typing import List, Union | ||
|
||
from google.cloud import aiplatform | ||
|
||
# [START aiplatform_sdk_import_data_text_classification_single_label_sample] | ||
def import_data_text_classification_single_label( | ||
project: str, | ||
location: str, | ||
dataset: str, | ||
src_uris: Union[str, List[str]], | ||
sync: bool = True, | ||
): | ||
aiplatform.init(project=project, location=location) | ||
|
||
ds = aiplatform.TextDataset(dataset) | ||
ds.import_data( | ||
gcs_source=src_uris, | ||
import_schema_uri=aiplatform.schema.dataset.ioformat.text.single_label_classification, | ||
sync=sync, | ||
) | ||
|
||
ds.wait() | ||
|
||
print(ds.display_name) | ||
print(ds.resource_name) | ||
return ds | ||
|
||
|
||
# [END aiplatform_sdk_import_data_text_classification_single_label_sample] |
Oops, something went wrong.