amandakonet commited on
Commit
bbe40df
1 Parent(s): 3ca4a20
Files changed (1) hide show
  1. app.py +27 -2
app.py CHANGED
@@ -1,9 +1,15 @@
1
- from transformers import pipeline
 
 
2
  import streamlit as st
3
  import pandas as pd
4
  from PIL import Image
5
  import os
6
 
 
 
 
 
7
  # read in example
8
  ex_claims = ['Global warming is driving polar bears toward extinction',
9
  'Global warming is driving polar bears toward extinction',
@@ -85,6 +91,9 @@ ex_labels = ['NOT_ENOUGH_INFO',
85
 
86
  ex_df = pd.DataFrame({'claim' : ex_claims, 'evidence' : ex_evidence, 'label': ex_labels})
87
 
 
 
 
88
  # title
89
  st.title('Combatting Climate Change Misinformation with Transformers')
90
 
@@ -165,8 +174,9 @@ st.markdown("* evidence *refutes* (contradicts) claim")
165
  st.markdown("* evidence *does not provide enough info to support or refute* (neutral) claim")
166
  st.markdown("For this project, I fine-tune ClimateBERT (4) on the text entailment task")
167
 
 
 
168
  st.markdown("## Try it out!")
169
- txt_class = pipeline('text-classification', model='amandakonet/climatebert-fact-checking', use_auth_token = os.environ["hf_token"])
170
 
171
  # select climate claim
172
  option_claim = st.selectbox('Select a climate claim to test', ex_df['claim'].unique())
@@ -181,6 +191,21 @@ st.write('You selected:', option_evidence)
181
 
182
  st.write(type(option))
183
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
  # section 6: analysis
185
  st.markdown("## Critical Analysis")
186
  st.markdown("What else could we do?")
 
1
+ ## SETUP #####################################################################################################################
2
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
+ import torch
4
  import streamlit as st
5
  import pandas as pd
6
  from PIL import Image
7
  import os
8
 
9
+ # load model
10
+ model = AutoModelForSequenceClassification.from_pretrained("amandakonet/climatebert-fact-checking")
11
+ tokenizer = AutoTokenizer.from_pretrained("amandakonet/climatebert-fact-checking")
12
+
13
  # read in example
14
  ex_claims = ['Global warming is driving polar bears toward extinction',
15
  'Global warming is driving polar bears toward extinction',
 
91
 
92
  ex_df = pd.DataFrame({'claim' : ex_claims, 'evidence' : ex_evidence, 'label': ex_labels})
93
 
94
+
95
+ ## TEXT ######################################################################################################################
96
+
97
  # title
98
  st.title('Combatting Climate Change Misinformation with Transformers')
99
 
 
174
  st.markdown("* evidence *does not provide enough info to support or refute* (neutral) claim")
175
  st.markdown("For this project, I fine-tune ClimateBERT (4) on the text entailment task")
176
 
177
+ ## EXAMPLE ###################################################################################################################
178
+
179
  st.markdown("## Try it out!")
 
180
 
181
  # select climate claim
182
  option_claim = st.selectbox('Select a climate claim to test', ex_df['claim'].unique())
 
191
 
192
  st.write(type(option))
193
 
194
+ st.markdown("Now, we can use your selected (claim,evidence) pair in the fine-tuned transformer!")
195
+
196
+
197
+ # tokenize
198
+ features = tokenizer(option_claim, option_evidence,
199
+ padding='max_length', truncation=True, return_tensors="pt", max_length=512)
200
+
201
+ # set model into eval
202
+ model.eval()
203
+ with torch.no_grad():
204
+ scores = model(**features).logits
205
+ label_mapping = ['contradiction', 'entailment', 'neutral']
206
+ labels = [label_mapping[score_max] for score_max in scores.argmax(dim=1)]
207
+ print("The claim: ", option_claim, "is ", labels ", by ", option_evidence)
208
+
209
  # section 6: analysis
210
  st.markdown("## Critical Analysis")
211
  st.markdown("What else could we do?")