Matt C commited on
Commit
2268b75
1 Parent(s): 6c042c6

prototyping s-nlp roberta

Browse files
Files changed (1) hide show
  1. app.py +13 -1
app.py CHANGED
@@ -1,5 +1,8 @@
1
  import streamlit as st
2
 
 
 
 
3
  txt = st.text_area('Text to analyze', '''
4
  It was the best of times, it was the worst of times, it was
5
  the age of wisdom, it was the age of foolishness, it was
@@ -7,4 +10,13 @@ txt = st.text_area('Text to analyze', '''
7
  was the season of Light, it was the season of Darkness, it
8
  was the spring of hope, it was the winter of despair, (...)
9
  ''')
10
- st.write('Sentiment:', run_sentiment_analysis(txt))
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
 
3
+ from transformers import RobertaTokenizer, RobertaForSequenceClassification
4
+
5
+
6
  txt = st.text_area('Text to analyze', '''
7
  It was the best of times, it was the worst of times, it was
8
  the age of wisdom, it was the age of foolishness, it was
 
10
  was the season of Light, it was the season of Darkness, it
11
  was the spring of hope, it was the winter of despair, (...)
12
  ''')
13
+
14
+ # load tokenizer and model weights
15
+ tokenizer = RobertaTokenizer.from_pretrained('SkolkovoInstitute/roberta_toxicity_classifier')
16
+ model = RobertaForSequenceClassification.from_pretrained('SkolkovoInstitute/roberta_toxicity_classifier')
17
+
18
+ # prepare the input
19
+ batch = tokenizer.encode('txt', return_tensors='pt')
20
+
21
+ # inference
22
+ model(batch)