Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 058296f

Browse filesBrowse files
dizcologyJon Wayne Parrott
authored andcommitted
Classify tutorial (GoogleCloudPlatform#1120)
* 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
1 parent a02123e commit 058296f
Copy full SHA for 058296f
Expand file treeCollapse file tree

22 files changed

+522
-0
lines changed

‎language/classify_text/README.rst

Copy file name to clipboard
+126Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
.. This file is automatically generated. Do not edit this file directly.
2+
3+
Google Cloud Natural Language API Python Samples
4+
===============================================================================
5+
6+
This directory contains samples for Google Cloud Natural Language API. The `Google Cloud Natural Language API`_ provides natural language understanding technologies to developers.
7+
8+
This tutorial demostrates how to use the `classify_text` method to classify content category of text files, and use the result to compare texts by their similarity to each other. See the `tutorial page`_ for details about this sample.
9+
10+
.. _tutorial page: https://cloud.google.com/natural-language/docs/classify-text-tutorial
11+
12+
13+
14+
15+
.. _Google Cloud Natural Language API: https://cloud.google.com/natural-language/docs/
16+
17+
Setup
18+
-------------------------------------------------------------------------------
19+
20+
21+
Authentication
22+
++++++++++++++
23+
24+
Authentication is typically done through `Application Default Credentials`_,
25+
which means you do not have to change the code to authenticate as long as
26+
your environment has credentials. You have a few options for setting up
27+
authentication:
28+
29+
#. When running locally, use the `Google Cloud SDK`_
30+
31+
.. code-block:: bash
32+
33+
gcloud auth application-default login
34+
35+
36+
#. When running on App Engine or Compute Engine, credentials are already
37+
set-up. However, you may need to configure your Compute Engine instance
38+
with `additional scopes`_.
39+
40+
#. You can create a `Service Account key file`_. This file can be used to
41+
authenticate to Google Cloud Platform services from any environment. To use
42+
the file, set the ``GOOGLE_APPLICATION_CREDENTIALS`` environment variable to
43+
the path to the key file, for example:
44+
45+
.. code-block:: bash
46+
47+
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account.json
48+
49+
.. _Application Default Credentials: https://cloud.google.com/docs/authentication#getting_credentials_for_server-centric_flow
50+
.. _additional scopes: https://cloud.google.com/compute/docs/authentication#using
51+
.. _Service Account key file: https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatinganaccount
52+
53+
Install Dependencies
54+
++++++++++++++++++++
55+
56+
#. Install `pip`_ and `virtualenv`_ if you do not already have them.
57+
58+
#. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+.
59+
60+
.. code-block:: bash
61+
62+
$ virtualenv env
63+
$ source env/bin/activate
64+
65+
#. Install the dependencies needed to run the samples.
66+
67+
.. code-block:: bash
68+
69+
$ pip install -r requirements.txt
70+
71+
.. _pip: https://pip.pypa.io/
72+
.. _virtualenv: https://virtualenv.pypa.io/
73+
74+
Samples
75+
-------------------------------------------------------------------------------
76+
77+
Classify Text Tutorial
78+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
79+
80+
81+
82+
To run this sample:
83+
84+
.. code-block:: bash
85+
86+
$ python classify_text_tutorial.py
87+
88+
usage: classify_text_tutorial.py [-h]
89+
{classify,index,query,query-category} ...
90+
91+
Using the classify_text method to cluster texts.
92+
93+
positional arguments:
94+
{classify,index,query,query-category}
95+
classify Classify the input text into categories.
96+
index Classify each text file in a directory and write the
97+
results to the index_file.
98+
query Find the indexed files that are the most similar to
99+
the query text.
100+
query-category Find the indexed files that are the most similar to
101+
the query label. The list of all available labels:
102+
https://cloud.google.com/natural-
103+
language/docs/categories
104+
105+
optional arguments:
106+
-h, --help show this help message and exit
107+
108+
109+
110+
111+
The client library
112+
-------------------------------------------------------------------------------
113+
114+
This sample uses the `Google Cloud Client Library for Python`_.
115+
You can read the documentation for more details on API usage and use GitHub
116+
to `browse the source`_ and `report issues`_.
117+
118+
.. _Google Cloud Client Library for Python:
119+
https://googlecloudplatform.github.io/google-cloud-python/
120+
.. _browse the source:
121+
https://github.com/GoogleCloudPlatform/google-cloud-python
122+
.. _report issues:
123+
https://github.com/GoogleCloudPlatform/google-cloud-python/issues
124+
125+
126+
.. _Google Cloud SDK: https://cloud.google.com/sdk/

‎language/classify_text/README.rst.in

Copy file name to clipboard
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# This file is used to generate README.rst
2+
3+
product:
4+
name: Google Cloud Natural Language API
5+
short_name: Cloud Natural Language API
6+
url: https://cloud.google.com/natural-language/docs/
7+
description: >
8+
The `Google Cloud Natural Language API`_ provides natural language
9+
understanding technologies to developers.
10+
11+
12+
This tutorial demostrates how to use the `classify_text` method to classify content category of text files, and use the result to compare texts by their similarity to each other. See the `tutorial page`_ for details about this sample.
13+
14+
15+
.. _tutorial page: https://cloud.google.com/natural-language/docs/classify-text-tutorial
16+
17+
setup:
18+
- auth
19+
- install_deps
20+
21+
samples:
22+
- name: Classify Text Tutorial
23+
file: classify_text_tutorial.py
24+
show_help: true
25+
26+
cloud_client_library: true

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.