Spaces:
Runtime error
Runtime error
Jeffrey Rathgeber Jr
commited on
test 3rd option
Browse files
app.py
CHANGED
|
@@ -12,19 +12,40 @@ model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
|
| 12 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 13 |
|
| 14 |
classifier = pipeline(task="sentiment-analysis", model=model, tokenizer=tokenizer)
|
| 15 |
-
# classifier = pipeline(task="sentiment-analysis")
|
| 16 |
|
| 17 |
textIn = st.text_input("Input Text Here:", "I really like the color of your car!")
|
| 18 |
|
| 19 |
-
option = st.selectbox('Which pre-trained model would you like for your sentiment analysis?',('Pipeline', 'TextBlob'))
|
| 20 |
|
| 21 |
st.write('You selected:', option)
|
| 22 |
|
| 23 |
|
| 24 |
-
|
| 25 |
-
token_ids = tokenizer.convert_tokens_to_ids(tokens)
|
| 26 |
-
input_ids = tokenizer(textIn)
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
if option == 'Pipeline':
|
| 30 |
# pipeline
|
|
@@ -45,3 +66,7 @@ if option == 'TextBlob':
|
|
| 45 |
sentiment = 'Positive'
|
| 46 |
|
| 47 |
st.write('According to TextBlob, input text is ', sentiment, ' and a subjectivity score (from 0 being objective to 1 being subjective) of ', subjectivity)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 13 |
|
| 14 |
classifier = pipeline(task="sentiment-analysis", model=model, tokenizer=tokenizer)
|
|
|
|
| 15 |
|
| 16 |
textIn = st.text_input("Input Text Here:", "I really like the color of your car!")
|
| 17 |
|
| 18 |
+
option = st.selectbox('Which pre-trained model would you like for your sentiment analysis?',('Pipeline', 'TextBlob', 'FINE-TUNED'))
|
| 19 |
|
| 20 |
st.write('You selected:', option)
|
| 21 |
|
| 22 |
|
| 23 |
+
#------------------------------------------------------------------------
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
# tokens = tokenizer.tokenize(textIn)
|
| 26 |
+
# token_ids = tokenizer.convert_tokens_to_ids(tokens)
|
| 27 |
+
# input_ids = tokenizer(textIn)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
# X_train = [textIn]
|
| 31 |
+
|
| 32 |
+
# batch = tokenizer(X_train, padding=True, truncation=True, max_length=512, return_tensors="pt")
|
| 33 |
+
# # batch = torch.tensor(batchbatch["input_ids"])
|
| 34 |
+
|
| 35 |
+
# with torch.no_grad():
|
| 36 |
+
# outputs = model(**batch, labels=torch.tensor([1, 0]))
|
| 37 |
+
# predictions = F.softmax(outputs.logits, dim=1)
|
| 38 |
+
# labels = torch.argmax(predictions, dim=1)
|
| 39 |
+
# labels = [model.config.id2label[label_id] for label_id in labels.tolist()]
|
| 40 |
+
|
| 41 |
+
# # save_directory = "saved"
|
| 42 |
+
# tokenizer.save_pretrained(save_directory)
|
| 43 |
+
# model.save_pretrained(save_directory)
|
| 44 |
+
|
| 45 |
+
# tokenizer = AutoTokenizer.from_pretrained(save_directory)
|
| 46 |
+
# model = AutoModelForSequenceClassification.from_pretrained(save_directory)
|
| 47 |
+
|
| 48 |
+
#------------------------------------------------------------------------
|
| 49 |
|
| 50 |
if option == 'Pipeline':
|
| 51 |
# pipeline
|
|
|
|
| 66 |
sentiment = 'Positive'
|
| 67 |
|
| 68 |
st.write('According to TextBlob, input text is ', sentiment, ' and a subjectivity score (from 0 being objective to 1 being subjective) of ', subjectivity)
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
if option == 'FINE-TUNED':
|
| 72 |
+
...
|