Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language:
|
3 |
+
- id
|
4 |
+
tags:
|
5 |
+
- indobert
|
6 |
+
- indobenchmark
|
7 |
+
- indonlu
|
8 |
+
---
|
9 |
+
This is the second classification of sentiment analysis for (redacted) task
|
10 |
+
|
11 |
+
### How to import
|
12 |
+
```python
|
13 |
+
import torch
|
14 |
+
from transformers import BertForSequenceClassification, BertTokenizer, BertConfig, pipeline
|
15 |
+
|
16 |
+
# Load the tokenizer and model
|
17 |
+
tokenizer = BertTokenizer.from_pretrained("nfhakim/police-sentiment-c1-v2")
|
18 |
+
config = BertConfig.from_pretrained("nfhakim/police-sentiment-c1-v2")
|
19 |
+
model = BertForSequenceClassification.from_pretrained("nfhakim/police-sentiment-c1-v2", config=config)
|
20 |
+
```
|
21 |
+
|
22 |
+
### How to use
|
23 |
+
```python
|
24 |
+
# Initialize the pipeline
|
25 |
+
nlp = pipeline("text-classification", model=model, tokenizer=tokenizer)
|
26 |
+
|
27 |
+
# Define a function to handle input text
|
28 |
+
def classify_text(text):
|
29 |
+
# Tokenize the text and truncate to the first 512 tokens if necessary
|
30 |
+
inputs = tokenizer(text, truncation=True, max_length=512, return_tensors="pt")
|
31 |
+
|
32 |
+
# Use the model to classify the text
|
33 |
+
results = nlp(inputs['input_ids'])
|
34 |
+
return results
|
35 |
+
|
36 |
+
# Example usage
|
37 |
+
input_text = "Your input text here"
|
38 |
+
output = classify_text(input_text)
|
39 |
+
print(output)
|
40 |
+
|
41 |
+
```
|