Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Classify tutorial #1120

Merged
merged 11 commits into from
Sep 19, 2017
Merged

Conversation

dizcology
Copy link
Member

Tutorial for classify_text.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Sep 18, 2017
@dizcology dizcology requested review from andrewsg and gguuss and removed request for gguuss September 18, 2017 03:21
@@ -0,0 +1,80 @@
# Introduction
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should (ideally) use an autogenerated readme. This readme has way too much content and possibly duplicates the tutorial on devsite.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@@ -0,0 +1,251 @@
# Copyright 2017, Google, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

# limitations under the License.

# [START classify_text_tutorial]
"""Using the classify_text method to cluster texts."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This docstring needs to be far more descriptive.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. but let me know if I should add more. the tutorial page on cloud.google.com hasn't been published yet.

import os

from google.cloud import language_v1beta2
from google.cloud.language_v1beta2 import enums
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can just use language_v1beta2.types and language_v1beta2.enums if you want to save yourself the trouble of importing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to reduce clutter in other samples (e.g. prefer types.Document over lanbuage_v1beta2.Document) I have been importing all three separately. I hope to keep it consistent in this code sample as well.

from google.cloud.language_v1beta2 import enums
from google.cloud.language_v1beta2 import types

import numpy as np
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please do not alias imports. This also goes into the second section of imports.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

However, aliasing numpy as np seems very common for Python. Later let's revisit the possibility of relaxing the authoring guide to allow this?

document = types.Document(
content=text,
type=enums.Document.Type.PLAIN_TEXT)
categories = language_client.classify_text(document).categories
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For better understandability, please assign the result to a temporary variable:

result = language_client.classify_text(document)
categories = result.categories

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

the query text.
"""

with open(index_file, 'r') as f:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throughout this file, please use io.open over open.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

query_categories = classify(text, verbose=False)

similarities = []
for filename, categories in index.iteritems():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to use six.iteritems(index) for this to work on 2 & 3.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@dizcology dizcology removed the request for review from andrewsg September 18, 2017 22:06
@theacodes theacodes merged commit 058296f into GoogleCloudPlatform:master Sep 19, 2017
hkdevandla pushed a commit to hkdevandla/python-language that referenced this pull request Sep 26, 2020
)

* first version of classify_text tutorial

* addressing comments

* classify text tutorial

* update client version

* year first written

* use auto generated README

* add README.rst.in and README.rst

* addressing review comments

* add tests for index and query

* import order

* add numpy to requirements
busunkim96 pushed a commit to googleapis/python-language that referenced this pull request Sep 29, 2020
)

* first version of classify_text tutorial

* addressing comments

* classify text tutorial

* update client version

* year first written

* use auto generated README

* add README.rst.in and README.rst

* addressing review comments

* add tests for index and query

* import order

* add numpy to requirements
m-strzelczyk pushed a commit that referenced this pull request Nov 18, 2022
* first version of classify_text tutorial

* addressing comments

* classify text tutorial

* update client version

* year first written

* use auto generated README

* add README.rst.in and README.rst

* addressing review comments

* add tests for index and query

* import order

* add numpy to requirements
parthea pushed a commit to googleapis/google-cloud-python that referenced this pull request Jul 6, 2023
)

* first version of classify_text tutorial

* addressing comments

* classify text tutorial

* update client version

* year first written

* use auto generated README

* add README.rst.in and README.rst

* addressing review comments

* add tests for index and query

* import order

* add numpy to requirements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants