Model card WIP
Browse files
README.md
CHANGED
|
@@ -3,4 +3,57 @@ license: apache-2.0
|
|
| 3 |
language:
|
| 4 |
- en
|
| 5 |
pipeline_tag: text-classification
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
language:
|
| 4 |
- en
|
| 5 |
pipeline_tag: text-classification
|
| 6 |
+
datasets:
|
| 7 |
+
- grammarly/detexd-eval
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
# DeTexD-RoBERTa-base delicate text detection
|
| 11 |
+
|
| 12 |
+
This is a baseline RoBERTa-base model for the delicate text detection task.
|
| 13 |
+
|
| 14 |
+
* Paper: [DeTexD: A Benchmark Dataset for Delicate Text Detection](TODO)
|
| 15 |
+
* [GitHub repository](https://github.com/grammarly/detexd)
|
| 16 |
+
|
| 17 |
+
## Classification example code
|
| 18 |
+
|
| 19 |
+
Here's a short usage example with the torch library in a binary classification task:
|
| 20 |
+
|
| 21 |
+
```python
|
| 22 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 23 |
+
import torch
|
| 24 |
+
|
| 25 |
+
tokenizer = AutoTokenizer.from_pretrained("grammarly/detexd-roberta")
|
| 26 |
+
model = AutoModelForSequenceClassification.from_pretrained("grammarly/detexd-roberta")
|
| 27 |
+
model.eval()
|
| 28 |
+
|
| 29 |
+
def predict_binary_score(text: str, break_class_ix=3):
|
| 30 |
+
with torch.no_grad():
|
| 31 |
+
# get multiclass probability scores
|
| 32 |
+
logits = model(**tokenizer(text, return_tensors='pt'))[0]
|
| 33 |
+
probs = torch.nn.functional.softmax(logits, dim=-1)
|
| 34 |
+
|
| 35 |
+
# convert to a binary prediction by summing the probability scores
|
| 36 |
+
# for the higher-index classes, as defined by break_class_ix
|
| 37 |
+
bin_score = probs[..., break_class_ix:].sum(dim=-1)
|
| 38 |
+
|
| 39 |
+
return bin_score.item()
|
| 40 |
+
|
| 41 |
+
def predict_delicate(text: str, threshold=0.72496545):
|
| 42 |
+
return predict_binary_score(text) > threshold
|
| 43 |
+
|
| 44 |
+
print(predict_delicate("Time flies like an arrow. Fruit flies like a banana."))
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
Expected output:
|
| 48 |
+
|
| 49 |
+
```
|
| 50 |
+
False
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
## BibTeX entry and citation info
|
| 54 |
+
|
| 55 |
+
Please cite [our paper](TODO) if you use this model.
|
| 56 |
+
|
| 57 |
+
```bibtex
|
| 58 |
+
TODO
|
| 59 |
+
```
|