Berbex commited on
Commit
7d33fb7
β€’
1 Parent(s): ba70565

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -3
app.py CHANGED
@@ -1,9 +1,23 @@
1
  import gradio as gr
2
-
3
  from datasets import load_dataset
4
 
5
- dataset = load_dataset("zeroshot/twitter-financial-news-sentiment")
6
- dataset
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  """
8
  categories = ('Car in good condition','Damaged Car')
9
 
 
1
  import gradio as gr
2
+ import torch
3
  from datasets import load_dataset
4
 
5
+ dataset = load_dataset("zeroshot/twitter-financial-news-sentiment", )
6
+
7
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
8
+
9
+ model = AutoModelForSequenceClassification.from_pretrained("bert-base-uncased")
10
+ tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
11
+
12
+ def sentiment_score(review):
13
+ tokens = tokenizer.encode(review, return_tensors='pt')
14
+ result = model(tokens)
15
+ return int(torch.argmax(result.logits))
16
+
17
+ dataset['sentiment'] = dataset['text'].apply(lambda x: sentiment_score(x[:512]))
18
+
19
+ print(dataset[:10])
20
+
21
  """
22
  categories = ('Car in good condition','Damaged Car')
23