Skip to main content

Text Categorizer

Problem statement

When analyzing texts of any nature (being search keywords and YouTube video descriptions) it might be challenging to identify insights given unstructured nature of such texts.

Solution

text-categorizer uses power of large language models to perform categorization at your texts - simply provide a couple of seed examples and text-categorizer will do the rest.

Deliverable (implementation)

text-categorizer is implemented as a:

  • library - Use it in your projects with a help of TextCategorizer class.
  • CLI tool - text-categorizer tool is available to be used in the terminal.
  • HTTP endpoint - text-categorizer can be easily exposed as HTTP endpoint.
  • Langchain tool - integrated text-categorizer into your Langchain applications.

Deployment

Prerequisites

  • Python 3.11+

  • A GCP project with billing account attached

  • Service account created and service account key downloaded in order to write data to BigQuery.

    • Once you downloaded service account key export it as an environmental variable

      export GOOGLE_APPLICATION_CREDENTIALS=path/to/service_account.json
      
    • If authenticating via service account is not possible you can authenticate with the following command:

      gcloud auth application-default login
      
  • API key to access to access Google Gemini.
    • Once you created API key export it as an environmental variable

      export GOOGLE_API_KEY=<YOUR_API_KEY_HERE>
      

Installation

Install text-categorizer with pip install text-categorization command.

Usage

This section is focused on using text-categorizer as a CLI tool. Check library, http endpoint, langchain tool sections to learn more.

Once text-categorizer is installed you can call it:

text-categorizer 'text1' 'text2' 'text3' \
  --examples path/to/examples.txt \
  --llm gemini \
  --llm.model=gemini-1.5-flash \
  --output-type csv \
  --output-destination sample_results

where:

  • 'text1' 'text2' 'text3' - texts that needed to be categorized,
  • --examples path/to/examples.txt - path to examples (each line of the file should be formatted as text - category, i.e. dog - pet).
  • --llm gemini - type of large language model (currently only Google Gemini is supported)
  • --llm.model=gemini-1.5-flash - any parameters to initialize selected LLM
  • --output-type csv - type of output
  • --output-destination sample_results - name of output table or file.

--examples - might also come from BigQuery - simply pass full table name (project.dataset.table) as an example (Table should contains two columns - text and category).

Instead of passing texts as a parameters to text-categorizer you can provide --remote-texts flag - it will accept a full table name in BigQuery. You can combine passing texts and --remote-texts (Table should contain a column named text) .

Disclaimer

This is not an officially supported Google product.

Metadata

Release files for text-categorization 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for text-categorization 0.1.1
File Size Uploaded Provenance Actions
text-categorization-0.1.1.tar.gz 9.3 kB Without provenance Details for text-categorization-0.1.1.tar.gz

Release files / text-categorization-0.1.1.tar.gz

Download URL text-categorization-0.1.1.tar.gz
Size 9.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d337ece1a9b5e2357e1bee7f13f31e7c5e698bdf7b6c63fe6a26a8d7d551de25
BLAKE2b-256 checksum
How to use checksums
ce2949384adb8c087e556038bf568f38dd38c351028fe1f86b02d27090964e6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.8

Security for text-categorization 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page