milestone-2 / app.py
Matt C
prototyping s-nlp roberta again
6767b70
raw
history blame
No virus
777 Bytes
import streamlit as st
from transformers import RobertaTokenizer, RobertaForSequenceClassification
txt = st.text_area('Text to analyze', '''
It was the best of times, it was the worst of times, it was
the age of wisdom, it was the age of foolishness, it was
the epoch of belief, it was the epoch of incredulity, it
was the season of Light, it was the season of Darkness, it
was the spring of hope, it was the winter of despair, (...)
''')
# load tokenizer and model weights
tokenizer = AutoTokenizer.from_pretrained("s-nlp/roberta_toxicity_classifier")
model = AutoModelForSequenceClassification.from_pretrained("s-nlp/roberta_toxicity_classifier")
# prepare the input
batch = tokenizer.encode('txt', return_tensors='pt')
# inference
model(batch)