-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathlabels.rs
More file actions
46 lines (36 loc) 路 1.7 KB
/
Copy pathlabels.rs
File metadata and controls
46 lines (36 loc) 路 1.7 KB
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
use std::error::Error;
use txtai::labels::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
pub async fn labels() -> Result<(), Box<dyn Error>> {
let labels = Labels::with_url("http://localhost:8000");
let 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"];
println!("{:<75} {}", "Text", "Label");
println!("{}", "-".repeat(100));
for text in data.iter() {
let tags = vec!["Baseball", "Football", "Hockey", "Basketball"];
let label = labels.label(text, &tags.to_vec()).await?[0].id;
println!("{:<75} {}", text, tags[label]);
}
println!("");
println!("{:<75} {}", "Text", "Label");
println!("{}", "-".repeat(100));
for text in data.iter() {
let tags = vec!["馃榾", "馃槨"];
let label = labels.label(text, &tags).await?[0].id;
println!("{:<75} {}", text, tags[label]);
}
Ok(())
}