Last active
May 5, 2021 06:32
-
-
Save EricFillion/be1c42438cc3bc7436aa3044026be6af to your computer and use it in GitHub Desktop.
Zero Shot Text Classification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pip install transformers | |
from transformers import pipeline | |
tags = ["travel", "surfing", "Indonesia", "Bali", "cryptocurrencies", "bitcoin", "mining", "gardening", "plants"] | |
sequences = ["Best surf camp in Bali", "How do I build a crypto mining rig?", "my plant has yellow leaves"] | |
classifer = pipeline("zero-shot-classification") | |
for text in sequences: | |
result = classifer(text, tags) | |
print(text + ":") | |
for label, score in zip(result["labels"], result["scores"]): | |
print(label, score) | |
print("\n\n") | |
#----------------------------------------------------- | |
# Output | |
""" | |
Best surf camp in Bali: | |
Bali 0.42244213819503784 | |
surfing 0.40309280157089233 | |
travel 0.10794368386268616 | |
Indonesia 0.05909815430641174 | |
bitcoin 0.003099546767771244 | |
cryptocurrencies 0.0015756567008793354 | |
plants 0.0012342673726379871 | |
gardening 0.0008835656335577369 | |
mining 0.0006302755209617317 | |
How do I build a crypto mining rig?: | |
cryptocurrencies 0.6826867461204529 | |
mining 0.2748754620552063 | |
Bali 0.012076622806489468 | |
bitcoin 0.010957781225442886 | |
travel 0.005191634874790907 | |
surfing 0.004757559858262539 | |
Indonesia 0.004334508907049894 | |
plants 0.002861511427909136 | |
gardening 0.0022582190576940775 | |
my plant has yellow leaves: | |
plants 0.9064661264419556 | |
gardening 0.07110192626714706 | |
Bali 0.006484213285148144 | |
travel 0.004733263049274683 | |
surfing 0.0045728315599262714 | |
Indonesia 0.003091926220804453 | |
mining 0.0013643732527270913 | |
bitcoin 0.0011404716642573476 | |
cryptocurrencies 0.0010448909597471356 | |
""" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment