nfhakim commited on
Commit
75b027e
1 Parent(s): 88efe07

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +8 -11
README.md CHANGED
@@ -1,7 +1,6 @@
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
@@ -9,16 +8,14 @@ from transformers import BertForSequenceClassification, BertTokenizer, BertConfi
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 = 'INSERT TEXT - MINIMUM 3 SENTENCES FOR BETTER PREDICITONS'
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
 
 
 
1
  This is the first classification of sentiment analysis for (redacted) task
2
 
3
+ ### How to import
 
4
  ```python
5
  import torch
6
  from transformers import BertForSequenceClassification, BertTokenizer, BertConfig
 
8
  tokenizer = BertTokenizer.from_pretrained("nfhakim/sentiment-analysis-c1")
9
  config = BertConfig.from_pretrained("nfhakim/sentiment-analysis-c1")
10
  model = BertForSequenceClassification.from_pretrained("nfhakim/sentiment-analysis-c1", config=config)
11
+ ```
12
 
13
+ ### How to use
14
+ ```python
15
+ from transformers import pipeline
16
+ nlp = pipeline("text-classification", model="nfhakim/sentiment-analysis-c1")
 
 
 
 
17
 
18
+ results = nlp("Your input text here")
19
  ```
20
 
21
+