Datasets:
Tasks:
Text Classification
Sub-tasks:
sentiment-classification
Languages:
English
Multilinguality:
monolingual
Size Categories:
1k<10K
ArXiv:
License:
Update readme.py
Browse files
readme.py
CHANGED
@@ -68,9 +68,29 @@ Fine-tuning script can be found [here](https://huggingface.co/datasets/cardiffnl
|
|
68 |
|
69 |
|
70 |
### Usage
|
|
|
71 |
```python
|
72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
```
|
|
|
74 |
### Reference
|
75 |
If you use any resource from T-NER, please consider to cite our [paper](https://aclanthology.org/2021.eacl-demos.7/).
|
76 |
|
|
|
68 |
|
69 |
|
70 |
### Usage
|
71 |
+
|
72 |
```python
|
73 |
+
import math
|
74 |
+
import torch
|
75 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
76 |
+
|
77 |
+
def sigmoid(x):
|
78 |
+
return 1 / (1 + math.exp(-x))
|
79 |
+
|
80 |
+
tokenizer = AutoTokenizer.from_pretrained({model_name})
|
81 |
+
model = AutoModelForSequenceClassification.from_pretrained({model_name}, problem_type="multi_label_classification")
|
82 |
+
model.eval()
|
83 |
+
class_mapping = model.config.id2label
|
84 |
+
|
85 |
+
with torch.no_grad():
|
86 |
+
text = "#NewVideo Cray Dollas- Water- Ft. Charlie Rose- (Official Music Video)- {{URL}} via {@YouTube@} #watchandlearn {{USERNAME}}"
|
87 |
+
tokens = tokenizer(text, return_tensors='pt')
|
88 |
+
output = model(**tokens)
|
89 |
+
flags = [sigmoid(s) > 0.5 for s in output[0][0].detach().tolist()]
|
90 |
+
topic = [class_mapping[n] for n, i in enumerate(flags) if i]
|
91 |
+
print(topic)
|
92 |
```
|
93 |
+
|
94 |
### Reference
|
95 |
If you use any resource from T-NER, please consider to cite our [paper](https://aclanthology.org/2021.eacl-demos.7/).
|
96 |
|