Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
This is the first classification of sentiment analysis for (redacted) task
|
| 2 |
+
|
| 3 |
+
### How to use this code
|
| 4 |
+
|
| 5 |
+
```python
|
| 6 |
+
import torch
|
| 7 |
+
from transformers import BertForSequenceClassification, BertTokenizer, BertConfig
|
| 8 |
+
|
| 9 |
+
tokenizer = BertTokenizer.from_pretrained("nfhakim/sentiment-analysis-c1")
|
| 10 |
+
config = BertConfig.from_pretrained("nfhakim/sentiment-analysis-c1")
|
| 11 |
+
model = BertForSequenceClassification.from_pretrained("nfhakim/sentiment-analysis-c1", config=config)
|
| 12 |
+
|
| 13 |
+
text = 'Jakarta - Satnarkoba Polresta Bogor Kota mengungkap peredaran narkotika jenis ganja yang dikirim melalui jasa ekspedisi di Kota Bogor. Barang bukti 6 kilogram ganja yang diduga akan diedarkan pada malam tahun baru itu disita polisi.'
|
| 14 |
+
subwords = tokenizer.encode(text)
|
| 15 |
+
subwords = torch.LongTensor(subwords).view(1, -1).to(model.device)
|
| 16 |
+
|
| 17 |
+
i2w = {0: 'positive', 1: 'non-positive'}
|
| 18 |
+
|
| 19 |
+
logits = model(subwords)[0]
|
| 20 |
+
label = torch.topk(logits, k=1, dim=-1)[1].squeeze().item()
|
| 21 |
+
|
| 22 |
+
print(f'Text: {text} | Label : {i2w[label]} ({torch.nn.functional.softmax(logits, dim=-1).squeeze()[label] * 100:.3f}%)')
|
| 23 |
+
```
|
| 24 |
+
|