mirror of
https://github.com/neuml/txtai.git
synced 2026-10-12 02:19:52 +00:00
8.9 KiB
8.9 KiB
In [ ]:
%%capture
!pip install git+https://github.com/neuml/txtaiIn [ ]:
%%capture
from txtai.pipeline import Labels
# Create labels model
labels = Labels()
# Alternate models can be used via passing the model path as shown below
# labels = Labels("roberta-large-mnli")In [ ]:
data = ["Dodgers lose again, give up 3 HRs in a loss to the Giants",
"Giants 5 Cardinals 4 final in extra innings",
"Dodgers drop Game 2 against the Giants, 5-4",
"Flyers 4 Lightning 1 final. 45 saves for the Lightning.",
"Slashing, penalty, 2 minute power play coming up",
"What a stick save!",
"Leads the NFL in sacks with 9.5",
"UCF 38 Temple 13",
"With the 30 yard completion, down to the 10 yard line",
"Drains the 3pt shot!!, 0:15 remaining in the game",
"Intercepted! Drives down the court and shoots for the win",
"Massive dunk!!! they are now up by 15 with 2 minutes to go"]
# List of labels
tags = ["Baseball", "Football", "Hockey", "Basketball"]
print("%-75s %s" % ("Text", "Label"))
print("-" * 100)
for text in data:
print("%-75s %s" % (text, tags[labels(text, tags)[0][0]]))Text Label ---------------------------------------------------------------------------------------------------- Dodgers lose again, give up 3 HRs in a loss to the Giants Baseball Giants 5 Cardinals 4 final in extra innings Baseball Dodgers drop Game 2 against the Giants, 5-4 Baseball Flyers 4 Lightning 1 final. 45 saves for the Lightning. Hockey Slashing, penalty, 2 minute power play coming up Hockey What a stick save! Hockey Leads the NFL in sacks with 9.5 Football UCF 38 Temple 13 Football With the 30 yard completion, down to the 10 yard line Football Drains the 3pt shot!!, 0:15 remaining in the game Basketball Intercepted! Drives down the court and shoots for the win Basketball Massive dunk!!! they are now up by 15 with 2 minutes to go Basketball
In [ ]:
tags = ["😀", "😡"]
print("%-75s %s" % ("Text", "Label"))
print("-" * 100)
for text in data:
print("%-75s %s" % (text, tags[labels(text, tags)[0][0]]))Text Label ---------------------------------------------------------------------------------------------------- Dodgers lose again, give up 3 HRs in a loss to the Giants 😡 Giants 5 Cardinals 4 final in extra innings 😀 Dodgers drop Game 2 against the Giants, 5-4 😡 Flyers 4 Lightning 1 final. 45 saves for the Lightning. 😀 Slashing, penalty, 2 minute power play coming up 😡 What a stick save! 😀 Leads the NFL in sacks with 9.5 😀 UCF 38 Temple 13 😀 With the 30 yard completion, down to the 10 yard line 😀 Drains the 3pt shot!!, 0:15 remaining in the game 😀 Intercepted! Drives down the court and shoots for the win 😀 Massive dunk!!! they are now up by 15 with 2 minutes to go 😀