Views
No views yet
1
2from model import PolyEncoderModel
3
4texts = [
5 "The wildlife conservation program is focused on protecting endangered species in Africa.",
6 "The government announced a new initiative to combat poverty in rural areas.",
7 "A celebrity chef has opened a new restaurant specializing in vegan cuisine."
8 ]
9batch_labels = [
10
11 ["Conservation", "Business", "Animals", "Africa"],
12 ["Politics", "Social Issues", "Economy", "Technolgy"],
13 ["Food", "Business","Politics", "Vegan"]
14
15 ]
16# Load the model
17model = CrossEncoderModel("sabdou/poly-encoder-model", max_num_labels=6)
18# Prediction with JSON output
19predictions = model.forward_predict(texts, batch_labels)
20print("Predictions:", predictions)
21Predictions: [
{'text': 'The wildlife conservation program is focused on protecting endangered species in Africa.',
'scores': {'Conservation': 1.0,
'Business': 0.0,
'Animals': 1.0,
'Africa': 0.99}},
{'text': 'The government announced a new initiative to combat poverty in rural areas.',
'scores': {'Politics': 1.0,
'Social Issues': 0.99,
'Economy': 1.0,
'Technolgy': 0.0}},
{'text': 'A celebrity chef has opened a new restaurant specializing in vegan cuisine.',
'scores': {'Food': 1.0,
'Business': 1.0,
'Politics': 0.0,
'Vegan': 1.0}}]