ZeroShot Classfier (zs_classifier
)
zs_classifier
is a zeroshot text classification module build on top of flair library. It uses tars-base
model for text classification
This tutorial shows you how to import and use zs_classifier
with jac code.
- Import ZS Classifier module in jac
- ZeroShot Predictions
- ZeroShot Embeddings
Walk through
1. Import ZeroShot Classfier(zs_classifier)
module in jac
- Open terminal and run jaseci by cmd
jsctl -m
- Load
zs_classifier
module in jac by cmdactions load module jac_nlp.zs_classifier
2. ZeroShot Predictions
-
Creating a Jac Walker (
predict_zs
)-
Create a file by name
zs_classifier.jac
-
Create
predict_zs
walkerwalker predict_zs{ can zs_classifier.classify; report zs_classifier.classify(text="I am so glad you liked it", classes=["happy","sad"]); }
Parameter details
classify
: used to classify text among the classes provided- Input:
text
(str or List(str)): it can be string or list of stringclasses
(List): list of classes that text needs to be classified
- Returns: list of classes with the confidence score for each
- Input:
-
-
Steps for running
zs_classifier.jac
program- Build
zs_classifier.jac
by run cmdjac build zs_classifier.jac
- Activate sentinal by run cmd
sentinel set -snt active:sentinel -mode ir zs_classifier.jir
- Calling walker
predict_zs
withdefault parameter
walker run predict_zs
Expected output
[ { "I am so glad you liked it": [ { "value": "happy", "confidence": 0.8714166879653931 } ] } ]
- Build
3. ZeroShot Embeddings
-
Creating a Jac Walker (
get_embeddings
)-
Create
get_embeddings
walker in thezs_classifier.jac
walker test_get_embedding{ can zs_classifier.get_embeddings; report zs_classifier.get_embeddings(texts="I am so glad you liked it!"); }
Parameter details
get_embeddings
: can be used to get embeddings for text from zs model- Input:
text
(str or List(str)): it can be string or list of string
- Returns: list of embdedding of length 768 size
- Input:
-
-
Steps for running
zs_classifier.jac
program- Build
zs_classifier.jac
by run cmdjac build zs_classifier.jac
- Activate sentinal by run cmd
sentinel set -snt active:sentinel -mode ir zs_classifier.jir
- Calling walker
get_embeddings
withdefault parameter
walker run get_embeddings
Expected output
[ 0.15722215175628662, -0.2446146011352539, 0.7713489532470703, 0.20605269074440002, ... ... ... ... -0.4917687475681305, 0.17996184527873993, -0.39374977350234985, 0.3616657555103302 ]
- Build