Update README.md
Browse files
README.md
CHANGED
|
@@ -77,25 +77,27 @@ El modelo fue evaluado en un conjunto de datos balanceado con 1000 muestras para
|
|
| 77 |
## Uso
|
| 78 |
|
| 79 |
```python
|
| 80 |
-
from transformers import
|
| 81 |
-
import torch
|
| 82 |
|
| 83 |
-
#
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
-
#
|
| 88 |
texto = "Este producto superó mis expectativas, lo recomiendo totalmente."
|
| 89 |
-
inputs = tokenizer(texto, return_tensors="pt", padding=True, truncation=True, max_length=512)
|
| 90 |
|
| 91 |
-
# Realizar
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
|
|
|
|
|
|
| 96 |
|
| 97 |
-
# La clase predicha será un número del 0 al 4, que corresponde a 1-5 estrellas
|
| 98 |
-
estrellas_predichas = predicted_class + 1
|
| 99 |
print(f"Predicción: {estrellas_predichas} estrellas")
|
| 100 |
```
|
| 101 |
|
|
|
|
| 77 |
## Uso
|
| 78 |
|
| 79 |
```python
|
| 80 |
+
from transformers import pipeline
|
|
|
|
| 81 |
|
| 82 |
+
# Crear el pipeline de clasificación
|
| 83 |
+
clasificador = pipeline(
|
| 84 |
+
"text-classification",
|
| 85 |
+
model="polodealvarado/distilbert-review_classification",
|
| 86 |
+
tokenizer="polodealvarado/distilbert-review_classification",
|
| 87 |
+
top_k=1, # Solo la clase más probable
|
| 88 |
+
)
|
| 89 |
|
| 90 |
+
# Texto de entrada
|
| 91 |
texto = "Este producto superó mis expectativas, lo recomiendo totalmente."
|
|
|
|
| 92 |
|
| 93 |
+
# Realizar predicción
|
| 94 |
+
output = clasificador(texto)
|
| 95 |
+
|
| 96 |
+
# Extraer la clase predicha (por ejemplo, 'LABEL_0', 'LABEL_1', ...)
|
| 97 |
+
etiqueta = output[0][0]["label"]
|
| 98 |
+
indice = int(etiqueta.replace("LABEL_", "")) # 'LABEL_0' → 0
|
| 99 |
+
estrellas_predichas = indice + 1
|
| 100 |
|
|
|
|
|
|
|
| 101 |
print(f"Predicción: {estrellas_predichas} estrellas")
|
| 102 |
```
|
| 103 |
|