-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
Classify tutorial #1120
Conversation
language/classify_text/README.md
Outdated
@@ -0,0 +1,80 @@ | |||
# Introduction |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.""" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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(): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
) * 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
) * 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
* 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
) * 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
Tutorial for classify_text.