Text Classification
Transformers
Safetensors
modernbert
fill-mask
sentiment-analysis
indic
multilingual
code-mixed
romanized
text-embeddings-inference
Instructions to use CobuildX-AI/cbx-indic-sentiment-classifier-36M with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use CobuildX-AI/cbx-indic-sentiment-classifier-36M with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="CobuildX-AI/cbx-indic-sentiment-classifier-36M")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForMaskedLM tokenizer = AutoTokenizer.from_pretrained("CobuildX-AI/cbx-indic-sentiment-classifier-36M") model = AutoModelForMaskedLM.from_pretrained("CobuildX-AI/cbx-indic-sentiment-classifier-36M", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Release v0.1
Browse files- LICENSE +201 -0
- NOTICE +38 -0
- README.md +150 -0
- cbx_config.json +35 -0
- cbx_sentiment.py +91 -0
- checksums.sha256 +11 -0
- config.json +67 -0
- example.py +17 -0
- model.safetensors +3 -0
- requirements.txt +3 -0
- tokenizer.json +0 -0
- tokenizer_config.json +29 -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,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
cbx-indic-sentiment-classifier-36M
|
| 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 and documentation in this repository. Provided "as is", without warranties or conditions of any kind (LICENSE, sections 7 and 8); see "Intended use and disclaimer" in README.md.
|
| 5 |
+
|
| 6 |
+
This model contains or was built from the following third-party materials:
|
| 7 |
+
|
| 8 |
+
1. mmBERT (jhu-clsp/mmBERT-small, revision abc32620dd4f6ab06f5fbe905dc25f310618e09f), the base model (its vocabulary was pruned and, for the smaller sizes, layers removed). Copyright (c) 2025 the mmBERT authors (Marone, Weller, Fleshman, Yang, Lawrie, Van Durme). MIT License:
|
| 9 |
+
|
| 10 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
| 11 |
+
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
| 12 |
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
| 13 |
+
persons to whom the Software is furnished to do so, subject to the following conditions:
|
| 14 |
+
|
| 15 |
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
| 16 |
+
Software.
|
| 17 |
+
|
| 18 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
| 19 |
+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
| 20 |
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
| 21 |
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
| 22 |
+
|
| 23 |
+
2. Text (not distributed in this repository). The model was trained and tested on text from these datasets, whose authors we thank and credit:
|
| 24 |
+
- Telugu_Sentiment, Marreddy et al. 2022 (te): https://huggingface.co/datasets/mounikaiiith/Telugu_Sentiment. Licence: CC BY 4.0. Used for: training and testing.
|
| 25 |
+
- 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.
|
| 26 |
+
- 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.
|
| 27 |
+
- 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.
|
| 28 |
+
- 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.
|
| 29 |
+
- 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.
|
| 30 |
+
- Motamot (Bengali political sentiment), arXiv:2407.19528 (bn): https://huggingface.co/datasets/Mukaffi28/Motamot_Bengali_Political_Sentiment_Analysis. Licence: MIT. Used for: training.
|
| 31 |
+
- 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.
|
| 32 |
+
- 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.
|
| 33 |
+
- 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.
|
| 34 |
+
- 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.
|
| 35 |
+
- 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.
|
| 36 |
+
No dataset text is distributed with the model. Use of the model does not imply endorsement by any of these authors or publishers.
|
| 37 |
+
|
| 38 |
+
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,153 @@
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- hi
|
| 5 |
+
- bn
|
| 6 |
+
- mr
|
| 7 |
+
- ta
|
| 8 |
+
- te
|
| 9 |
+
- kn
|
| 10 |
+
- ml
|
| 11 |
+
- gu
|
| 12 |
+
- pa
|
| 13 |
+
- or
|
| 14 |
+
- as
|
| 15 |
+
- ur
|
| 16 |
+
- en
|
| 17 |
+
library_name: transformers
|
| 18 |
+
pipeline_tag: text-classification
|
| 19 |
+
base_model: jhu-clsp/mmBERT-small
|
| 20 |
+
tags:
|
| 21 |
+
- sentiment-analysis
|
| 22 |
+
- indic
|
| 23 |
+
- multilingual
|
| 24 |
+
- code-mixed
|
| 25 |
+
- romanized
|
| 26 |
+
- text-classification
|
| 27 |
---
|
| 28 |
+
|
| 29 |
+
# cbx-indic-sentiment-classifier-36M
|
| 30 |
+
|
| 31 |
+
A sentiment classifier for 12 Indian languages and English: Hindi, Bengali, Marathi, Tamil, Telugu, Kannada, Malayalam, Gujarati, Punjabi, Odia, Assamese, Urdu and English, written in native script, in Latin letters (romanized) or code-mixed. Give it a comment, review, post or sentence and it returns `positive`, `negative` or `neutral`: the writer's own sentiment.
|
| 32 |
+
|
| 33 |
+
It has 36.5M parameters: the 58M with every second layer removed (11 of 22 layers), distilled again from the fine-tuned mmBERT-base, also on about 160,000 unlabelled real texts scored by that model. Other sizes: 58M.
|
| 34 |
+
On a CPU (8 threads, fp32) one short text (17 tokens) takes about 7 ms and a full 256-token text about 27 ms.
|
| 35 |
+
|
| 36 |
+
**Licence: Apache License, Version 2.0.** Read [Intended use and disclaimer](#intended-use-and-disclaimer) before using it.
|
| 37 |
+
|
| 38 |
+
## Labels
|
| 39 |
+
|
| 40 |
+
One label per text. F1 per label on Real text test (below).
|
| 41 |
+
|
| 42 |
+
| Label | Meaning | F1 |
|
| 43 |
+
|---|---|---:|
|
| 44 |
+
| `positive` | the writer expresses a favourable opinion or feeling: praise, liking, satisfaction, thanks, good wishes, excitement | 0.73 |
|
| 45 |
+
| `negative` | the writer expresses an unfavourable opinion or feeling: complaint, dislike, anger, sadness, disappointment, criticism, mockery | 0.58 |
|
| 46 |
+
| `neutral` | no opinion or feeling from the writer: facts, news reporting, announcements, questions, requests, instructions, ads without evaluation | 0.83 |
|
| 47 |
+
|
| 48 |
+
The labels follow a written guide. Sentiment is the writer's own stance, not the event: news that only reports a crime, a disaster or good news is `neutral`, however bad or good the event. Sarcasm takes its intended meaning, mild opinions count ("decent phone for the price" is `positive`), and a text with both polarities gets the one that dominates or is the writer's conclusion, otherwise `neutral`.
|
| 49 |
+
|
| 50 |
+
## Quick start
|
| 51 |
+
|
| 52 |
+
```bash
|
| 53 |
+
pip install -r requirements.txt
|
| 54 |
+
python example.py
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
```python
|
| 58 |
+
from cbx_sentiment import SentimentClassifier
|
| 59 |
+
|
| 60 |
+
clf = SentimentClassifier(".") # folder with the model files; CPU or GPU
|
| 61 |
+
r = clf.classify("Bahut badhiya phone hai, battery poora din chalti hai.")
|
| 62 |
+
r["label"], r["scores"] # top label and the probability of each label
|
| 63 |
+
clf.classify(["first text", "second text"]) # a list gives a list
|
| 64 |
+
```
|
| 65 |
+
|
| 66 |
+
`python example.py` prints (texts invented; any errors are the model's own):
|
| 67 |
+
|
| 68 |
+
```
|
| 69 |
+
positive 0.98 Bahut badhiya phone hai, battery poora din chalti hai.
|
| 70 |
+
negative 1.00 ডেলিভারি তিন দিন দেরিতে এসেছে, খুবই হতাশ।
|
| 71 |
+
neutral 0.93 நாளை காலை பத்து மணிக்கு கூட்டம் தொடங்கும்.
|
| 72 |
+
positive 1.00 ಈ ಸಿನಿಮಾ ತುಂಬಾ ಚೆನ್ನಾಗಿದೆ, ಎಲ್ಲರೂ ನೋಡಿ!
|
| 73 |
+
neutral 1.00 सरकार ने नई योजना की घोषणा की है।
|
| 74 |
+
negative 1.00 yaar kya bakwaas movie thi, paisa barbaad
|
| 75 |
+
negative 1.00 Service was okay but the food was cold and overpriced.
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
## Input
|
| 79 |
+
|
| 80 |
+
- One comment, review, post or sentence. The model reads at most 256 tokens; longer text is cut (`"truncated": True`).
|
| 81 |
+
- Native script, romanized and code-mixed text are all supported. The model judges the text alone: it does not see the conversation, the product or the post a comment replies to.
|
| 82 |
+
- If every text you score carries an opinion (for example product reviews with a star rating), compare only the `positive` and `negative` scores: that is how the IndicSentiment accuracy below is computed.
|
| 83 |
+
|
| 84 |
+
## Evaluation
|
| 85 |
+
|
| 86 |
+
**Real text test:** 2,575 real texts, about 200 per language, never used in training: web text (Sangraha, FineWeb-2), social-media comments, tweets and reviews from the datasets credited below, with at least 50 opinionated texts per language (53% neutral, 27% positive, 20% negative). Each text was labelled independently by two LLMs (Gemma 4 31B and Claude Sonnet 5.5) following the written guide; gpt-5.4-mini decided their disagreements. **No person reviewed the labels**, so they contain errors.
|
| 87 |
+
|
| 88 |
+
**Web text test:** 1,252 real texts (80–150 per language; web text and Dravidian comments, 72% neutral), labelled the same way. Smaller and mostly neutral; reported for comparison with the real text test.
|
| 89 |
+
|
| 90 |
+
**IndicSentiment:** 12,946 product reviews (AI4Bharat IndicSentiment, test and validation splits, 13 languages), each positive or negative as labelled by the dataset's authors. The model's `positive` and `negative` scores are compared (neutral is ignored), so this is a two-way accuracy. Not used in training.
|
| 91 |
+
|
| 92 |
+
| Model | Real text test (macro F1) | Web text test (macro F1) | IndicSentiment (accuracy) |
|
| 93 |
+
|---|---:|---:|---:|
|
| 94 |
+
| 58M (same family) | 0.721 | 0.680 | 0.849 |
|
| 95 |
+
| **this model (36M)** | 0.713 | 0.650 | 0.818 |
|
| 96 |
+
| TF-IDF + logistic regression | 0.685 | 0.623 | 0.726 |
|
| 97 |
+
| cardiffnlp/twitter-xlm-roberta-base-sentiment | 0.601 | – | 0.847 |
|
| 98 |
+
| cardiffnlp/twitter-xlm-roberta-base-sentiment-multilingual | 0.606 | – | 0.758 |
|
| 99 |
+
| tabularisai/multilingual-sentiment-analysis | 0.524 | – | 0.779 |
|
| 100 |
+
|
| 101 |
+
TF-IDF: character n-grams with logistic regression, trained on the same data. The three public models were used as published, with their labels mapped to ours; they were not trained on our data or guide, so part of their gap on the real text tests is a difference in what counts as neutral. tabularisai/multilingual-sentiment-analysis is licensed for non-commercial use only.
|
| 102 |
+
|
| 103 |
+
**By language** (Real text test, macro F1):
|
| 104 |
+
|
| 105 |
+
| Language | 58M | 36M (this model) | Texts |
|
| 106 |
+
|---|---:|---:|---:|
|
| 107 |
+
| Hindi (`hi`) | 0.67 | 0.68 | 199 |
|
| 108 |
+
| Bengali (`bn`) | 0.87 | 0.86 | 200 |
|
| 109 |
+
| Marathi (`mr`) | 0.73 | 0.70 | 199 |
|
| 110 |
+
| Tamil (`ta`) | 0.78 | 0.75 | 197 |
|
| 111 |
+
| Telugu (`te`) | 0.57 | 0.59 | 199 |
|
| 112 |
+
| Kannada (`kn`) | 0.80 | 0.77 | 195 |
|
| 113 |
+
| Malayalam (`ml`) | 0.73 | 0.72 | 196 |
|
| 114 |
+
| Gujarati (`gu`) | 0.71 | 0.70 | 196 |
|
| 115 |
+
| Punjabi (`pa`) | 0.57 | 0.56 | 200 |
|
| 116 |
+
| Odia (`or`) | 0.46 | 0.53 | 199 |
|
| 117 |
+
| Assamese (`as`) | 0.82 | 0.81 | 200 |
|
| 118 |
+
| Urdu (`ur`) | 0.61 | 0.61 | 197 |
|
| 119 |
+
| English (`en`) | 0.74 | 0.68 | 198 |
|
| 120 |
+
|
| 121 |
+
**By script** (this model, accuracy): code-mixed 0.71 (28 texts), native script 0.77 (1700 texts), romanized 0.74 (847 texts)
|
| 122 |
+
|
| 123 |
+
## Training data
|
| 124 |
+
|
| 125 |
+
About 63,000 labelled texts from the eleven training datasets credited below: social-media comments, tweets and reviews, plus web text from Sangraha and FineWeb-2. All of them were labelled to the written guide by two LLMs, with a third deciding disagreements; the datasets' own labels were not used. About 15% of the training texts (9,500) were written by LLMs to fill language and label combinations with little real text; no generated text is in any test set. The models were distilled from mmBERT-base fine-tuned on the same data.
|
| 126 |
+
|
| 127 |
+
| Dataset | Languages | Licence | Used for |
|
| 128 |
+
|---|---|---|---|
|
| 129 |
+
| [Telugu_Sentiment, Marreddy et al. 2022](https://huggingface.co/datasets/mounikaiiith/Telugu_Sentiment) | te | CC BY 4.0 | training and testing |
|
| 130 |
+
| [XLM-T tweet_sentiment_multilingual, Barbieri et al. 2022](https://huggingface.co/datasets/cardiffnlp/tweet_sentiment_multilingual) | en, hi | CC BY 3.0 (tweets: X / Twitter terms) | training and testing |
|
| 131 |
+
| [Hinglish YouTube sentiments dataset (shae2977)](https://huggingface.co/datasets/shae2977/hinglish-youtube-sentiments-dataset) | hi | CC BY 4.0 | training and testing |
|
| 132 |
+
| [Roman Urdu Data Set, Sharf 2018, UCI Machine Learning Repository](https://archive.ics.uci.edu/dataset/458/roman+urdu+data+set) | ur | CC BY 4.0 | training and testing |
|
| 133 |
+
| [Assamese movie reviews sentiment, A. Dutta and S. Dutta](https://huggingface.co/datasets/AvinabhDutta-Dev/assamese-movie-reviews-sentiment) | as | CC BY 4.0 | training and testing |
|
| 134 |
+
| [Bangla sentiment benchmark corpus, Sazzed 2021](https://huggingface.co/datasets/Akash190104/bengali_sentiment_analysis) | bn | CC BY 4.0 | training and testing |
|
| 135 |
+
| [Motamot (Bengali political sentiment), arXiv:2407.19528](https://huggingface.co/datasets/Mukaffi28/Motamot_Bengali_Political_Sentiment_Analysis) | bn | MIT | training |
|
| 136 |
+
| [Sangraha, AI4Bharat](https://huggingface.co/datasets/ai4bharat/sangraha) | as, bn, en, gu, hi, kn, ml, mr, or, pa, ta, te, ur | CC BY 4.0 | training and testing |
|
| 137 |
+
| [FineWeb-2, Hugging Face](https://huggingface.co/datasets/HuggingFaceFW/fineweb-2) | as, bn, gu, hi, kn, ml, mr, or, pa, ta, te, ur | ODC-By 1.0 | training and testing |
|
| 138 |
+
| [DravidianCodeMix comments (OffensEval Dravidian), Chakravarthi et al.](https://huggingface.co/datasets/community-datasets/offenseval_dravidian) | kn, ml, ta | CC BY 4.0 | training and testing |
|
| 139 |
+
| [Gujarati-English code-mixed comments (ShrutiPatel3011)](https://huggingface.co/datasets/ShrutiPatel3011/gujarati-english-codemixed-sentiment) | gu | CC BY 4.0 | training and testing |
|
| 140 |
+
| [IndicSentiment, Doddapaneni et al. 2023 (IndicXTREME), AI4Bharat](https://huggingface.co/datasets/ai4bharat/IndicSentiment) | as, bn, en, gu, hi, kn, ml, mr, or, pa, ta, te, ur | CC0 1.0 | testing |
|
| 141 |
+
|
| 142 |
+
## Limitations
|
| 143 |
+
|
| 144 |
+
- **Too many opinions are called neutral.** On IndicSentiment, where every review is positive or negative, the model labels 52% of reviews `neutral`. Negative opinions are missed most (`negative` F1 0.58 on the real text test). If your texts always carry an opinion, compare `positive` and `negative` scores only.
|
| 145 |
+
- **Weaker languages:** Odia (0.53), Punjabi (0.56), Telugu (0.59) and Urdu (0.61) score well below the other languages on the real text test. Expect more errors there.
|
| 146 |
+
- **Code-mixed text** is in training, but the real text test has only 28 code-mixed texts, so its accuracy there is not well measured.
|
| 147 |
+
- **Labels are from LLMs**, not people, for training and for the tests. The guide's choices (for example, that reported news is neutral) are one reasonable reading, not the only one; data labelled another way will score lower.
|
| 148 |
+
- **Context.** The model sees one text. Sarcasm, irony, quotes and replies to content it cannot see are often misread.
|
| 149 |
+
- **Bias.** Errors are not spread evenly across languages, scripts, dialects or topics; political, religious and community-related text may be judged less accurately.
|
| 150 |
+
|
| 151 |
+
## Intended use and disclaimer
|
| 152 |
+
|
| 153 |
+
**Intended use:** measuring and routing sentiment in text at scale, for example customer feedback, reviews, support messages and social-media posts, where results are read in aggregate or checked by people. **Not intended** for decisions about individual people (hiring, credit, moderation penalties, surveillance) without a person reviewing each case. The model makes mistakes, more in some languages than others (see Limitations). It is provided "as is", without warranties of any kind; Cobuild Tech Private Limited is not liable for its use. You are responsible for checking that it suits your data and for complying with the laws that apply to your use.
|
cbx_config.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "cbx-indic-sentiment-classifier-36M",
|
| 3 |
+
"version": "v0.1",
|
| 4 |
+
"labels": [
|
| 5 |
+
"positive",
|
| 6 |
+
"negative",
|
| 7 |
+
"neutral"
|
| 8 |
+
],
|
| 9 |
+
"max_len": 256,
|
| 10 |
+
"embedding_rank": null,
|
| 11 |
+
"base_model": "jhu-clsp/mmBERT-small",
|
| 12 |
+
"base_revision": "abc32620dd4f6ab06f5fbe905dc25f310618e09f",
|
| 13 |
+
"parameters": 36456195,
|
| 14 |
+
"scores": {
|
| 15 |
+
"test_real_v2": {
|
| 16 |
+
"n": 2575,
|
| 17 |
+
"macro_f1": 0.7125
|
| 18 |
+
},
|
| 19 |
+
"test_real_llm": {
|
| 20 |
+
"n": 1252,
|
| 21 |
+
"macro_f1": 0.6497
|
| 22 |
+
},
|
| 23 |
+
"test_indicsentiment": {
|
| 24 |
+
"n": 12946,
|
| 25 |
+
"binary_acc": 0.8183,
|
| 26 |
+
"macro_f1": 0.5724
|
| 27 |
+
}
|
| 28 |
+
},
|
| 29 |
+
"cpu_latency_ms": {
|
| 30 |
+
"threads": 8,
|
| 31 |
+
"short_tokens": 17,
|
| 32 |
+
"short_ms": 6.649615505011752,
|
| 33 |
+
"long_ms": 26.845012020203285
|
| 34 |
+
}
|
| 35 |
+
}
|
cbx_sentiment.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2026 Cobuild Tech Private Limited
|
| 2 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 3 |
+
"""CBX Indic 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; "scores" are softmax probabilities that sum to 1. The model reads at
|
| 14 |
+
most 256 tokens; longer text is cut ("truncated": True).
|
| 15 |
+
"""
|
| 16 |
+
import json
|
| 17 |
+
from pathlib import Path
|
| 18 |
+
|
| 19 |
+
import torch
|
| 20 |
+
import torch.nn as nn
|
| 21 |
+
from safetensors.torch import load_file
|
| 22 |
+
from transformers import AutoConfig, AutoModel, AutoTokenizer
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class _Net(nn.Module):
|
| 26 |
+
def __init__(self, path, cfg):
|
| 27 |
+
super().__init__()
|
| 28 |
+
self.backbone = AutoModel.from_config(AutoConfig.from_pretrained(path), attn_implementation="sdpa")
|
| 29 |
+
h = self.backbone.config.hidden_size
|
| 30 |
+
if cfg.get("embedding_rank"): # factorised word table (smaller sizes)
|
| 31 |
+
self.backbone.embeddings.tok_embeddings = nn.Sequential(
|
| 32 |
+
nn.Embedding(self.backbone.config.vocab_size, cfg["embedding_rank"]),
|
| 33 |
+
nn.Linear(cfg["embedding_rank"], h, bias=False))
|
| 34 |
+
self.head = nn.Linear(h, len(cfg["labels"]))
|
| 35 |
+
|
| 36 |
+
def forward(self, input_ids, attention_mask):
|
| 37 |
+
hs = self.backbone(input_ids=input_ids, attention_mask=attention_mask).last_hidden_state.float()
|
| 38 |
+
m = attention_mask.unsqueeze(-1).float()
|
| 39 |
+
return self.head((hs[:, 0] + (hs * m).sum(1) / m.sum(1).clamp(min=1)) / 2)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
class SentimentClassifier:
|
| 43 |
+
def __init__(self, path=".", device=None):
|
| 44 |
+
path = Path(path)
|
| 45 |
+
self.cfg = json.loads((path / "cbx_config.json").read_text())
|
| 46 |
+
self.labels = self.cfg["labels"]
|
| 47 |
+
self.max_len = self.cfg["max_len"]
|
| 48 |
+
self.device = device or ("cuda" if torch.cuda.is_available() else "cpu")
|
| 49 |
+
self.tok = AutoTokenizer.from_pretrained(path)
|
| 50 |
+
self.net = _Net(path, self.cfg)
|
| 51 |
+
self.net.load_state_dict(load_file(str(path / "model.safetensors")))
|
| 52 |
+
self.net.to(self.device).eval()
|
| 53 |
+
|
| 54 |
+
@torch.inference_mode()
|
| 55 |
+
def logits(self, texts, max_tokens=16384):
|
| 56 |
+
"""Raw logits [n][labels] in input order, and a truncated flag per text."""
|
| 57 |
+
texts = list(texts)
|
| 58 |
+
full = [len(x) for x in self.tok(texts, verbose=False)["input_ids"]]
|
| 59 |
+
enc = self.tok(texts, truncation=True, max_length=self.max_len, verbose=False)["input_ids"]
|
| 60 |
+
out = [None] * len(enc)
|
| 61 |
+
order = sorted(range(len(enc)), key=lambda i: len(enc[i]))
|
| 62 |
+
i = 0
|
| 63 |
+
while i < len(order):
|
| 64 |
+
j, n = i, 0
|
| 65 |
+
while j < len(order) and (j - i + 1) * max(n, len(enc[order[j]])) <= max_tokens:
|
| 66 |
+
n = max(n, len(enc[order[j]]))
|
| 67 |
+
j += 1
|
| 68 |
+
j = max(j, i + 1)
|
| 69 |
+
idx = order[i:j]
|
| 70 |
+
n = max(len(enc[k]) for k in idx)
|
| 71 |
+
ids = torch.full((len(idx), n), self.tok.pad_token_id, dtype=torch.long)
|
| 72 |
+
mask = torch.zeros((len(idx), n), dtype=torch.long)
|
| 73 |
+
for r, k in enumerate(idx):
|
| 74 |
+
ids[r, :len(enc[k])] = torch.tensor(enc[k])
|
| 75 |
+
mask[r, :len(enc[k])] = 1
|
| 76 |
+
lg = self.net(ids.to(self.device), mask.to(self.device)).float().cpu().tolist()
|
| 77 |
+
for r, k in enumerate(idx):
|
| 78 |
+
out[k] = lg[r]
|
| 79 |
+
i = j
|
| 80 |
+
return out, [f > self.max_len for f in full]
|
| 81 |
+
|
| 82 |
+
def classify(self, texts):
|
| 83 |
+
single = isinstance(texts, str)
|
| 84 |
+
texts = [texts] if single else list(texts)
|
| 85 |
+
lg, tr = self.logits(texts)
|
| 86 |
+
out = []
|
| 87 |
+
for row, t in zip(lg, tr):
|
| 88 |
+
p = torch.softmax(torch.tensor(row), -1).tolist()
|
| 89 |
+
s = dict(zip(self.labels, p))
|
| 90 |
+
out.append({"label": max(s, key=s.get), "scores": {k: round(v, 4) for k, v in s.items()}, "truncated": t})
|
| 91 |
+
return out[0] if single else out
|
checksums.sha256
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4 LICENSE
|
| 2 |
+
5cd23b9acb08b1046dd0b464b71f70ff8b012fdfd98d222fd4aa189d1b7d40b4 NOTICE
|
| 3 |
+
c0f6f9bcbb751c31f344a22a377ef467880dc7d3093782c6f878f20f3bf93180 README.md
|
| 4 |
+
cbc7380f9eecdac7e1dcf2d1da9c39c555c15a14fb9a96773de20afdfeec9c3c cbx_config.json
|
| 5 |
+
24e7146a951a596be244164ec244bbfd3f1faa7e8e3c32cb09924cd0a37152af cbx_sentiment.py
|
| 6 |
+
9debd32823a36532524b8eda91e072819e3c7dd534a434a94cb091173d6196fa config.json
|
| 7 |
+
e95b31dbe60ea1edf64e3d8e89a79ab8b1c008ab9a03e727521c43deb220315b example.py
|
| 8 |
+
aa1c084a37c0fbc22d46c5771faab9dbf62f82d1f4f5fddaddd142020920e0ba model.safetensors
|
| 9 |
+
ee71b13268fabbacc0925339898205f92239cf331d3c54ec1f7008f8587bab6f requirements.txt
|
| 10 |
+
06d1b86cfdfb2852bfa6840e980424e3c1f9ea9e495658b8dc5b690d7ee2c5f6 tokenizer.json
|
| 11 |
+
34237a702df9372414aa067f8d6e084a2d227ce93d87d6fd642a8d7a3d35d76e tokenizer_config.json
|
config.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"ModernBertForMaskedLM"
|
| 4 |
+
],
|
| 5 |
+
"attention_bias": false,
|
| 6 |
+
"attention_dropout": 0.0,
|
| 7 |
+
"bos_token_id": 2,
|
| 8 |
+
"classifier_activation": "gelu",
|
| 9 |
+
"classifier_bias": false,
|
| 10 |
+
"classifier_dropout": 0.0,
|
| 11 |
+
"classifier_pooling": "mean",
|
| 12 |
+
"cls_token_id": 1,
|
| 13 |
+
"decoder_bias": true,
|
| 14 |
+
"deterministic_flash_attn": false,
|
| 15 |
+
"dtype": "float32",
|
| 16 |
+
"embedding_dropout": 0.0,
|
| 17 |
+
"eos_token_id": 1,
|
| 18 |
+
"global_attn_every_n_layers": 3,
|
| 19 |
+
"gradient_checkpointing": false,
|
| 20 |
+
"hidden_activation": "gelu",
|
| 21 |
+
"hidden_size": 384,
|
| 22 |
+
"initializer_cutoff_factor": 2.0,
|
| 23 |
+
"initializer_range": 0.02,
|
| 24 |
+
"intermediate_size": 1152,
|
| 25 |
+
"layer_norm_eps": 1e-05,
|
| 26 |
+
"layer_types": [
|
| 27 |
+
"full_attention",
|
| 28 |
+
"sliding_attention",
|
| 29 |
+
"sliding_attention",
|
| 30 |
+
"full_attention",
|
| 31 |
+
"sliding_attention",
|
| 32 |
+
"sliding_attention",
|
| 33 |
+
"full_attention",
|
| 34 |
+
"sliding_attention",
|
| 35 |
+
"sliding_attention",
|
| 36 |
+
"full_attention",
|
| 37 |
+
"sliding_attention"
|
| 38 |
+
],
|
| 39 |
+
"local_attention": 128,
|
| 40 |
+
"mask_token_id": 4,
|
| 41 |
+
"max_position_embeddings": 8192,
|
| 42 |
+
"mlp_bias": false,
|
| 43 |
+
"mlp_dropout": 0.0,
|
| 44 |
+
"model_type": "modernbert",
|
| 45 |
+
"norm_bias": false,
|
| 46 |
+
"norm_eps": 1e-05,
|
| 47 |
+
"num_attention_heads": 6,
|
| 48 |
+
"num_hidden_layers": 11,
|
| 49 |
+
"pad_token_id": 0,
|
| 50 |
+
"position_embedding_type": "sans_pos",
|
| 51 |
+
"rope_parameters": {
|
| 52 |
+
"full_attention": {
|
| 53 |
+
"rope_theta": 160000,
|
| 54 |
+
"rope_type": "default"
|
| 55 |
+
},
|
| 56 |
+
"sliding_attention": {
|
| 57 |
+
"rope_theta": 160000,
|
| 58 |
+
"rope_type": "default"
|
| 59 |
+
}
|
| 60 |
+
},
|
| 61 |
+
"sep_token_id": 1,
|
| 62 |
+
"sparse_pred_ignore_index": -100,
|
| 63 |
+
"sparse_prediction": false,
|
| 64 |
+
"tie_word_embeddings": true,
|
| 65 |
+
"transformers_version": "5.23.0",
|
| 66 |
+
"vocab_size": 40000
|
| 67 |
+
}
|
example.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
"सरकार ने नई योजना की घोषणा की है।", # Hindi: the government has announced a new scheme
|
| 13 |
+
"yaar kya bakwaas movie thi, paisa barbaad", # romanized Hindi: what a rubbish film, money wasted
|
| 14 |
+
"Service was okay but the food was cold and overpriced.",
|
| 15 |
+
]
|
| 16 |
+
for text, r in zip(texts, clf.classify(texts)):
|
| 17 |
+
print(f"{r['label']:<9} {max(r['scores'].values()):.2f} {text}")
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:aa1c084a37c0fbc22d46c5771faab9dbf62f82d1f4f5fddaddd142020920e0ba
|
| 3 |
+
size 145832060
|
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,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"backend": "tokenizers",
|
| 3 |
+
"bos_token": "<bos>",
|
| 4 |
+
"clean_up_tokenization_spaces": false,
|
| 5 |
+
"cls_token": "<bos>",
|
| 6 |
+
"eos_token": "<eos>",
|
| 7 |
+
"extra_special_tokens": [
|
| 8 |
+
"<start_of_turn>",
|
| 9 |
+
"<end_of_turn>"
|
| 10 |
+
],
|
| 11 |
+
"is_local": true,
|
| 12 |
+
"local_files_only": false,
|
| 13 |
+
"mask_token": "<mask>",
|
| 14 |
+
"max_length": 256,
|
| 15 |
+
"model_input_names": [
|
| 16 |
+
"input_ids",
|
| 17 |
+
"attention_mask"
|
| 18 |
+
],
|
| 19 |
+
"model_max_length": 8192,
|
| 20 |
+
"pad_token": "<pad>",
|
| 21 |
+
"padding_side": "right",
|
| 22 |
+
"sep_token": "<eos>",
|
| 23 |
+
"spaces_between_special_tokens": false,
|
| 24 |
+
"stride": 0,
|
| 25 |
+
"tokenizer_class": "TokenizersBackend",
|
| 26 |
+
"truncation_side": "right",
|
| 27 |
+
"truncation_strategy": "longest_first",
|
| 28 |
+
"unk_token": "<unk>"
|
| 29 |
+
}
|