andyqin18 commited on
Commit
228ca50
1 Parent(s): c789552

Added more

Browse files
Files changed (2) hide show
  1. app.py +22 -10
  2. milestone3.py +1 -0
app.py CHANGED
@@ -1,21 +1,32 @@
1
  import streamlit as st
2
  from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
3
 
 
 
 
 
 
 
4
  st.title("Sentiment Analysis App - beta")
5
- st.header("This app is to analyze the sentiments behind a text. Currently it uses \
6
  pre-trained models without fine-tuning.")
7
 
 
 
 
 
 
 
 
 
 
 
8
  user_input = st.text_input("Enter your text:", value="Missing Sophie.Z...")
9
  user_model = st.selectbox("Please select a model:",
10
- ("distilbert-base-uncased-finetuned-sst-2-english",
11
- "cardiffnlp/twitter-roberta-base-sentiment",
12
- "finiteautomata/bertweet-base-sentiment-analysis"))
13
 
14
- def analyze(model_name, text):
15
- model = AutoModelForSequenceClassification.from_pretrained(model_name)
16
- tokenizer = AutoTokenizer.from_pretrained(model_name)
17
- classifier = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
18
- return classifier(text)
19
 
20
 
21
  if st.button("Analyze"):
@@ -23,6 +34,7 @@ if st.button("Analyze"):
23
  st.write("Please enter a text.")
24
  else:
25
  with st.spinner("Hang on.... Analyzing..."):
26
- st.write(analyze(user_model, user_input))
 
27
  else:
28
  st.write("Go on! Try the app!")
 
1
  import streamlit as st
2
  from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
3
 
4
+ def analyze(model_name, text):
5
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ classifier = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
8
+ return classifier(text)
9
+
10
  st.title("Sentiment Analysis App - beta")
11
+ st.write("This app is to analyze the sentiments behind a text. \n Currently it uses \
12
  pre-trained models without fine-tuning.")
13
 
14
+ model_descrip = {
15
+ "distilbert-base-uncased-finetuned-sst-2-english": "This model is a fine-tune checkpoint of DistilBERT-base-uncased, fine-tuned on SST-2.\n \
16
+ Labels: POSITIVE; NEGATIVE ",
17
+ "cardiffnlp/twitter-roberta-base-sentiment": "This is a roBERTa-base model trained on ~58M tweets and finetuned for sentiment analysis with the TweetEval benchmark.\n \
18
+ Labels: 0 -> Negative; 1 -> Neutral; 2 -> Positive",
19
+ "finiteautomata/bertweet-base-sentiment-analysis": "Model trained with SemEval 2017 corpus (around ~40k tweets). Base model is BERTweet, a RoBERTa model trained on English tweets. \n \
20
+ Labels: POS; NEU; NEG"
21
+ }
22
+
23
+
24
  user_input = st.text_input("Enter your text:", value="Missing Sophie.Z...")
25
  user_model = st.selectbox("Please select a model:",
26
+ model_descrip)
 
 
27
 
28
+ st.write("### Model Description:")
29
+ st.write(model_descrip[user_model])
 
 
 
30
 
31
 
32
  if st.button("Analyze"):
 
34
  st.write("Please enter a text.")
35
  else:
36
  with st.spinner("Hang on.... Analyzing..."):
37
+ result = analyze(user_model, user_input)
38
+ st.write(f"Result: \nLabel: {result[0]['label']} Score: {result[0]['score']}")
39
  else:
40
  st.write("Go on! Try the app!")
milestone3.py CHANGED
@@ -9,6 +9,7 @@ model = AutoModelForSequenceClassification.from_pretrained(model_name)
9
  tokenizer = AutoTokenizer.from_pretrained(model_name)
10
 
11
  classifier = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
 
12
  res = classifier(["I am very happy now.", "Not happy now."])
13
 
14
  for result in res:
 
9
  tokenizer = AutoTokenizer.from_pretrained(model_name)
10
 
11
  classifier = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
12
+ print(classifier.__class__)
13
  res = classifier(["I am very happy now.", "Not happy now."])
14
 
15
  for result in res: