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
Release v0.1
Browse files- LICENSE +201 -0
- NOTICE +42 -0
- README.md +123 -0
- cbx_config.json +29 -0
- cbx_sentiment.py +118 -0
- checksums.sha256 +13 -0
- config.json +59 -0
- example.py +16 -0
- model.safetensors +3 -0
- onnx/model.onnx +3 -0
- onnx_example.py +32 -0
- requirements.txt +3 -0
- tokenizer.json +0 -0
- tokenizer_config.json +13 -0
LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Apache License
|
| 2 |
+
Version 2.0, January 2004
|
| 3 |
+
http://www.apache.org/licenses/
|
| 4 |
+
|
| 5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 6 |
+
|
| 7 |
+
1. Definitions.
|
| 8 |
+
|
| 9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 11 |
+
|
| 12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 13 |
+
the copyright owner that is granting the License.
|
| 14 |
+
|
| 15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 16 |
+
other entities that control, are controlled by, or are under common
|
| 17 |
+
control with that entity. For the purposes of this definition,
|
| 18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 19 |
+
direction or management of such entity, whether by contract or
|
| 20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 22 |
+
|
| 23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 24 |
+
exercising permissions granted by this License.
|
| 25 |
+
|
| 26 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 27 |
+
including but not limited to software source code, documentation
|
| 28 |
+
source, and configuration files.
|
| 29 |
+
|
| 30 |
+
"Object" form shall mean any form resulting from mechanical
|
| 31 |
+
transformation or translation of a Source form, including but
|
| 32 |
+
not limited to compiled object code, generated documentation,
|
| 33 |
+
and conversions to other media types.
|
| 34 |
+
|
| 35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 36 |
+
Object form, made available under the License, as indicated by a
|
| 37 |
+
copyright notice that is included in or attached to the work
|
| 38 |
+
(an example is provided in the Appendix below).
|
| 39 |
+
|
| 40 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 41 |
+
form, that is based on (or derived from) the Work and for which the
|
| 42 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 43 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 44 |
+
of this License, Derivative Works shall not include works that remain
|
| 45 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 46 |
+
the Work and Derivative Works thereof.
|
| 47 |
+
|
| 48 |
+
"Contribution" shall mean any work of authorship, including
|
| 49 |
+
the original version of the Work and any modifications or additions
|
| 50 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 51 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 52 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 53 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 54 |
+
means any form of electronic, verbal, or written communication sent
|
| 55 |
+
to the Licensor or its representatives, including but not limited to
|
| 56 |
+
communication on electronic mailing lists, source code control systems,
|
| 57 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 58 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 59 |
+
excluding communication that is conspicuously marked or otherwise
|
| 60 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 61 |
+
|
| 62 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 63 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 64 |
+
subsequently incorporated within the Work.
|
| 65 |
+
|
| 66 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 67 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 68 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 69 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 70 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 71 |
+
Work and such Derivative Works in Source or Object form.
|
| 72 |
+
|
| 73 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 74 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 75 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 76 |
+
(except as stated in this section) patent license to make, have made,
|
| 77 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 78 |
+
where such license applies only to those patent claims licensable
|
| 79 |
+
by such Contributor that are necessarily infringed by their
|
| 80 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 81 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 82 |
+
institute patent litigation against any entity (including a
|
| 83 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 84 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 85 |
+
or contributory patent infringement, then any patent licenses
|
| 86 |
+
granted to You under this License for that Work shall terminate
|
| 87 |
+
as of the date such litigation is filed.
|
| 88 |
+
|
| 89 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 90 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 91 |
+
modifications, and in Source or Object form, provided that You
|
| 92 |
+
meet the following conditions:
|
| 93 |
+
|
| 94 |
+
(a) You must give any other recipients of the Work or
|
| 95 |
+
Derivative Works a copy of this License; and
|
| 96 |
+
|
| 97 |
+
(b) You must cause any modified files to carry prominent notices
|
| 98 |
+
stating that You changed the files; and
|
| 99 |
+
|
| 100 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 101 |
+
that You distribute, all copyright, patent, trademark, and
|
| 102 |
+
attribution notices from the Source form of the Work,
|
| 103 |
+
excluding those notices that do not pertain to any part of
|
| 104 |
+
the Derivative Works; and
|
| 105 |
+
|
| 106 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 107 |
+
distribution, then any Derivative Works that You distribute must
|
| 108 |
+
include a readable copy of the attribution notices contained
|
| 109 |
+
within such NOTICE file, excluding those notices that do not
|
| 110 |
+
pertain to any part of the Derivative Works, in at least one
|
| 111 |
+
of the following places: within a NOTICE text file distributed
|
| 112 |
+
as part of the Derivative Works; within the Source form or
|
| 113 |
+
documentation, if provided along with the Derivative Works; or,
|
| 114 |
+
within a display generated by the Derivative Works, if and
|
| 115 |
+
wherever such third-party notices normally appear. The contents
|
| 116 |
+
of the NOTICE file are for informational purposes only and
|
| 117 |
+
do not modify the License. You may add Your own attribution
|
| 118 |
+
notices within Derivative Works that You distribute, alongside
|
| 119 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 120 |
+
that such additional attribution notices cannot be construed
|
| 121 |
+
as modifying the License.
|
| 122 |
+
|
| 123 |
+
You may add Your own copyright statement to Your modifications and
|
| 124 |
+
may provide additional or different license terms and conditions
|
| 125 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 126 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 127 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 128 |
+
the conditions stated in this License.
|
| 129 |
+
|
| 130 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 131 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 132 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 133 |
+
this License, without any additional terms or conditions.
|
| 134 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 135 |
+
the terms of any separate license agreement you may have executed
|
| 136 |
+
with Licensor regarding such Contributions.
|
| 137 |
+
|
| 138 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 139 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 140 |
+
except as required for reasonable and customary use in describing the
|
| 141 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 142 |
+
|
| 143 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 144 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 145 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 146 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 147 |
+
implied, including, without limitation, any warranties or conditions
|
| 148 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 149 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 150 |
+
appropriateness of using or redistributing the Work and assume any
|
| 151 |
+
risks associated with Your exercise of permissions under this License.
|
| 152 |
+
|
| 153 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 154 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 155 |
+
unless required by applicable law (such as deliberate and grossly
|
| 156 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 157 |
+
liable to You for damages, including any direct, indirect, special,
|
| 158 |
+
incidental, or consequential damages of any character arising as a
|
| 159 |
+
result of this License or out of the use or inability to use the
|
| 160 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 161 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 162 |
+
other commercial damages or losses), even if such Contributor
|
| 163 |
+
has been advised of the possibility of such damages.
|
| 164 |
+
|
| 165 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 166 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 167 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 168 |
+
or other liability obligations and/or rights consistent with this
|
| 169 |
+
License. However, in accepting such obligations, You may act only
|
| 170 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 171 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 172 |
+
defend, and hold each Contributor harmless for any liability
|
| 173 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 174 |
+
of your accepting any such warranty or additional liability.
|
| 175 |
+
|
| 176 |
+
END OF TERMS AND CONDITIONS
|
| 177 |
+
|
| 178 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 179 |
+
|
| 180 |
+
To apply the Apache License to your work, attach the following
|
| 181 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 182 |
+
replaced with your own identifying information. (Don't include
|
| 183 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 184 |
+
comment syntax for the file format. We also recommend that a
|
| 185 |
+
file or class name and description of purpose be included on the
|
| 186 |
+
same "printed page" as the copyright notice for easier
|
| 187 |
+
identification within third-party archives.
|
| 188 |
+
|
| 189 |
+
Copyright [yyyy] [name of copyright owner]
|
| 190 |
+
|
| 191 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 192 |
+
you may not use this file except in compliance with the License.
|
| 193 |
+
You may obtain a copy of the License at
|
| 194 |
+
|
| 195 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 196 |
+
|
| 197 |
+
Unless required by applicable law or agreed to in writing, software
|
| 198 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 199 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 200 |
+
See the License for the specific language governing permissions and
|
| 201 |
+
limitations under the License.
|
NOTICE
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
cbx-indim-sentiment-classifier-32M
|
| 2 |
+
Copyright 2026 Cobuild Tech Private Limited.
|
| 3 |
+
|
| 4 |
+
Licensed under the Apache License, Version 2.0 (see LICENSE): the model weights, configuration, tokenizer, scripts
|
| 5 |
+
and documentation in this repository. Provided "as is", without warranties or conditions of any kind (LICENSE,
|
| 6 |
+
sections 7 and 8); see "Intended use and disclaimer" in README.md.
|
| 7 |
+
|
| 8 |
+
This model contains or was built from the following third-party materials:
|
| 9 |
+
|
| 10 |
+
1. InDIM-small (CobuildX-AI/InDIM-small), the base model, Apache-2.0, Cobuild Tech Private Limited. InDIM-small was
|
| 11 |
+
initialised from mmBERT (jhu-clsp/mmBERT-small). Copyright (c) 2025 the mmBERT authors (Marone, Weller, Fleshman,
|
| 12 |
+
Yang, Lawrie, Van Durme). MIT License:
|
| 13 |
+
|
| 14 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
| 15 |
+
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
| 16 |
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
| 17 |
+
persons to whom the Software is furnished to do so, subject to the following conditions:
|
| 18 |
+
|
| 19 |
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
| 20 |
+
Software.
|
| 21 |
+
|
| 22 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
| 23 |
+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
| 24 |
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
| 25 |
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
| 26 |
+
|
| 27 |
+
2. Text (not distributed in this repository). The model was trained and tested on text from these datasets, whose authors we thank and credit:
|
| 28 |
+
- Telugu_Sentiment, Marreddy et al. 2022 (te): https://huggingface.co/datasets/mounikaiiith/Telugu_Sentiment. Licence: CC BY 4.0. Used for: training and testing.
|
| 29 |
+
- XLM-T tweet_sentiment_multilingual, Barbieri et al. 2022 (en, hi): https://huggingface.co/datasets/cardiffnlp/tweet_sentiment_multilingual. Licence: CC BY 3.0 (tweets: X / Twitter terms). Used for: training and testing.
|
| 30 |
+
- Hinglish YouTube sentiments dataset (shae2977) (hi): https://huggingface.co/datasets/shae2977/hinglish-youtube-sentiments-dataset. Licence: CC BY 4.0. Used for: training and testing.
|
| 31 |
+
- Roman Urdu Data Set, Sharf 2018, UCI Machine Learning Repository (ur): https://archive.ics.uci.edu/dataset/458/roman+urdu+data+set. Licence: CC BY 4.0. Used for: training and testing.
|
| 32 |
+
- Assamese movie reviews sentiment, A. Dutta and S. Dutta (as): https://huggingface.co/datasets/AvinabhDutta-Dev/assamese-movie-reviews-sentiment. Licence: CC BY 4.0. Used for: training and testing.
|
| 33 |
+
- Bangla sentiment benchmark corpus, Sazzed 2021 (bn): https://huggingface.co/datasets/Akash190104/bengali_sentiment_analysis. Licence: CC BY 4.0. Used for: training and testing.
|
| 34 |
+
- Motamot (Bengali political sentiment), arXiv:2407.19528 (bn): https://huggingface.co/datasets/Mukaffi28/Motamot_Bengali_Political_Sentiment_Analysis. Licence: MIT. Used for: training.
|
| 35 |
+
- Sangraha, AI4Bharat (as, bn, en, gu, hi, kn, ml, mr, or, pa, ta, te, ur): https://huggingface.co/datasets/ai4bharat/sangraha. Licence: CC BY 4.0. Used for: training and testing.
|
| 36 |
+
- FineWeb-2, Hugging Face (as, bn, gu, hi, kn, ml, mr, or, pa, ta, te, ur): https://huggingface.co/datasets/HuggingFaceFW/fineweb-2. Licence: ODC-By 1.0. Used for: training and testing.
|
| 37 |
+
- DravidianCodeMix comments (OffensEval Dravidian), Chakravarthi et al. (kn, ml, ta): https://huggingface.co/datasets/community-datasets/offenseval_dravidian. Licence: CC BY 4.0. Used for: training and testing.
|
| 38 |
+
- Gujarati-English code-mixed comments (ShrutiPatel3011) (gu): https://huggingface.co/datasets/ShrutiPatel3011/gujarati-english-codemixed-sentiment. Licence: CC BY 4.0. Used for: training and testing.
|
| 39 |
+
- IndicSentiment, Doddapaneni et al. 2023 (IndicXTREME), AI4Bharat (as, bn, en, gu, hi, kn, ml, mr, or, pa, ta, te, ur): https://huggingface.co/datasets/ai4bharat/IndicSentiment. Licence: CC0 1.0. Used for: testing.
|
| 40 |
+
No dataset text is distributed with the model. Use of the model does not imply endorsement by any of these authors or publishers.
|
| 41 |
+
|
| 42 |
+
3. Labels. The training and test labels were produced by large language models: Gemma 4 31B (Apache-2.0), Claude Sonnet 5.5 (Anthropic) and gpt-5.4-mini (OpenAI). Part of the training text was generated by Gemma 4 31B and gpt-5.4-mini.
|
README.md
CHANGED
|
@@ -1,3 +1,126 @@
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
+
library_name: transformers
|
| 4 |
+
pipeline_tag: text-classification
|
| 5 |
+
base_model: CobuildX-AI/InDIM-small
|
| 6 |
+
language: [hi, bn, mr, ta, te, kn, ml, gu, pa, or, as, ur, en]
|
| 7 |
+
tags: [sentiment-analysis, indic, multilingual, code-mixed, romanized, text-classification, onnx]
|
| 8 |
---
|
| 9 |
+
|
| 10 |
+
# cbx-indim-sentiment-classifier-32M
|
| 11 |
+
|
| 12 |
+
A sentiment classifier for 12 Indian languages and English: Hindi, Bengali, Marathi, Tamil, Telugu, Kannada,
|
| 13 |
+
Malayalam, Gujarati, Punjabi, Odia, Assamese, Urdu and English, in native script, romanized or code-mixed. Give it a
|
| 14 |
+
comment, review, post or sentence and it returns `positive`, `negative` or `neutral`: the writer's own sentiment. It
|
| 15 |
+
is [InDIM-small (32M)](https://huggingface.co/CobuildX-AI/InDIM-small) fine-tuned for sentiment, and runs in a few
|
| 16 |
+
milliseconds on a CPU.
|
| 17 |
+
|
| 18 |
+
## Usage
|
| 19 |
+
|
| 20 |
+
```python
|
| 21 |
+
from cbx_sentiment import SentimentClassifier # cbx_sentiment.py is in this repository
|
| 22 |
+
|
| 23 |
+
clf = SentimentClassifier(".") # folder with the model files; CPU or GPU
|
| 24 |
+
clf.classify("Bahut badhiya phone hai, battery poora din chalti hai.")
|
| 25 |
+
# {"label": "positive", "scores": {"positive": 0.97, "negative": 0.02, "neutral": 0.01}, "truncated": False}
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
`python example.py` runs six examples; `python onnx_example.py` runs the same model with ONNX Runtime
|
| 29 |
+
(`onnx/model.onnx`, fp32, same decisions as PyTorch on 1,000 of 1,000 test texts).
|
| 30 |
+
|
| 31 |
+
```
|
| 32 |
+
positive 0.97 Bahut badhiya phone hai, battery poora din chalti hai.
|
| 33 |
+
negative 1.00 ডেলিভারি তিন দিন দেরিতে এসেছে, খুবই হতাশ।
|
| 34 |
+
neutral 1.00 நாளை காலை பத்து மணிக்கு கூட்டம் தொடங்கும்.
|
| 35 |
+
positive 1.00 ಈ ಸಿನಿಮಾ ತುಂಬಾ ಚೆನ್ನಾಗಿದೆ, ಎಲ್ಲರೂ ನೋಡಿ!
|
| 36 |
+
negative 1.00 yaar kya bakwaas movie thi, paisa barbaad
|
| 37 |
+
negative 0.98 Service was okay but the food was cold and overpriced.
|
| 38 |
+
```
|
| 39 |
+
|
| 40 |
+
## Labels
|
| 41 |
+
|
| 42 |
+
| Label | Meaning |
|
| 43 |
+
|---|---|
|
| 44 |
+
| `positive` | the writer expresses a favourable opinion or feeling: praise, liking, satisfaction, thanks, good wishes, excitement |
|
| 45 |
+
| `negative` | the writer expresses an unfavourable opinion or feeling: complaint, dislike, anger, sadness, disappointment, criticism, mockery |
|
| 46 |
+
| `neutral` | no opinion or feeling from the writer: facts, news reporting, announcements, questions, requests, instructions, ads without evaluation |
|
| 47 |
+
|
| 48 |
+
Sentiment is the writer's own stance, not the event: news that only reports a crime or good news is `neutral`.
|
| 49 |
+
Sarcasm takes its intended meaning, and a text with both polarities gets the one that dominates or is the writer's
|
| 50 |
+
conclusion, otherwise `neutral`.
|
| 51 |
+
|
| 52 |
+
## Results
|
| 53 |
+
|
| 54 |
+
Two test sets labelled by people (not used in training). Every model was fine-tuned with the same recipe and data
|
| 55 |
+
(plain fine-tuning, learning rate picked on validation); mean of 3 training runs ± SD unless marked.
|
| 56 |
+
|
| 57 |
+
- **IndicSentiment** ([AI4Bharat](https://huggingface.co/datasets/ai4bharat/IndicSentiment), CC0): 12,946 product
|
| 58 |
+
reviews in 13 languages, each positive or negative. Scored by comparing the `positive` and `negative` scores only
|
| 59 |
+
(two-way accuracy).
|
| 60 |
+
- **Source-labelled test:** 8,712 texts with their datasets' own labels: Telugu sentences (6,796), English tweets
|
| 61 |
+
(870) and romanized Hindi YouTube comments (1,046). Their labelling rules differ from ours, so every model scores
|
| 62 |
+
near 0.5 macro F1; read it for the order between models.
|
| 63 |
+
|
| 64 |
+
| Model | Parameters | IndicSentiment accuracy | Source-labelled macro F1 | English tweets | Romanized Hindi | Telugu |
|
| 65 |
+
|---|---|---|---|---|---|---|
|
| 66 |
+
| **InDIM-small (this model's base)** | **32M** | 0.822 ± 0.016 | 0.512 ± 0.005 | 0.640 | 0.560 | 0.443 |
|
| 67 |
+
| mmBERT-small | 140M | 0.839 ± 0.004 | 0.508 ± 0.015 | 0.706 | 0.565 | 0.415 |
|
| 68 |
+
| mmBERT-base (1 run) | 307M | 0.901 | 0.524 | 0.716 | 0.601 | 0.421 |
|
| 69 |
+
| IndicBERT v2 | 278M | **0.944 ± 0.003** | **0.547 ± 0.002** | 0.713 | 0.577 | **0.475** |
|
| 70 |
+
|
| 71 |
+
(The last three columns are macro F1 within each source.)
|
| 72 |
+
|
| 73 |
+
- This repository holds the training run with the best validation score: **IndicSentiment 0.811, source-labelled 0.518**.
|
| 74 |
+
- InDIM-small is level with mmBERT-small at a quarter of its size and better on Telugu; the larger models, especially
|
| 75 |
+
IndicBERT v2, are clearly better on IndicSentiment. Its weakest languages there are English, Hindi and Urdu.
|
| 76 |
+
|
| 77 |
+
**CPU latency** (Intel i7-10700, 8 threads, one text at a time, PyTorch fp32): 5.7 ms for a 15-token sentence,
|
| 78 |
+
22.8 ms for a long (about 200-word) input.
|
| 79 |
+
|
| 80 |
+
**Precision:** fp16 gives the same labels as fp32 on both test sets. PyTorch dynamic int8 (per-channel) keeps 95–97%
|
| 81 |
+
of labels unchanged; ONNX int8 changed 4% of decisions in our test, so only the fp32 ONNX file is provided.
|
| 82 |
+
|
| 83 |
+
## Input
|
| 84 |
+
|
| 85 |
+
- One comment, review, post or sentence. The model reads at most 256 tokens; longer text is cut
|
| 86 |
+
(`"truncated": True`).
|
| 87 |
+
- Native script, romanized and code-mixed text are all supported. The model judges the text alone: it does not see
|
| 88 |
+
the conversation or the post a comment replies to.
|
| 89 |
+
- If every text you score carries an opinion (for example product reviews with a star rating), compare only the
|
| 90 |
+
`positive` and `negative` scores, as in the IndicSentiment accuracy above.
|
| 91 |
+
|
| 92 |
+
## Limitations
|
| 93 |
+
|
| 94 |
+
- **Too many opinions are called neutral.** On IndicSentiment, where every review is positive or negative, a
|
| 95 |
+
three-way decision often says `neutral`. Compare `positive` and `negative` only if your texts always carry an
|
| 96 |
+
opinion.
|
| 97 |
+
- **Training labels come from LLMs**, following a written guide, not from people; data labelled under different
|
| 98 |
+
rules (for example, reported news as negative) will score lower.
|
| 99 |
+
- **Context:** sarcasm, irony, quotes and replies to content the model cannot see are often misread.
|
| 100 |
+
- **Bias:** errors are not spread evenly across languages, scripts, dialects or topics; political, religious and
|
| 101 |
+
community-related text may be judged less accurately.
|
| 102 |
+
|
| 103 |
+
## Intended use and disclaimer
|
| 104 |
+
|
| 105 |
+
**Intended use:** measuring and routing sentiment in text at scale, for example customer feedback, reviews, support
|
| 106 |
+
messages and social-media posts, where results are read in aggregate or checked by people. **Not intended** for
|
| 107 |
+
decisions about individual people (hiring, credit, moderation penalties, surveillance) without a person reviewing
|
| 108 |
+
each case. The model makes mistakes, more in some languages than others. It is provided "as is", without warranties
|
| 109 |
+
of any kind; Cobuild Tech Private Limited is not liable for its use. You are responsible for checking that it suits
|
| 110 |
+
your data and for complying with the laws that apply to your use.
|
| 111 |
+
|
| 112 |
+
## Training
|
| 113 |
+
|
| 114 |
+
[InDIM-small (32M)](https://huggingface.co/CobuildX-AI/InDIM-small) fine-tuned on about 63,000 texts in 13 languages
|
| 115 |
+
(social-media comments, tweets, reviews and web text, about 15% written by LLMs to fill gaps), labelled to the
|
| 116 |
+
guide above by LLMs (plain fine-tuning, learning rate 4e-4). The source datasets are credited in NOTICE.
|
| 117 |
+
|
| 118 |
+
## Citation
|
| 119 |
+
|
| 120 |
+
If you use this model, please cite [InDIM-small (32M)](https://huggingface.co/CobuildX-AI/InDIM-small#citation).
|
| 121 |
+
|
| 122 |
+
## Licence
|
| 123 |
+
|
| 124 |
+
Apache-2.0 (see LICENSE). Dataset credits and licences: see NOTICE.
|
| 125 |
+
|
| 126 |
+
Questions: hello@cobuildx.ai.
|
cbx_config.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "cbx-indim-sentiment-classifier-32M",
|
| 3 |
+
"labels": [
|
| 4 |
+
"positive",
|
| 5 |
+
"negative",
|
| 6 |
+
"neutral"
|
| 7 |
+
],
|
| 8 |
+
"max_len": 256,
|
| 9 |
+
"embedding_rank": 128,
|
| 10 |
+
"base_model": "CobuildX-AI/InDIM-small",
|
| 11 |
+
"parameters": 31492611,
|
| 12 |
+
"scores": {
|
| 13 |
+
"test_indicsentiment": {
|
| 14 |
+
"n": 12946,
|
| 15 |
+
"binary_acc": 0.8109,
|
| 16 |
+
"macro_f1": 0.5806
|
| 17 |
+
},
|
| 18 |
+
"test_source": {
|
| 19 |
+
"n": 8712,
|
| 20 |
+
"macro_f1": 0.5183
|
| 21 |
+
}
|
| 22 |
+
},
|
| 23 |
+
"cpu_latency_ms": {
|
| 24 |
+
"threads": 8,
|
| 25 |
+
"short_tokens": 15,
|
| 26 |
+
"short_ms": 5.681210499460576,
|
| 27 |
+
"long_ms": 22.758636499929707
|
| 28 |
+
}
|
| 29 |
+
}
|
cbx_sentiment.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2026 Cobuild Tech Private Limited
|
| 2 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 3 |
+
"""InDIM sentiment classifier: a text in, positive / negative / neutral out.
|
| 4 |
+
|
| 5 |
+
from cbx_sentiment import SentimentClassifier
|
| 6 |
+
clf = SentimentClassifier(".") # folder with the model files; CPU or GPU
|
| 7 |
+
clf.classify("Bahut badhiya phone hai, battery poora din chalti hai.")
|
| 8 |
+
|
| 9 |
+
`classify` takes one text (returns one result) or a list (returns a list). A result:
|
| 10 |
+
|
| 11 |
+
{"label": "positive", "scores": {"positive": 0.9, "negative": 0.01, "neutral": 0.02}, "truncated": False}
|
| 12 |
+
|
| 13 |
+
"label" is the label with the highest score, unless cbx_config.json has a "decision" rule: then the first label in
|
| 14 |
+
the rule whose score reaches its threshold wins, otherwise the rule's fallback label (thresholds tuned on validation;
|
| 15 |
+
see the model card). When cbx_config.json lists "operating_points" (named rules), pick one with
|
| 16 |
+
`SentimentClassifier(".", operating_point="<name>")` or `clf.use_operating_point("<name>")`; the default is "decision". "scores" are softmax probabilities that sum to 1. The model reads at most 256 tokens;
|
| 17 |
+
longer text is cut ("truncated": True).
|
| 18 |
+
"""
|
| 19 |
+
import json
|
| 20 |
+
from pathlib import Path
|
| 21 |
+
|
| 22 |
+
import torch
|
| 23 |
+
import torch.nn as nn
|
| 24 |
+
from safetensors.torch import load_file
|
| 25 |
+
from transformers import AutoConfig, AutoModel, AutoTokenizer
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
class _Net(nn.Module):
|
| 29 |
+
def __init__(self, path, cfg):
|
| 30 |
+
super().__init__()
|
| 31 |
+
self.backbone = AutoModel.from_config(AutoConfig.from_pretrained(path), attn_implementation="sdpa")
|
| 32 |
+
h = self.backbone.config.hidden_size
|
| 33 |
+
if cfg.get("embedding_rank"): # factorised word table (smaller sizes)
|
| 34 |
+
self.backbone.embeddings.tok_embeddings = nn.Sequential(
|
| 35 |
+
nn.Embedding(self.backbone.config.vocab_size, cfg["embedding_rank"]),
|
| 36 |
+
nn.Linear(cfg["embedding_rank"], h, bias=False))
|
| 37 |
+
self.head = nn.Linear(h, len(cfg["labels"]))
|
| 38 |
+
|
| 39 |
+
def forward(self, input_ids, attention_mask):
|
| 40 |
+
hs = self.backbone(input_ids=input_ids, attention_mask=attention_mask).last_hidden_state.float()
|
| 41 |
+
m = attention_mask.unsqueeze(-1).float()
|
| 42 |
+
return self.head((hs[:, 0] + (hs * m).sum(1) / m.sum(1).clamp(min=1)) / 2)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
class SentimentClassifier:
|
| 46 |
+
def __init__(self, path=".", device=None, operating_point=None):
|
| 47 |
+
path = Path(path)
|
| 48 |
+
self.cfg = json.loads((path / "cbx_config.json").read_text())
|
| 49 |
+
if operating_point is not None:
|
| 50 |
+
self.use_operating_point(operating_point)
|
| 51 |
+
self.labels = self.cfg["labels"]
|
| 52 |
+
self.max_len = self.cfg["max_len"]
|
| 53 |
+
self.device = device or ("cuda" if torch.cuda.is_available() else "cpu")
|
| 54 |
+
self.tok = AutoTokenizer.from_pretrained(path)
|
| 55 |
+
self.net = _Net(path, self.cfg)
|
| 56 |
+
self.net.load_state_dict(load_file(str(path / "model.safetensors")))
|
| 57 |
+
self.net.to(self.device).eval()
|
| 58 |
+
|
| 59 |
+
@torch.inference_mode()
|
| 60 |
+
def logits(self, texts, max_tokens=16384):
|
| 61 |
+
"""Raw logits [n][labels] in input order, and a truncated flag per text."""
|
| 62 |
+
texts = list(texts)
|
| 63 |
+
full = [len(x) for x in self.tok(texts, verbose=False)["input_ids"]]
|
| 64 |
+
enc = self.tok(texts, truncation=True, max_length=self.max_len, verbose=False)["input_ids"]
|
| 65 |
+
out = [None] * len(enc)
|
| 66 |
+
order = sorted(range(len(enc)), key=lambda i: len(enc[i]))
|
| 67 |
+
i = 0
|
| 68 |
+
while i < len(order):
|
| 69 |
+
j, n = i, 0
|
| 70 |
+
while j < len(order) and (j - i + 1) * max(n, len(enc[order[j]])) <= max_tokens:
|
| 71 |
+
n = max(n, len(enc[order[j]]))
|
| 72 |
+
j += 1
|
| 73 |
+
j = max(j, i + 1)
|
| 74 |
+
idx = order[i:j]
|
| 75 |
+
n = max(len(enc[k]) for k in idx)
|
| 76 |
+
ids = torch.full((len(idx), n), self.tok.pad_token_id, dtype=torch.long)
|
| 77 |
+
mask = torch.zeros((len(idx), n), dtype=torch.long)
|
| 78 |
+
for r, k in enumerate(idx):
|
| 79 |
+
ids[r, :len(enc[k])] = torch.tensor(enc[k])
|
| 80 |
+
mask[r, :len(enc[k])] = 1
|
| 81 |
+
lg = self.net(ids.to(self.device), mask.to(self.device)).float().cpu().tolist()
|
| 82 |
+
for r, k in enumerate(idx):
|
| 83 |
+
out[k] = lg[r]
|
| 84 |
+
i = j
|
| 85 |
+
return out, [f > self.max_len for f in full]
|
| 86 |
+
|
| 87 |
+
def use_operating_point(self, name):
|
| 88 |
+
"""Switch the decision rule to a named operating point from cbx_config.json (see the model card)."""
|
| 89 |
+
pts = self.cfg.get("operating_points") or {}
|
| 90 |
+
if name not in pts:
|
| 91 |
+
raise ValueError(f"unknown operating point {name!r}; available: {sorted(pts)}")
|
| 92 |
+
self.cfg["decision"] = {**pts[name], "operating_point": name}
|
| 93 |
+
|
| 94 |
+
def decide(self, probs):
|
| 95 |
+
"""Label indices from probability rows: the decision rule if the config has one, else the argmax."""
|
| 96 |
+
rule = (self.cfg.get("decision") or {}).get("rule")
|
| 97 |
+
out = []
|
| 98 |
+
for p in probs:
|
| 99 |
+
k = max(range(len(p)), key=p.__getitem__)
|
| 100 |
+
if rule:
|
| 101 |
+
k = self.labels.index(self.cfg["decision"]["fallback"])
|
| 102 |
+
for lab, t in rule:
|
| 103 |
+
if p[self.labels.index(lab)] >= t:
|
| 104 |
+
k = self.labels.index(lab)
|
| 105 |
+
break
|
| 106 |
+
out.append(k)
|
| 107 |
+
return out
|
| 108 |
+
|
| 109 |
+
def classify(self, texts):
|
| 110 |
+
single = isinstance(texts, str)
|
| 111 |
+
texts = [texts] if single else list(texts)
|
| 112 |
+
lg, tr = self.logits(texts)
|
| 113 |
+
out = []
|
| 114 |
+
probs = [torch.softmax(torch.tensor(row), -1).tolist() for row in lg]
|
| 115 |
+
for p, k, t in zip(probs, self.decide(probs), tr):
|
| 116 |
+
out.append({"label": self.labels[k], "scores": {l: round(v, 4) for l, v in zip(self.labels, p)},
|
| 117 |
+
"truncated": t})
|
| 118 |
+
return out[0] if single else out
|
checksums.sha256
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4 LICENSE
|
| 2 |
+
35d6eef775de1db0f92718f173d53c7dd2d1507e7424f5251a0c748f7d6273c7 NOTICE
|
| 3 |
+
7112cfc7fdb30dee9f43d75902d4312a7e52a6b7642d4957b9926e66cc4a87d5 README.md
|
| 4 |
+
9840d46cc00e907b8e3c92e2ea5204cab81924725aed11b48f644d8046bdbcbc cbx_config.json
|
| 5 |
+
7c687a72884392b4a5f9321d586eea761141ac5f168f16ee01e9b54cc8892011 cbx_sentiment.py
|
| 6 |
+
2b1b954c9e4deb6349c707a724531bacb8f3817014de935c4bd4e9b46a621bb4 config.json
|
| 7 |
+
abdd50a6bad7fdbd57f143184ae2612a328daf98db3ec9e406229f3b3dbbfc80 example.py
|
| 8 |
+
bc6b9e7d55ee57807036bbfb35f82cd7f76c251ccd4454935e2ebde65d1c2b24 model.safetensors
|
| 9 |
+
e4173bb4c3707420205eaaef72ddf179a146abda13bb24eac26793635d1f792c onnx/model.onnx
|
| 10 |
+
a350d86a45e95a438221db853aee5629cd84eb76c1be9361069ecd200497aff4 onnx_example.py
|
| 11 |
+
ee71b13268fabbacc0925339898205f92239cf331d3c54ec1f7008f8587bab6f requirements.txt
|
| 12 |
+
6c824bf98fe6cb6fc717df2db1fc2cb34837b54175b019fdcc9a182f7ab22d71 tokenizer.json
|
| 13 |
+
95d62f60e61c040fb37f731c8cf6f83cd315faa9f25f7818cb1860896eb0612c tokenizer_config.json
|
config.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"attention_bias": false,
|
| 3 |
+
"attention_dropout": 0.0,
|
| 4 |
+
"bos_token_id": null,
|
| 5 |
+
"classifier_activation": "gelu",
|
| 6 |
+
"classifier_bias": false,
|
| 7 |
+
"classifier_dropout": 0.0,
|
| 8 |
+
"classifier_pooling": "cls",
|
| 9 |
+
"cls_token_id": null,
|
| 10 |
+
"decoder_bias": true,
|
| 11 |
+
"deterministic_flash_attn": false,
|
| 12 |
+
"embedding_dropout": 0.0,
|
| 13 |
+
"eos_token_id": null,
|
| 14 |
+
"hidden_activation": "gelu",
|
| 15 |
+
"hidden_size": 384,
|
| 16 |
+
"initializer_cutoff_factor": 2.0,
|
| 17 |
+
"initializer_range": 0.02,
|
| 18 |
+
"intermediate_size": 576,
|
| 19 |
+
"layer_types": [
|
| 20 |
+
"full_attention",
|
| 21 |
+
"sliding_attention",
|
| 22 |
+
"sliding_attention",
|
| 23 |
+
"full_attention",
|
| 24 |
+
"sliding_attention",
|
| 25 |
+
"sliding_attention",
|
| 26 |
+
"full_attention",
|
| 27 |
+
"sliding_attention",
|
| 28 |
+
"sliding_attention",
|
| 29 |
+
"full_attention",
|
| 30 |
+
"sliding_attention",
|
| 31 |
+
"sliding_attention"
|
| 32 |
+
],
|
| 33 |
+
"local_attention": 128,
|
| 34 |
+
"max_position_embeddings": 8192,
|
| 35 |
+
"mlp_bias": false,
|
| 36 |
+
"mlp_dropout": 0.0,
|
| 37 |
+
"model_type": "modernbert",
|
| 38 |
+
"norm_bias": false,
|
| 39 |
+
"norm_eps": 1e-05,
|
| 40 |
+
"num_attention_heads": 6,
|
| 41 |
+
"num_hidden_layers": 12,
|
| 42 |
+
"pad_token_id": 128000,
|
| 43 |
+
"rope_parameters": {
|
| 44 |
+
"full_attention": {
|
| 45 |
+
"rope_theta": 160000.0,
|
| 46 |
+
"rope_type": "default"
|
| 47 |
+
},
|
| 48 |
+
"sliding_attention": {
|
| 49 |
+
"rope_theta": 160000.0,
|
| 50 |
+
"rope_type": "default"
|
| 51 |
+
}
|
| 52 |
+
},
|
| 53 |
+
"sep_token_id": null,
|
| 54 |
+
"sparse_pred_ignore_index": -100,
|
| 55 |
+
"sparse_prediction": false,
|
| 56 |
+
"tie_word_embeddings": true,
|
| 57 |
+
"transformers_version": "5.23.0",
|
| 58 |
+
"vocab_size": 128064
|
| 59 |
+
}
|
example.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2026 Cobuild Tech Private Limited
|
| 2 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 3 |
+
"""Run from the model folder: python example.py (every text below is invented for this example)"""
|
| 4 |
+
from cbx_sentiment import SentimentClassifier
|
| 5 |
+
|
| 6 |
+
clf = SentimentClassifier(".")
|
| 7 |
+
texts = [
|
| 8 |
+
"Bahut badhiya phone hai, battery poora din chalti hai.", # romanized Hindi: great phone, the battery lasts all day
|
| 9 |
+
"ডেলিভারি তিন দিন দেরিতে এসেছে, খুবই হতাশ।", # Bengali: delivery came three days late, very disappointed
|
| 10 |
+
"நாளை காலை பத்து மணிக்கு கூட்டம் தொடங்கும்.", # Tamil: the meeting starts at ten tomorrow morning
|
| 11 |
+
"ಈ ಸಿನಿಮಾ ತುಂಬಾ ಚೆನ್ನಾಗಿದೆ, ಎಲ್ಲರೂ ನೋಡಿ!", # Kannada: this film is very good, everyone watch it
|
| 12 |
+
"yaar kya bakwaas movie thi, paisa barbaad", # romanized Hindi: what a rubbish film, money wasted
|
| 13 |
+
"Service was okay but the food was cold and overpriced.",
|
| 14 |
+
]
|
| 15 |
+
for text, r in zip(texts, clf.classify(texts)):
|
| 16 |
+
print(f"{r['label']:<9} {max(r['scores'].values()):.2f} {' '.join(text.split())}")
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bc6b9e7d55ee57807036bbfb35f82cd7f76c251ccd4454935e2ebde65d1c2b24
|
| 3 |
+
size 125978452
|
onnx/model.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e4173bb4c3707420205eaaef72ddf179a146abda13bb24eac26793635d1f792c
|
| 3 |
+
size 126034271
|
onnx_example.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Run the model with ONNX Runtime instead of PyTorch (CPU).
|
| 2 |
+
|
| 3 |
+
pip install onnxruntime
|
| 4 |
+
python onnx_example.py
|
| 5 |
+
|
| 6 |
+
onnx/model.onnx takes `input_ids` and `attention_mask` [batch, length] and returns the logits [batch, labels].
|
| 7 |
+
SentimentClassifier still does the tokenisation and the decision; only the network call changes.
|
| 8 |
+
"""
|
| 9 |
+
import os
|
| 10 |
+
|
| 11 |
+
import numpy as np
|
| 12 |
+
import onnxruntime as ort
|
| 13 |
+
import torch
|
| 14 |
+
|
| 15 |
+
from cbx_sentiment import SentimentClassifier
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class OnnxNet:
|
| 19 |
+
def __init__(self, file):
|
| 20 |
+
self.sess = ort.InferenceSession(file, providers=["CPUExecutionProvider"])
|
| 21 |
+
|
| 22 |
+
def __call__(self, input_ids, attention_mask):
|
| 23 |
+
out = self.sess.run(None, {"input_ids": input_ids.cpu().numpy().astype(np.int64),
|
| 24 |
+
"attention_mask": attention_mask.cpu().numpy().astype(np.int64)})[0]
|
| 25 |
+
return torch.from_numpy(out)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
here = os.path.dirname(os.path.abspath(__file__))
|
| 29 |
+
name = "model.onnx"
|
| 30 |
+
clf = SentimentClassifier(here, device="cpu")
|
| 31 |
+
clf.net = OnnxNet(os.path.join(here, "onnx", name))
|
| 32 |
+
print(clf.classify('Bahut badhiya phone hai, battery poora din chalti hai.'))
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch>=2.4
|
| 2 |
+
transformers>=5.0
|
| 3 |
+
safetensors>=0.4
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"backend": "tokenizers",
|
| 3 |
+
"clean_up_tokenization_spaces": false,
|
| 4 |
+
"cls_token": "[CLS]",
|
| 5 |
+
"is_local": true,
|
| 6 |
+
"local_files_only": false,
|
| 7 |
+
"mask_token": "[MASK]",
|
| 8 |
+
"model_max_length": 8192,
|
| 9 |
+
"pad_token": "[PAD]",
|
| 10 |
+
"sep_token": "[SEP]",
|
| 11 |
+
"tokenizer_class": "TokenizersBackend",
|
| 12 |
+
"unk_token": "<unk>"
|
| 13 |
+
}
|