Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
58 lines (49 loc) · 2.38 KB

File metadata and controls

58 lines (49 loc) · 2.38 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
50
51
52
53
54
55
56
57
58
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import txtai.API.IndexResult;
import txtai.Labels;
/**
* 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
*/
public class LabelsDemo {
public static void main(String[] args) {
try {
Labels labels = new Labels("http://localhost:8000");
List <String> data =
Arrays.asList("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
List<String> tags = Arrays.asList("Baseball", "Football", "Hockey", "Basketball");
System.out.printf("%-75s %s%n", "Text", "Label");
System.out.println(new String(new char[100]).replace("\0", "-"));
for (String text: data) {
List<IndexResult> label = labels.label(text, tags);
System.out.printf("%-75s %s%n", text, tags.get(label.get(0).id));
}
System.out.println();
System.out.printf("%-75s %s%n", "Text", "Label");
System.out.println(new String(new char[100]).replace("\0", "-"));
tags = Arrays.asList("😀", "😡");
for (String text: data) {
List<IndexResult> label = labels.label(text, tags);
System.out.printf("%-75s %s%n", text, tags.get(label.get(0).id));
}
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.