rexarski's picture
[INITIAL] add .gitignore, app.py and requirements.txt
29cb445
raw
history blame
6.18 kB
from transformers import AutoModelForSequenceClassification, AutoTokenizer
import torch
import streamlit as st
import pandas as pd
model1 = AutoModelForSequenceClassification.from_pretrained(
"rexarski/bert-base-climate-fever-fixed"
)
tokenizer1 = AutoTokenizer.from_pretrained(
"rexarski/bert-base-climate-fever-fixed"
)
label_mapping1 = ["SUPPORTS", "REFUTES", "NOT_ENOUGH_INFO"]
model2 = AutoModelForSequenceClassification.from_pretrained(
"rexarski/distilroberta-tcfd-disclosure"
)
tokenizer2 = AutoTokenizer.from_pretrained("distilroberta-base")
label_mapping2 = [
"Governance a)",
"Governance b)",
"Metrics and Targets a)",
"Metrics and Targets b)",
"Metrics and Targets c)",
"Risk Management a)",
"Risk Management b)",
"Risk Management c)",
"Strategy a)",
"Strategy b)",
"Strategy c)",
]
def factcheck(text1, text2):
features = tokenizer1(
[text1],
[text2],
padding="max_length",
truncation=True,
return_tensors="pt",
max_length=512,
)
model1.eval()
with torch.no_grad():
scores = model1(**features).logits
labels = [
label_mapping1[score_max] for score_max in scores.argmax(dim=1)
]
return labels[0]
def tcfd_classify(text):
features = tokenizer2(
text,
padding="max_length",
truncation=True,
return_tensors="pt",
max_length=512,
)
model2.eval()
with torch.no_grad():
scores = model2(**features).logits
labels = [
label_mapping2[score_max] for score_max in scores.argmax(dim=1)
]
return labels[0]
data1 = {
"example": ["Example 1", "Example 2", "Example 3", "Example 4"],
"claim": [
"Sea ice has diminished much faster than scientists and climate models anticipated.",
"Climate Models Have Overestimated Global Warming",
"Climate skeptics argue temperature records have been adjusted in recent years to make the past appear cooler and the present warmer, although the Carbon Brief showed that NOAA has actually made the past warmer, evening out the difference.",
"Humans are too insignificant to affect global climate.",
],
"evidence": [
"Past models have underestimated the rate of Arctic shrinkage and underestimated the rate of precipitation increase.",
"""The 2017 United States-published National Climate Assessment notes that "climate models may still be underestimating or missing relevant feedback processes".""",
"""Reconstructions have consistently shown that the rise in the instrumental temperature record of the past 150 years is not matched in earlier centuries, and the name "hockey stick graph" was coined for figures showing a long-term decline followed by an abrupt rise in temperatures.""",
"Human impact on the environment or anthropogenic impact on the environment includes changes to biophysical environments and ecosystems, biodiversity, and natural resources caused directly or indirectly by humans, including global warming, environmental degradation (such as ocean acidification), mass extinction and biodiversity loss, ecological crisis, and ecological collapse.",
],
"label": ["SUPPORTS", "SUPPORTS", "NOT_ENOUGH_INFO", "REFUTES"],
}
data2 = {
"example": ["Example 1", "Example 2", "Example 3", "Example 4"],
"text": [
"As a global provider of transport and logistics services, we are often called on for expert input and industry insights by government representatives.",
"There are no sentences in the provided excerpts that disclose Scope 1 and Scope 2, and, if appropriate Scope 3 GHG emissions. The provided excerpts focus on other metrics and targets related to social impact investing, assets under management, and carbon footprint calculations.",
"""Our strategy needs to be resilient under a range of climate-related scenarios. This year we have undertaken climate-related scenario testing of a select group of customers in the thermal coal supply chain. We assessed these customers using two of the International Energy Agency’s scenarios; the ‘New Policies Scenario’ and the ‘450 Scenario’. Our reporting reflects the Financial Stability Board’s (FSB) Task Force on Climate-Related Disclosures (TCFD) recommendations. Using the FSB TCFD’s disclosure framework, we have begun discussions with some of our customers in emissions-intensive industries. The ESG Committee is responsible for reviewing and approving our climate change-related objectives, including goals and targets. The Board Risk Committee has formal responsibility for the overview of ANZ’s management of new and emerging risks, including climate change-related risks.""",
"AXA created a Group-level Responsible Investment Committee (RIC), chaired by the Group Chief Investment Officer, and including representatives from AXA Asset Management entities, representatives of Corporate Responsibility (CR), Risk Management and Group Communication.",
],
"label": [
"Risk Management a)",
"Metrics and Targets b)",
"Strategy c)",
"Goverance b)",
],
}
df1 = pd.DataFrame(data1)
df2 = pd.DataFrame(data2)
st.markdown("## Factchecking")
ex1_selected = st.selectbox(
"Select a climate claim-evidence pair", df1["example"]
)
selected_row1 = df1[df1["example"] == ex1_selected]
st.markdown(f'**Claim**: {selected_row1["claim"].values[0]}')
st.markdown(f'**Evidence**: {selected_row1["evidence"].values[0]}')
st.markdown(f'**Label**: {selected_row1["label"].values[0]}')
st.markdown("---")
st.markdown(
f'**Prediction**: {factcheck(selected_row1["claim"].values[0], selected_row1["evidence"].values[0])}'
)
st.markdown("## TCFD disclosure classification")
ex2_selected = st.selectbox("Select a TCFD disclosure example", df2["example"])
selected_row2 = df2[df2["example"] == ex2_selected]
st.markdown(f'**Text**: {selected_row2["text"].values[0]}')
st.markdown(f'**Label**: {selected_row2["label"].values[0]}')
st.markdown("---")
st.markdown(f'**Prediction**: {tcfd_classify(selected_row2["text"].values[0])}')