CodeHima/TOSBertV2
09
1---2license: mit3language:4- en5metrics:6- accuracy7widget:8 - text: "You have the right to use CommunityConnect for its intended purpose of connecting with others, sharing content responsibly, and engaging in constructive dialogue. You are responsible for the content you post and must respect the rights and privacy of others."9 example_title: "Fair Clause"10 - text: " We reserve the right to suspend, terminate, or restrict your access to the platform at any time and for any reason, without prior notice or explanation. This includes but is not limited to violations of our community guidelines or terms of service, as determined solely by ConnectWorld."11 example_title: "Unfair Clause"12library_name: transformers13pipeline_tag: text-classification14tags:15- nlp16- bert17- TOS18---19# BertTOS v2: Terms of Service Unfairness Classifier20 21## Model Details22 23- **Model Name:** BertTOS v224- **Model Type:** Fine-tuned BERT for sequence classification25- **Version:** 2.026- **Language(s):** English27- **License:** [MIT]28- **Developer:** [Himanshu Mohanty]29 30## Model Description31 32BertTOS v2 is a fine-tuned BERT model designed to classify clauses in Terms of Service (ToS) documents based on their unfairness level. This model can help users identify potentially problematic clauses in legal documents, particularly in the context of consumer protection.33 34### Task35 36The model performs multi-class classification on individual sentences or clauses, categorizing them into three levels of unfairness:37 380. Clearly Fair391. Potentially Unfair402. Clearly Unfair41 42### Training Data43 44The model was trained on the [CodeHima/TOS_Dataset](https://huggingface.co/datasets/CodeHima/TOS_Dataset) dataset, which contains annotated sentences from Terms of Service documents. Each sentence is labeled with one of the three unfairness levels.45 46### Model Architecture47 48- Base Model: BERT (bert-base-uncased)49- Fine-tuning: Sequence classification head50- Input: Tokenized text (max length 512 tokens)51- Output: Probabilities for each unfairness level52 53## Performance54 55The model's performance metrics on the test set:56 57- Accuracy: [0.8795761078998073]58- F1 Score (weighted): [0.885282]59- Precision (weighted): [0.883729]60- Recall (weighted): [0.889157]61 62## Limitations63 64- The model is trained on English language ToS documents and may not perform well on other languages or legal contexts.65- Performance may vary depending on the specific wording and context of clauses.66- The model should be used as a tool to assist human judgment, not as a definitive legal assessment.67 68## Ethical Considerations69 70- This model is intended to help identify potentially unfair clauses, but it should not be considered as legal advice.71- Users should be aware of potential biases in the training data and model predictions.72- The model's output should be reviewed by legal professionals for critical applications.73 74## How to Use75 76You can use this model directly with the Hugging Face `transformers` library:77 78```python79from transformers import AutoTokenizer, AutoModelForSequenceClassification80import torch81 82# Load model and tokenizer83model_name = "YourHuggingFaceUsername/TOSBertV2"84tokenizer = AutoTokenizer.from_pretrained(model_name)85model = AutoModelForSequenceClassification.from_pretrained(model_name)86 87# Function to predict unfairness level88def predict_unfairness(text):89 inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=512)90 91 model.eval()92 with torch.no_grad():93 outputs = model(**inputs)94 95 probabilities = torch.softmax(outputs.logits, dim=-1).squeeze()96 predicted_class = torch.argmax(probabilities).item()97 98 label_mapping = {0: 'clearly_fair', 1: 'potentially_unfair', 2: 'clearly_unfair'}99 predicted_label = label_mapping[predicted_class]100 101 return predicted_label, probabilities.tolist()102 103# Example usage104clause = "The company reserves the right to change these terms at any time without notice."105predicted_label, probabilities = predict_unfairness(clause)106 107print(f"Predicted unfairness level: {predicted_label}")108print("Probabilities:")109for label, prob in zip(['clearly_fair', 'potentially_unfair', 'clearly_unfair'], probabilities):110 print(f"{label}: {prob:.4f}")111```112 113## Training114 115The model was trained using the following hyperparameters:116 117- Epochs: 3118- Batch Size: 16119- Learning Rate: [ ]120- Optimizer: AdamW121- Weight Decay: 0.01122 123## Citation124 125If you use this model in your research, please cite:126 127```bibtex128@misc{TOSBertV2,129 author = {Himanshu Mohanty},130 title = {TOSBertV2: is a fine-tuned BERT model designed to classify clauses in Terms of Service},131 year = {2024},132 publisher = {Hugging Face},133 journal = {Hugging Face Model Hub},134 howpublished = {\url{https://huggingface.co/CodeHima/TOSBertV2}}135}