-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlabels.go
49 lines (40 loc) · 1.58 KB
/
labels.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Example labels functionality.
//
// Implements logic found in this notebook: https://github.com/neuml/txtai/blob/master/examples/07_Apply_labels_with_zero_shot_classification.ipynb
package main
import (
"fmt"
"strings"
"github.com/neuml/txtai.go"
)
func main() {
labels := txtai.Labels("http://localhost:8000")
data := []string{"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 := []string{"Baseball", "Football", "Hockey", "Basketball"}
fmt.Printf("%-75s %s\n", "Text", "Label")
fmt.Println(strings.Repeat("-", 100))
for _, text := range data {
label := labels.Label(text, tags)
fmt.Printf("%-75s %s\n", text, tags[label[0].Id])
}
fmt.Println()
fmt.Printf("%-75s %s\n", "Text", "Label")
fmt.Println(strings.Repeat("-", 100))
tags = []string{"😀", "😡"}
for _, text := range data {
label := labels.Label(text, tags)
fmt.Printf("%-75s %s\n", text, tags[label[0].Id])
}
}