Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions language/classify_text/classify_text_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# [START language_classify_text_tutorial]
"""Using the classify_text method to find content categories of text files,
Then use the content category labels to compare text similarity.

Expand Down Expand Up @@ -94,7 +93,6 @@ def index(path, index_file):
# [END language_classify_text_tutorial_index]


# [START language_classify_text_tutorial_split_labels]
def split_labels(categories):
"""The category labels are of the form "/a/b/c" up to three levels,
for example "/Computers & Electronics/Software", and these labels
Expand All @@ -121,10 +119,8 @@ def split_labels(categories):
_categories[label] = confidence

return _categories
# [END language_classify_text_tutorial_split_labels]


# [START language_classify_text_tutorial_similarity]
def similarity(categories1, categories2):
"""Cosine similarity of the categories treated as sparse vectors."""
categories1 = split_labels(categories1)
Expand All @@ -143,7 +139,6 @@ def similarity(categories1, categories2):
dot += confidence * categories2.get(label, 0.0)

return dot / (norm1 * norm2)
# [END language_classify_text_tutorial_similarity]


# [START language_classify_text_tutorial_query]
Expand Down Expand Up @@ -255,4 +250,3 @@ def query_category(index_file, category_string, n_top=3):
query(args.index_file, args.text)
if args.command == 'query-category':
query_category(args.index_file, args.category)
# [END language_classify_text_tutorial]