Text Classification
Transformers
TensorBoard
Safetensors
distilbert
Generated from Trainer
text-embeddings-inference
Instructions to use AndresR2909/finetuning_bert_text_classification with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use AndresR2909/finetuning_bert_text_classification with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="AndresR2909/finetuning_bert_text_classification")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("AndresR2909/finetuning_bert_text_classification") model = AutoModelForSequenceClassification.from_pretrained("AndresR2909/finetuning_bert_text_classification", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download handler.py from AndresR2909/finetuning_bert_text_classification: direct link, hf CLI and curl.
- Browser
- Download file 1.81 kB
-
https://huggingface.co/AndresR2909/finetuning_bert_text_classification/resolve/main/handler.py
- Command line
-
hf download hf://AndresR2909/finetuning_bert_text_classification/handler.py
-
curl -L -o handler.py https://huggingface.co/AndresR2909/finetuning_bert_text_classification/resolve/main/handler.py
1.81 kB
| from typing import Dict, List, Any | |
| from transformers import pipeline | |
| import logging | |
| # Configuración básica del logging | |
| logging.basicConfig(level=logging.INFO) | |
| logger = logging.getLogger(__name__) | |
| class EndpointHandler(): | |
| def __init__(self, path=""): | |
| logger.info(f"Modelo cargado desde el path: {path}") | |
| # Cargar el pipeline con el modelo especificado | |
| try: | |
| self.pipeline = pipeline(model=path, truncation=True) | |
| except Exception as e: | |
| logger.exception(f"Error cargando el modelo desde el path {path}: {e}") | |
| path = "AndresR2909/finetuning-bert-text-classification" | |
| self.pipeline = pipeline(model=path, truncation=True) | |
| def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]: | |
| """ | |
| data args: | |
| inputs (:obj: `str`) | |
| date (:obj: `str`) | |
| Return: | |
| A :obj:`list` | `dict`: will be serialized and returned | |
| """ | |
| # get inputs | |
| input = data.get("inputs",data) | |
| date = data.get("date", None) | |
| # Textos para análisis | |
| texts = [input] | |
| # Realizar la inferencia | |
| outputs = self.pipeline(texts) | |
| # Ajustar las etiquetas a 0 y 1 | |
| label_mapping = {"LABEL_0": 0, "LABEL_1": 1} | |
| label_names = {0: "sin_intencion", 1: "intencion_suicida"} | |
| # Modificar las salidas con el formato deseado | |
| adjusted_results = [ | |
| { | |
| "input": text, | |
| "clasiffication": str(label_mapping[result['label']]), # "clasiffication" como string | |
| "label": label_names[label_mapping[result['label']]] # Mapeo de etiquetas a nombres | |
| } | |
| for result, text in zip(outputs, texts) | |
| ] | |
| return adjusted_results |