# Oracle APEX Plugin for Zero Shot Classification

Zero-shot text classification is a task in natural language processing where a model is trained on a set of labeled examples but is then able to classify new examples from previously unseen classes.

![](https://cdn.hashnode.com/uploads/covers/6317847b2cef8b07c2f1d5c6/40af1f61-7eb0-4fe5-a0a7-63345a58675c.png align="center")

It’s called **zero-shot** because you give the model *zero examples* of how to classify items into your chosen categories.

So basically without examples; the AI has got to score the supplied candidate descriptions and returns the highest-scoring one

These optimized models for Zero-shot can be extremely small. In my example below

*   I'm using [nli-deberta-v3-xsmall](https://huggingface.co/Xenova/nli-deberta-v3-xsmall) AI Model which comes in at 143mb.
    
    *   i.e a Bunch of numbers and calculations
        
*   I'm using [Transformer.js](https://github.com/huggingface/transformers.js) which is a JavaScript library that runs the AI model
    
    *   i.e the engine that processes the user text and does the number crunching from the AI model
        

What's super cool is that I can use the WebGPU when using Chromium browsers - which means Im using the processing power of my GPU

If I'm not using Chromium or WebGPU is not available, it will use WASM. Still good for Zero-shot text classification.

All of this so far is running in the browser, subscription free, zero cost and runs locally.

What I've done next is to add all this into an Oracle APEX Dynamic Action Plugin so that it can be used to categorize input and place the output into a Page Item.

I decided to use the CDN link rather that create a 150mb+ Plugin. Although its completely possible to incorporate the files into the the Plugin static files

In the example below I'm using input text and using these categories

```json
[
  {
    "candidate": "an urgent or time-sensitive message requiring prompt attention or action, such as a service outage, critical incident, immediate deadline or important issue",
    "value": "Priority"
  },
  {
    "candidate": "ordinary personal or work correspondence, such as a conversation, question, meeting arrangement, invitation, follow-up or discussion",
    "value": "Inbox"
  },
  {
    "candidate": "a marketing or promotional message advertising products, services, sales, discounts, special offers, events or commercial newsletters",
    "value": "Promotional"
  },
  {
    "candidate": "a notification from a social network or online community about likes, comments, mentions, followers, friend requests, shared posts or community activity",
    "value": "Social"
  },
  {
    "candidate": "an automated informational or transactional notification, such as an order confirmation, delivery update, receipt, invoice, booking confirmation, account notification or routine status update",
    "value": "Updates"
  },
  {
    "candidate": "a suspicious or deceptive unsolicited message, such as a fake prize, lottery win, phishing request, impersonation, fraudulent offer or get-rich-quick scheme",
    "value": "Spam"
  }
]
```

So basically

*   Candidate = The most plausible match for the input text
    
*   Value = The resulting value when a match is made
    

I can add as many candidates as I wish

In the Plugin, I assign the Input and Output to P2\_INPUT and P2\_OUTPUT respectively

Here is it in action

![](https://cdn.hashnode.com/uploads/covers/6317847b2cef8b07c2f1d5c6/eeaafdec-29cc-499c-a2e4-194794e2f482.gif align="center")

As you can see, im using Quick Picks to sort out my emails.... and it's fast!

In all honesty, the first call takes about 3-5 seconds whilst it downloads everything.

In the picture above:

*   I use an input text of "*FLASH SALE: 40% off everything this weekend only. Use code SAVE40 at checkout.*" in **P2\_INPUT**
    
*   Clicking the **button** activates the Plug-in
    
*   Transformers and the Zero Shot Model determine that Promotional is the best candidate and set the **P2\_OUTPUT** to **Promotional**
    

In fact the plugin returned the following

```json
{
  "candidate": "a marketing email advertising a sale, discount or product",
  "score": 0.7538969082328599,
  "value": "Promotional",
  "backend": "webgpu (fp16)"
}
```

As you can see - it was using the power of my GPU (theres a fallback to WASM) and it returned the **highest scoreing** Candidate with **75.39**%

To be clear, this it not a certainty score - this is a score attributed to the highest scoring candidate. Its not facutally correct, the model just percives it the highest scoring

For example, if I use these candidates

```json
[
  {"candidate": "a crisp, round fruit with red or green skin", "value": "APPLE"},
  {"candidate": "a long, curved fruit with yellow skin", "value": "BANANA"},
  {"candidate": "a round citrus fruit with orange coloured peel", "value": "ORANGE"},
  {"candidate": "a small, red fruit with seeds on its surface", "value": "STRAWBERRY"},
  {"candidate": "a small, round fruit that grows in bunches", "value": "GRAPE"},
  {"candidate": "a large fruit with rough skin and spiky leaves", "value": "PINEAPPLE"}
]
```

and use the following input

> Who is Dominic Calvert-Lewin

Then it returns

```json
{
  "candidate": "a crisp, round apple with red or green skin",
  "score": 0.2718418686993495,
  "value": "APPLE",
  "backend": "webgpu (fp16)"
}
```

Its not 27% certain. In fact with 6 candidates; that gives an average of 16.67% each; it just picked the least bad candidate - out of a bad set.

I've uploaded the plugin here for you to use, fork, contribute to:

[https://github.com/lufcmattylad/Zero-shot-classification-apex-plugin](https://github.com/lufcmattylad/Zero-shot-classification-apex-plugin)

As of now, I treat this as a proof of concept.

Some other examples you could use are RAG Statuses

```json
  [
    {"candidate": "on track",  "value": "G"},
    {"candidate": "at risk",   "value": "A"},
    {"candidate": "off track", "value": "R"}
  ]
```

Priorties

```json
  [
    {"candidate": "urgent",     "value": 1},
    {"candidate": "important",  "value": 2},
    {"candidate": "not urgent", "value": 3}
  ]
```

Or Incident classifications

```json
  [
    {"candidate": "a billing or payment question",   "value": "BILLING"},
    {"candidate": "a technical problem or bug",      "value": "TECH"},
    {"candidate": "a request for a new feature",     "value": "FEATURE"},
    {"candidate": "a question about my account",     "value": "ACCOUNT"}
  ]
```

ENJOY

What's the picture? Leeds United a couple of hours after [the Crystal Palace game](https://www.youtube.com/watch?v=QuCVcCmgOmw). Litter everywhere 😥 - Visit Yorkshire
