Downloads · 30 days
12
22% of all-time downloads
kzt005/polite-guard
polite-guard is a text classification model from kzt005. Use it when you need a label for a piece of text. It is set up for transformers. The card lists the license as apache-2.0.
- Model type: BERT (Bidirectional Encoder Representations from Transformers) - Architecture: Fine-tuned BERT-base uncased - Task: Text Classification - Source Code: https://github.com/intel/polite-guard - Dataset: htt…
Downloads · 30 days
12
22% of all-time downloads
All-time downloads
55
Public
Parameters
109M
3.5 GB on disk
Likes
0
Public
Click a slice to open those files.
.onnx768 MB · 64%
From the Hugging Face model README
Polite Guard is an open-source NLP language model developed by Intel, fine-tuned from BERT for text classification tasks. It is designed to classify text into four categories: polite, somewhat polite, neutral, and impolite. This model, along with its accompanying datasets and source code, is available on Hugging Face* and GitHub* to enable both communities to contribute to developing more sophisticated and context-aware AI systems.
Polite Guard provides a scalable model development pipeline and methodology, making it easier for developers to create and fine-tune their own models. Other contributions of the project include:
| Hypeparameter | Batch size | Learning rate | Learning rate schedule | Max epochs | Optimizer | Weight decay | Precision |
|---|---|---|---|---|---|---|---|
| Value | 32 | 4.78e-05 | Linear warmup (10% of steps) | 2 | AdamW | 1.01e-06 | bf16-mixed |
Hyperparameter tuning was performed using Bayesian optimization with the Tree-structured Parzen Estimator (TPE) algorithm through Optuna* with 35 trials to maximize the validation F1-score. The hyperparameter search space included
learning rate: [1e-5, 5e-4]
weight decay: [1e-6, 1e-2]
The fine-tuning process used Optuna's pruning callback to terminate underperforming hyperparameter trials, and model checkpointing to save the best performing model states.

The code for the synthetic data generation and fine-tuning can be found here.
Here are the key performance metrics of the model on the test dataset containing both synthetic and manually annotated data:
You can use this model directly with a pipeline for categorizing text into classes polite, somewhat polite, neutral, and impolite.
from transformers import pipeline
classifier = pipeline("text-classification", "Intel/polite-guard")
text = "Your input text"
output = classifier(text)
print(output)
The next example demonstrates how to run this model in the browser using Hugging Face's transformers.js library with webnn-gpu for hardware acceleration.
<!DOCTYPE html>
<html>
<body>
<h1>WebNN Transformers.js Intel/polite-guard</h1>
<script type="module">
import { pipeline } from "https://cdn.jsdelivr.net/npm/@huggingface/transformers";
const classifier = await pipeline("text-classification", "Intel/polite-guard", {
dtype: "fp32",
device: "webnn-gpu", // You can also try: "webgpu", "webnn", "webnn-npu", "webnn-cpu", "wasm"
});
const text = "Your input text";
const output = await classifier(text);
console.log(`${text}: ${output[0].label}`);
</script>
</body>
</html>
To learn more about the implementation of the data generator and fine-tuner packages, refer to
For more AI development how-to content, visit Intel® AI Development Resources.
If you are interested in exploring other models, join us in the Intel and Hugging Face communities. These models simplify the development and adoption of Generative AI solutions, while fostering innovation among developers worldwide. If you find this project valuable, please like ❤️ it on Hugging Face and share it with your network. Your support helps us grow the community and reach more contributors.
Polite Guard has been trained and validated on a limited set of data that pertains to customer reviews, product reviews, and corporate communications. Accuracy metrics cannot be guaranteed outside these narrow use cases, and therefore this tool should be validated within the specific context of use for which it might be deployed. This tool is not intended to be used to evaluate employee performance. This tool is not sufficient to prevent harm in many contexts, and additional tools and techniques should be employed in any sensitive use case where impolite speech may cause harm to individuals, communities, or society.
Please note that the Polite Guard model uses AI technology and you are interacting with a chatbot. Prompts that are being used during the demo will not be stored. For information regarding the handling of personal data collected refer to the Global Privacy Notice (https://www.intel.com/content/www/us/en/privacy/intelprivacy-notice.html), which encompass our privacy practices.
*Other names and brands may be claimed as the property of others.