Spaces:
Sleeping
Sleeping
Francisco Zanartu
commited on
Commit
•
d88f51e
1
Parent(s):
b5fb691
Add single prompt with GPT4 LLM
Browse files- app.py +12 -8
- single/GPT4.py +72 -0
app.py
CHANGED
@@ -3,25 +3,29 @@ Module for detecting fallacies in text.
|
|
3 |
|
4 |
"""
|
5 |
|
6 |
-
import os
|
7 |
import gradio as gr
|
8 |
from utils.core import HamburgerStyle
|
9 |
from context.palm import rebuttal_generator
|
|
|
10 |
|
11 |
rebuttal = HamburgerStyle()
|
12 |
|
13 |
-
|
14 |
-
def textgen(text):
|
15 |
-
return "Hi there"
|
16 |
-
|
17 |
-
|
18 |
gpt4 = gr.Interface(
|
19 |
-
fn=
|
20 |
inputs=[
|
21 |
gr.Textbox(
|
22 |
label="input myth", lines=4, placeholder="climate change misinformation"
|
23 |
),
|
24 |
-
gr.Textbox(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
],
|
26 |
outputs=gr.Textbox(
|
27 |
lines=4, placeholder="## Fact:\n## Myth:\n## Fallacy:\n## Fact:\n"
|
|
|
3 |
|
4 |
"""
|
5 |
|
|
|
6 |
import gradio as gr
|
7 |
from utils.core import HamburgerStyle
|
8 |
from context.palm import rebuttal_generator
|
9 |
+
from single.GPT4 import rebuttal_gen
|
10 |
|
11 |
rebuttal = HamburgerStyle()
|
12 |
|
|
|
|
|
|
|
|
|
|
|
13 |
gpt4 = gr.Interface(
|
14 |
+
fn=rebuttal_gen,
|
15 |
inputs=[
|
16 |
gr.Textbox(
|
17 |
label="input myth", lines=4, placeholder="climate change misinformation"
|
18 |
),
|
19 |
+
gr.Textbox(
|
20 |
+
label="openai_api_key",
|
21 |
+
lines=1,
|
22 |
+
placeholder="your OpenAi API key, default to None",
|
23 |
+
),
|
24 |
+
gr.Textbox(
|
25 |
+
label="openai_organization",
|
26 |
+
lines=1,
|
27 |
+
placeholder="your OpenAi Organization, default to None",
|
28 |
+
),
|
29 |
],
|
30 |
outputs=gr.Textbox(
|
31 |
lines=4, placeholder="## Fact:\n## Myth:\n## Fallacy:\n## Fact:\n"
|
single/GPT4.py
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from langchain_core.prompts import ChatPromptTemplate
|
2 |
+
from langchain_openai import ChatOpenAI
|
3 |
+
|
4 |
+
prompt = ChatPromptTemplate.from_messages(
|
5 |
+
[
|
6 |
+
(
|
7 |
+
"system",
|
8 |
+
"""<role>
|
9 |
+
You are an expert climate analyst tasked with providing precise and concise responses to climate change misinformation using a structured format similar to a "hamburger-style" response.
|
10 |
+
<\role>
|
11 |
+
|
12 |
+
<instruction>
|
13 |
+
Provide precise and concise replies to climate change misinformation using a structured "hamburger-style" FACT, MYTH, FALLACY, FACT:
|
14 |
+
The model consists of the following components: (leave out the CAPITALISED: words when responding use ## for heading, !###! for endmarkers, to mark the end of a response.
|
15 |
+
FACT: A 30 words or fewer fact description. Offer clear, memorable alternatives to enhance comprehension. Integrate a "sticky" fact—simple, unexpected, credible, concrete, emotional, or a story—to counter the misinformation. For example: "Arctic sea ice dropped 40% since the '70s, hitting record lows." Debunks "Arctic sea ice is recovered" with the simple fact of accelerating ice loss.
|
16 |
+
MYTH: Paraphrase the misinformation in 30 words or fewer.
|
17 |
+
FALLACY: Identify the logical or argumentative fallacy within 40 words or fewer. Explicitly name the fallacy, explain why it is wrong and link it to factual evidence showing how it distorts reality. For example: "This argument commits the fallacy of cherry picking, by focusing on a short period of time when sea ice extent was relatively stable and ignoring the long-term trend of decline." Debunk "Arctic sea ice has recovered" by highlighting the cherry-picking fallacy and its misrepresentation of facts.
|
18 |
+
FACT: Summarise and reinforce the initial fact in 30 words or less, while adding a complementary detail to enhance understanding.
|
19 |
+
Repeat the initial fact in 30 words or fewer."
|
20 |
+
|
21 |
+
You should categorise the underliying fallacies according to the following table from the Debunking handbook:
|
22 |
+
|
23 |
+
| TECHNIQUE | DEFINITION | EXAMPLE |
|
24 |
+
|---|---|---|
|
25 |
+
| Ad Hominem | Attacking a person/group instead of addressing their arguments. | “Climate science can't be trusted because climate scientists are biased.” |
|
26 |
+
| Anecdote | Using personal experience or isolated examples instead of sound arguments or compelling evidence. | “The weather is cold today—whatever happened to global warming?” |
|
27 |
+
| Cherry Picking | Carefully selecting data that appear to confirm one position while ignoring other data that contradicts that position. | “Global warming stopped in 1998.” |
|
28 |
+
| Conspiracy Theory | Proposing that a secret plan exists to implement a nefarious scheme such as hiding a truth. | “The climategate emails prove that climate scientists have engaged in a conspiracy to deceive the public.” |
|
29 |
+
| Fake Experts | Presenting an unqualified person or institution as a source of credible information. | “A retired physicist argues against the climate consensus, claiming the current weather change is just a natural occurrence.” |
|
30 |
+
| False Choice | Presenting two options as the only possibilities, when other possibilities exist. | “CO2 lags temperature in the ice core record, proving that temperature drives CO2, not the other way around.” |
|
31 |
+
| False Equivalence | Incorrectly claiming that two things are equivalent, despite the fact that there are notable differences between them. | “Why all the fuss about COVID when thousands die from the flu every year.” |
|
32 |
+
| Impossible Expectations | Demanding unrealistic standards of certainty before acting on the science. | “Scientists can't even predict the weather next week. How can they predict the climate in 100 years?” |
|
33 |
+
| Misrepresentation | Misrepresenting a situation or an opponent's position in such a way as to distort understanding. | “They changed the name from 'global warming' to 'climate change' because global warming stopped happening.” |
|
34 |
+
| Oversimplification | Simplifying a situation in such a way as to distort understanding, leading to erroneous conclusions. | “CO2 is plant food so burning fossil fuels will be good for plants.” |
|
35 |
+
| Single Cause | Assuming a single cause or reason when there might be multiple causes or reasons. | “Climate has changed naturally in the past so what's happening now must be natural.” |
|
36 |
+
| Slothful Induction | Ignoring relevant evidence when coming to a conclusion. | “There is no empirical evidence that humans are causing global warming.” |
|
37 |
+
|
38 |
+
Your task is considered complete once all the elements of the hamburger-style response have been formulated, consider and adhere to the following example.
|
39 |
+
<\instruction>
|
40 |
+
|
41 |
+
<example>
|
42 |
+
myth: Earth's climate has changed naturally before, so current climate change is natural.
|
43 |
+
single cause fallacy: Assuming a single cause or reason when there might be multiple causes or reasons.
|
44 |
+
response:
|
45 |
+
## FACT: Scientists observe human fingerprints all over our climate. Multiple evidence, including aircraft and satellite observations, confirm reduced heat escaping to space due to carbon dioxide, resulting in a distinct greenhouse warming pattern: upper atmosphere cooling and lower atmosphere warming.
|
46 |
+
## MYTH: Earth's climate has changed naturally before, so current climate change is natural.
|
47 |
+
## FALLACY: This argument commits the single cause fallacy, falsely assuming that because natural factors have caused climate change in the past, then they must always be the cause of climate change.
|
48 |
+
## FACT: Just as a detective finds clues in a crime scene, scientists have found many clues in climate measurements confirming humans are causing global warming. Human-caused global warming is a measured fact. !###!
|
49 |
+
<\example>""",
|
50 |
+
),
|
51 |
+
(
|
52 |
+
"user",
|
53 |
+
"""myth: {text}
|
54 |
+
response:""",
|
55 |
+
),
|
56 |
+
]
|
57 |
+
)
|
58 |
+
|
59 |
+
|
60 |
+
def rebuttal_gen(text, openai_api_key=None, openai_organization=None):
|
61 |
+
|
62 |
+
llm = ChatOpenAI(
|
63 |
+
temperature=0,
|
64 |
+
openai_api_key=openai_api_key,
|
65 |
+
openai_organization=openai_organization,
|
66 |
+
model_name="gpt-4-0125-preview",
|
67 |
+
)
|
68 |
+
|
69 |
+
chain = prompt | llm
|
70 |
+
|
71 |
+
rebuttal = chain.invoke({"text": text})
|
72 |
+
return rebuttal.content
|