-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path05_general_use_zero_short.py
30 lines (26 loc) · 1.33 KB
/
05_general_use_zero_short.py
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
# libs
"""
https://huggingface.co/models?pipeline_tag=text-classification&sort=trending
%pip install torch transformers --quiet
%pip install --upgrade jupyter ipywidgets --quiet
%pip install --upgrade tqdm --quiet
%pip install pandas
"""
from transformers import pipeline
# Inicializar o pipeline de zero-shot classification
classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
# Descrição do produto
descricao_produto = "The Samsung Galaxy S24 is an advanced and comprehensive Android smartphone across the board\
view with some excellent features. It has a large 6.2-inch screen with a resolution\
2340x1080 pixels. The features offered by the Samsung Galaxy S24 are many and innovative. \
Starting with 5G, which allows data transfer and excellent internet browsing."
# Categorias disponíveis
categories = ["Clothes", "Electronics", "Home Accessories"]
# Classificar a descrição do produto nas categorias disponíveis
resultado = classifier(descricao_produto, candidate_labels=categories)
# Imprimir os resultados
print("Descrição do Produto:", descricao_produto)
print("Categorias Disponíveis:", categories)
print("Classificação Resultante:")
for label, score in zip(resultado['labels'], resultado['scores']):
print(f" - {label}: {score:.3f}")