Text Classification
Transformers
ONNX
Safetensors
modernbert
sentiment-analysis
indic
multilingual
code-mixed
romanized
text-embeddings-inference
Instructions to use CobuildX-AI/cbx-indim-sentiment-classifier-32M with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use CobuildX-AI/cbx-indim-sentiment-classifier-32M with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="CobuildX-AI/cbx-indim-sentiment-classifier-32M")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("CobuildX-AI/cbx-indim-sentiment-classifier-32M", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download onnx_example.py from CobuildX-AI/cbx-indim-sentiment-classifier-32M: direct link, hf CLI and curl.
- Browser
- Download file 1.11 kB
-
https://huggingface.co/CobuildX-AI/cbx-indim-sentiment-classifier-32M/resolve/main/onnx_example.py
- Command line
-
hf download hf://CobuildX-AI/cbx-indim-sentiment-classifier-32M/onnx_example.py
-
curl -L -o onnx_example.py https://huggingface.co/CobuildX-AI/cbx-indim-sentiment-classifier-32M/resolve/main/onnx_example.py
1.11 kB
| """Run the model with ONNX Runtime instead of PyTorch (CPU). | |
| pip install onnxruntime | |
| python onnx_example.py | |
| onnx/model.onnx takes `input_ids` and `attention_mask` [batch, length] and returns the logits [batch, labels]. | |
| SentimentClassifier still does the tokenisation and the decision; only the network call changes. | |
| """ | |
| import os | |
| import numpy as np | |
| import onnxruntime as ort | |
| import torch | |
| from cbx_sentiment import SentimentClassifier | |
| class OnnxNet: | |
| def __init__(self, file): | |
| self.sess = ort.InferenceSession(file, providers=["CPUExecutionProvider"]) | |
| def __call__(self, input_ids, attention_mask): | |
| out = self.sess.run(None, {"input_ids": input_ids.cpu().numpy().astype(np.int64), | |
| "attention_mask": attention_mask.cpu().numpy().astype(np.int64)})[0] | |
| return torch.from_numpy(out) | |
| here = os.path.dirname(os.path.abspath(__file__)) | |
| name = "model.onnx" | |
| clf = SentimentClassifier(here, device="cpu") | |
| clf.net = OnnxNet(os.path.join(here, "onnx", name)) | |
| print(clf.classify('Bahut badhiya phone hai, battery poora din chalti hai.')) | |