AI as a research method
Assistant:
Method:
Example:
Given a series of unstandardized dates -> AI models -> Standardized dates
from openai import OpenAI
# Client points at the local vLLM server; api_key is unused but required by the SDK
client = OpenAI(base_url="http://localhost:8000/v1", api_key="dummy")
# Raw data: noisy scraped values that need one consistent format
raw_data = [
"March 3rd, 2021",
"2021.03.03",
"03/03/21",
]
# Instruction applied to every input value
prompt_template = (
"Rewrite the date below as YYYY-MM-DD. "
"Return only the date, nothing else.\nDate: {value}"
)
# The LLM call: one request per input value
standardized_data = []
for value in raw_data:
response = client.chat.completions.create(
model="google/gemma-4-12B-it",
messages=[{"role": "user", "content": prompt_template.format(value=value)}],
temperature=0.0,
max_tokens=64,
)
# Returns: pull the reply text out of the response object
standardized_data.append(response.choices[0].message.content.strip())Example output
Example: Given a list of event descriptions from the Global Terrorism Database -> AI models -> Victims and aggressors, extracted and labeled
from openai import OpenAI
import json
# Client points at the local vLLM server; api_key is unused but required by the SDK
client = OpenAI(base_url="http://localhost:8000/v1", api_key="dummy")
# Raw data: short event descriptions to pull named entities from
events = [
"Gunmen linked to the Riverlands Front stormed a market in Dalcroft, killing two vendors before being detained by local police.",
"A bomb attributed to the Kestrel Brigade damaged a bus station in Merrow, injuring three commuters.",
]
# Options: the prompt states the two roles the model must choose between
prompt_template = (
"Read the event below and extract every named person or group mentioned. "
"Classify each one as one of two options: victim or aggressor.\n"
"Event: {event}"
)
# Output format: coerce the reply into this structure; each list only
# accepts strings, so every entity must be sorted into one of the two options
response_format = {"type": "json_schema", "json_schema": {
"name": "entity_extraction",
"schema": {
"type": "object",
"properties": {
"victims": {"type": "array", "items": {"type": "string"}},
"aggressors": {"type": "array", "items": {"type": "string"}},
},
},
}}
# The LLM call: one request per event
extracted_entities = []
for event in events:
response = client.chat.completions.create(
model="google/gemma-4-12B-it",
messages=[{"role": "user", "content": prompt_template.format(event=event)}],
temperature=0.0,
max_tokens=200,
response_format=response_format,
)
# Returns: parse the JSON reply into its victims and aggressors lists
parsed = json.loads(response.choices[0].message.content)
extracted_entities.append(parsed)Example output
You can stack multiple tasks together to create a pipeline.
Example: Given a series of scraped candidate wiki pages -> AI models (clean, then annotate) -> Partisanship and election metadata per candidate
from openai import OpenAI
import json
# Client points at the local vLLM server; api_key is unused but required by the SDK
client = OpenAI(base_url="http://localhost:8000/v1", api_key="dummy")
# Raw data: scraped wiki infobox HTML for a series of election candidates
raw_html_pages = [
"<div class='infobox'><h2>Barack Obama</h2><p>Obama was nominated by the <b>Democratic Party</b> for <b>President of the United States</b> in the <i>2008</i> election and defeated Republican nominee John McCain.</p></div>",
"<div class='infobox'><h2>John McCain</h2><p>McCain was the <b>Republican Party</b> nominee for <b>President of the United States</b> in the <i>2008</i> election and lost to Democrat Barack Obama.</p></div>",
]
# Stage 1 instruction: clean each scraped page into plain biography text
clean_prompt_template = "Strip the HTML below to plain text. Return only the text.\nHTML: {html}"
# Stage 1: one cleaning call per scraped page
clean_bios = []
for html in raw_html_pages:
response = client.chat.completions.create(
model="google/gemma-4-12B-it",
messages=[{"role": "user", "content": clean_prompt_template.format(html=html)}],
temperature=0.0,
max_tokens=200,
)
clean_bios.append(response.choices[0].message.content.strip())
# Stage 2 instruction: annotate partisanship and election details from the clean text
annotate_prompt_template = (
"Read the biography below and report the candidate's party, the office "
"they sought, the election year, and whether they won.\nBiography: {bio}"
)
# Stage 2 output format: coerce the reply into these four fields
response_format = {"type": "json_schema", "json_schema": {
"name": "candidate_annotation",
"schema": {
"type": "object",
"properties": {
"party": {"type": "string"},
"office": {"type": "string"},
"election_year": {"type": "string"},
"outcome": {"type": "string", "enum": ["won", "lost"]},
},
},
}}
# Stage 2: one annotation call per cleaned biography, chained from stage 1's output
annotations = []
for bio in clean_bios:
response = client.chat.completions.create(
model="google/gemma-4-12B-it",
messages=[{"role": "user", "content": annotate_prompt_template.format(bio=bio)}],
temperature=0.0,
max_tokens=100,
response_format=response_format,
)
# Returns: parse the JSON reply into its four annotated fields
annotations.append(json.loads(response.choices[0].message.content))Example output
Why they can be dangerous?
Caveats if you have to use it:
Why they can be dangerous?
Caveats if you have to use it:
AI outputs are not considered as the ground truth. It is human’s responsibility to validate them.
