ticket-tagger

Automatically tag incoming tickets. Route and close tickets faster with a pre- trained ML that fine-tunes on your data as you scale.

Useful for companies routing and analyzing inbound customer help tickets.

Using

Steamship Packages are cloud-hosted AI libraries you can use from any programming environment.

Packages manage their own data & infrastructure in the cloud. Each instance gets its own private scope.

Links

Download a Jupyter Demo

> npx try-steamship ticket-tagger

From Python

from steamship import Steamship

# See GitHub README for Config requirements
instance = Steamship.use("ticket-tagger", config={})

# See GitHub README for available methods
resp = instance.invoke('method', arg1=val1, arg2=val2)
Pulled from the GitHub repository.
# Ticket Tagging API

This package classifies customer support tickets into a user-defined set of labels with no model training required. As 
labeled data is (optionally) collected, you can opt to train and switch over to a specialized (trained) model with no
interruption of service or infrastructure maintenance.

This dual-mode operation makes the package useful across a spectrum of scenarios:

* **Unspecialized (Zero-Shot Classifier) Model**: When classification results are desired immediately, with no "data science" overhead first.
* **Specialized (Trained Classifier) Model**: When training data is available, labels are more nuanced, or better performance is required.
* **Blended Operation**: When some customer accounts are high-value / high-volume enough to warrant a trained 
  classifier, while most are low-value / low-volume and should opt for classification via a generalized global model.

All training, inference, and data is managed in the cloud, per instance of the package.

## Live Demos

* [Demo the package on Streamlit](https://share.streamlit.io/app/steamship-apps-demos--home-ticket-tagging-demo-55jzrt/%EF%B8%8F_Ticket_Tagging)
* [Demo the package in Google Collab](https://githubtocolab.com/steamship-packages/ticket-tagging-api/blob/main/examples/ticket-tagger-python-client-demo.ipynb)

## Quick Setup

It only takes a minute to be up and running with the Steamship CLI & our Python client library. For other environments, contact hello@steamship.com.

1. **Create a Steamship Account.**

    ```bash
    npm install -g @steamship/cli && ship login
    ```
   
2. **Install the Steamship Client.**

    ```bash
    pip install steamship
    ```

3. **Create a package instance.** 
   Think of Steamship packages like Python imports, but the code runs in the cloud. 
   In addition to providing the package name, you also provide an **instance handle** and optional **configuration block**.
   The instance identifier isolates your package's data & infrastructure from other instances within your account.
   The configuration block is saved and immutable after instance construction. 

    ```python
    from steamship import Steamship   
    instance = Steamship.use("ticket-tagger", "my-instance-handle", config=optional_dict)  
    ```

4. **Use the package instance.**
   Interact with your package instance similarly to a kwarg-accepting Python object:

    ```python
    instance.invoke('method_name', arg1=val1, arg2=val2, arg3=val3...)
    ```

   A full walkthrough of the package is provided in `example/python-client-demo.ipynb`, and a list of methods is below.

## API Documentation

### Instance Configuration

The following configuration parameters may be provided when creating a new instance. They will be persisted and used each subsequent time that instance is used.

- **save_classifications** - Whether to retain all classifications in the Steamship Space for caching or analysis purposes.

### Instance Methods

The following methods are provided on each instance. The data and infrastructure they utilize are scoped by the instance handle.

- **set_labels(labels: List[str])** - Set the labels that will be used for tagging. This can be a simple list of strings. Resetting the labels after training a model will reset to zero-shot classification.  For best results, clean labels of special characters like underscores.
- **tag_ticket(ticket_text: str)** - Tag a ticket. Returns confidences for all provided labels.  Throws an error if set_labels has not been called.  This method will work out of the box with a zero-shot classifier, and will seamlessly transition to a trained model after prerequisites are met below.
- **tag_tickets(ticket_texts: List[str])** - Tag several tickets.  Returns confidences for all provided labels.  Throws an error if set_labels has not been called.  This method will work out of the box with a zero-shot classifier, and will seamlessly transition to a trained model after prerequisites are met below.
- **add_example(ticket_text: str, labels: List[str])** - Add a curated example for learning.  This could happen after a user manually confirms or rejects ticket suggestions, or when importing an existing set of pre-tagged tickets.  
- **add_examples(ticket_texts: list[str], labels: List[List[[str]])** - Add several curated examples for learning.  This could happen after a user manually confirms or rejects ticket suggestions, or when importing an existing set of pre-tagged tickets. 
- **count_examples()** - Return both total count and count per tag of the examples that have been added so far.
- **start_specialize()** - When sufficient data has been loaded, call this to switch from zero-shot to trained classifiers for better performance.
- **specialize_status()** - Call this to know the current status of the app: unspecialized, specialization_in_progress, or specialized.  This method *must* be polled after specialization begins for the app to switch to specialized mode.
- **clear_examples()** - Remove all previously added examples.
- **clear_trained_model()** - Remove any trained model.

## Design Notes - Transitioning from Zero-shot to Trained Classification

The package allows you to begin tagging tickets immediately with no training, leveraging zero-shot classification.  
If you wish  to improve performance, you can provide examples of text and labels, and transition to using a (likely) 
higher-accuracy trained model. 

During the training and deployment of the trained model, the zero-shot model remains active and usable, as shown below: 

![Diagram of Specialization Transition](https://github.com/steamship-packages/ticket-tagging-api/blob/main/docs/specialization_status.png)

The full flowchart of usage is shown in Python in [this notebook](https://github.com/steamship-packages/ticket-tagging-api/blob/main/examples/ticket-tagger-python-client-demo.ipynb). 
(HTTP-only invokers may which to see the [HTTP client demo](https://github.com/steamship-packages/ticket-tagging-api/blob/main/examples/ticket-tagger-http-client-demo.ipynb) and [HTTP instance 
creation demo](https://github.com/steamship-packages/ticket-tagging-api/blob/main/examples/app_instance_creation.ipynb).

![App Workflow Diagram](https://github.com/steamship-packages/ticket-tagging-api/blob/main/docs/app_workflow.png)

## Full Example

Full examples of usage are located as Jupyter notebooks in [examples/](https://github.com/steamship-packages/ticket-tagging-api/blob/main/examples/)

## Developing

Instructions for contributing to this package are located in [DEVELOPING.md](https://github.com/steamship-packages/ticket-tagging-api/blob/main/DEVELOPING.md)

## Testing

Instructions for testing this package are located in [TESTING.md](https://github.com/steamship-packages/ticket-tagging-api/blob/main/TESTING.md)

## Deploying

Instructions for deploying new or custom versions of package are located in [DEPLOYING.md](https://github.com/steamship-packages/ticket-tagging-api/blob/main/DEPLOYING.md). 
Note that deployment is not the same as using the package. Deployment makes new implementations of this package available to you or other Steamship users. 

Steamship is building the fastest way to ship language AI.

Stop building and start shipping. Reach out to get onboarded.
Read More