furquan commited on
Commit
50116f8
1 Parent(s): cba4fd1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -1,16 +1,18 @@
1
  import gradio as gr
2
  import torch
3
 
4
- from transformers import pipeline, AutoTokenizer, AutoModel
5
 
6
  #pipe = pipeline("text-generation", model="furquan/opt_2_7_b_prompt_tuned_sentiment_analysis", trust_remote_code=True, cache_dir="/local/home/furquanh/myProjects/week12/").to('cuda')
7
 
8
- tokenizer = AutoTokenizer.from_pretrained("furquan/opt-1-3b-prompt-tuned-sentiment-analysis", trust_remote_code=True)
9
- model = AutoModel.from_pretrained("furquan/opt-1-3b-prompt-tuned-sentiment-analysis", trust_remote_code=True)
 
 
10
 
11
 
12
  title = "OPT-1.3B"
13
- description = "This demo uses meta's opt-1.3b Causal LM as base model that was prompt tuned on the Stanford Sentiment Treebank-5 way dataset to only output the sentiment of a given text."
14
  article = "<p style='text-align: center'><a href='https://arxiv.org/pdf/2104.08691.pdf' target='_blank'>The Power of Scale for Parameter-Efficient Prompt Tuning</a></p>"
15
 
16
 
@@ -20,9 +22,9 @@ def sentiment(text):
20
  tokenized = tokenizer(text, return_tensors='pt')
21
  with torch.no_grad():
22
  outputs = model.generate(
23
- input_ids=tokenized["input_ids"], attention_mask=tokenized["attention_mask"]
24
  )
25
- return f"text: {text} Sentiment: {tokenizer.decode(outputs[0][-3:], skip_special_tokens=True)}"
26
 
27
  iface = gr.Interface(fn=sentiment, inputs="text", outputs="text", title=title,
28
  description=description, article=article)
 
1
  import gradio as gr
2
  import torch
3
 
4
+ from transformers import pipeline, AutoTokenizer, AutoModel, LlamaForCausalLM
5
 
6
  #pipe = pipeline("text-generation", model="furquan/opt_2_7_b_prompt_tuned_sentiment_analysis", trust_remote_code=True, cache_dir="/local/home/furquanh/myProjects/week12/").to('cuda')
7
 
8
+ # tokenizer = AutoTokenizer.from_pretrained("furquan/opt-1-3b-prompt-tuned-sentiment-analysis", trust_remote_code=True)
9
+ # model = AutoModel.from_pretrained("furquan/opt-1-3b-prompt-tuned-sentiment-analysis", trust_remote_code=True)
10
+ model = LlamaForCausalLM.from_pretrained("meta-llama/Llama-2-7b-chat-hf")
11
+ tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-2-7b-chat-hf")
12
 
13
 
14
  title = "OPT-1.3B"
15
+ description = "This demo uses meta's LLama-2-7b Causal LM as base model that was prompt tuned on the Stanford Sentiment Treebank-5 way dataset to only output the sentiment of a given text."
16
  article = "<p style='text-align: center'><a href='https://arxiv.org/pdf/2104.08691.pdf' target='_blank'>The Power of Scale for Parameter-Efficient Prompt Tuning</a></p>"
17
 
18
 
 
22
  tokenized = tokenizer(text, return_tensors='pt')
23
  with torch.no_grad():
24
  outputs = model.generate(
25
+ input_ids=tokenized["input_ids"], attention_mask=tokenized["attention_mask"], max_new_tokens=1
26
  )
27
+ return f"text: {text} Sentiment: {tokenizer.decode(outputs[0], skip_special_tokens=True).split(' ')[-1]}"
28
 
29
  iface = gr.Interface(fn=sentiment, inputs="text", outputs="text", title=title,
30
  description=description, article=article)