-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01_general_use.py
41 lines (35 loc) · 1.2 KB
/
01_general_use.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
31
32
33
34
35
36
37
38
39
40
41
# 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
import warnings
import pandas as pd
warnings.filterwarnings("ignore")
# usando o modelo pré treinado de classificacao
#step 1
v_pipe = pipeline(task="text-classification")
# Lendo com pipe
review = "Adorei o produto, otimo custo beneficio."
v_pipe(review)
#step 2
# add model from https://huggingface.co/models?pipeline_tag=text-classification&sort=trending
classifier = pipeline(task="text-classification",
model="nlptown/bert-base-multilingual-uncased-sentiment")
# utilizando com uma unica string
review_hate = "odiei o produto, pessimo custo beneficio."
classifier(review_hate)
# usando lista
list_of_review = [review, review_hate]
list_of_review_class = classifier(list_of_review)
# Criando um DataFrame com os resultados
df_output = pd.DataFrame({
"Review": list_of_review,
"Label": [item['label'] for item in list_of_review_class],
"Score": [item['score'] for item in list_of_review_class]
})
print(df_output)