Public
Edited
May 6, 2024
Importers
Insert cell
Insert cell
Insert cell
navio(zeroShotArray, {height: 500, attribWidth: 16})
Insert cell
// viewof zeroShot = navio(zeroShotArray, {height: 500, attribWidth: 16})
Insert cell
// navio(ToTFewShotsArray, {height: 500, attribWidth: 16})
Insert cell
// viewof zeroShotWithRules = navio(zeroShotWithRulesArray,{height: 500, attribWidth: 16})
Insert cell
Insert cell
Insert cell
// {
// return html`
// <div style="display: flex;">
// <div style="flex-basis:35%">${viewof zeroShot} </div>
// <div style="flex-basis:35%">${viewof CoTFewShots}</div>
// <div style="flex-basis:35%">${viewof zeroShotWithRules} </div>
// </div>`}
Insert cell
{
const treeSvg = Tree(hierarchyZeroShot, {
label: (d) => {
return d[0];
},
width: 1100,
fontSize: 14
});
return htl.html`<h2>Class/Subclass/Subsubclass Taxonomy Zero Shot</h2>
<div>${treeSvg}</div>`;
}
Insert cell
{
const treeSvg = Tree(hierarchyfewShotCOT, {
label: (d) => {
return d[0];
},
width: 1100,
fontSize: 14
});
return htl.html`<h2>Class/Subclass/Subsubclass Taxonomy Few-Shot Chain-of-Thought Prompting</h2>
<div>${treeSvg}</div>`;
}
Insert cell
{
const treeSvg = Tree(hierarcyToT, {
label: (d) => {
return d[0];
},
width: 1100,
fontSize: 14
});
return htl.html`<h2>Class/Subclass/Subsubclass Taxonomy Tree-of-Thoughts Few-Shot Prompting</h2>
<div>${treeSvg}</div>`;
}
Insert cell
Insert cell
myPanel = panel
Insert cell
import { panel } with {
zeroShotArray as data,
defaultGroupBy,
defaultColorBy,
defaultLayout
} from "a578473b724795d5"
Insert cell
defaultLayout = "pack"
Insert cell
defaultColorBy = "Country"
Insert cell
defaultGroupBy = "Country"
Insert cell
import {Tree} from "@john-guerra/tidy-tree-component"
Insert cell
// hireachyFewShot = hierarchy(fewShotsProcessed)
Insert cell
hierarchyZeroShot = hierarchy(zeroShotArray,"latest_prompt")
Insert cell
hierarchyfewShotCOT = hierarchy(fewShotCOTArray,"latest_prompt")
Insert cell
hierarcyToT = hierarchy(ToTFewShotsArray,"latest_prompt")
Insert cell
function hierarchy(items, type) {
const hierarchy = new Map();
items.forEach(item => {
// Ensure item['Classes of irresponsible AI use'] is treated as an array
const classes = item ? Array.isArray(item['Classes of irresponsible AI use'])
? item['Classes of irresponsible AI use']
: [item['Classes of irresponsible AI use']] : [];

classes.forEach(classKey => {
// Initialize a Map for this classKey if it doesn't exist
if (!hierarchy.has(classKey)) {
hierarchy.set(classKey, new Map());
}

const classMap = hierarchy.get(classKey);

// Process subclasses if this classKey is a key in the subclass object
if (item['Subclasses'] && item['Subclasses'][classKey]) {
const subclassArray = item['Subclasses'][classKey];
subclassArray.forEach(subclassItem => {
// Initialize a Map for this subclassItem under classKey
if (!classMap.has(subclassItem)) {
classMap.set(subclassItem, new Map());
}
const subclassMap = classMap.get(subclassItem);

// Process sub-subclasses based on the type
if (type === 'zeroShot' && item['Sub-subclasses'] && item['Sub-subclasses'][subclassItem]) {
const subsubclassArray = item['Sub-subclasses'][subclassItem];
subsubclassArray.forEach(subsubclassItem => {
// Initialize an array for this subsubclassItem under subclassItem if it doesn't exist
if (!subclassMap.has(subsubclassItem)) {
subclassMap.set(subsubclassItem, []);
}
});
} else if (type === 'zeroShotRules' && item['Sub-subclass'] && item['Sub-subclass'][classKey] && item['Sub-subclass'][classKey][subclassItem]) {
const subsubclassArray = item['Sub-subclass'][classKey][subclassItem];
subsubclassArray.forEach(subsubclassItem => {
// Initialize an array for this subsubclassItem under subclassItem if it doesn't exist
if (!subclassMap.has(subsubclassItem)) {
subclassMap.set(subsubclassItem, []);
}
});
} else if (type === 'latest_prompt' && item['Sub-subclass'] && item['Sub-subclass'][subclassItem]) {
const subsubclassArray = item['Sub-subclass'][subclassItem];
subsubclassArray.forEach(subsubclassItem => {
// Initialize an array for this subsubclassItem under subclassItem if it doesn't exist
if (!subclassMap.has(subsubclassItem)) {
subclassMap.set(subsubclassItem, []);
}
});
}
});
}
});
});

return hierarchy;
}
Insert cell
viewof zeroShotUnrolled = {
// Generates an object where each groupBy attribute is a field and the value is a function spliting by that attribute
const objForDerive = Object.fromEntries(
groupByZeroShot.map((a) => [a, aq.escape((d) => op.split(d[a], ","))])
);

let df = aq
.from(zeroShotArray)
.derive(objForDerive);

for (let a of groupByZeroShot) {
df = df.unroll(a);
}

return df
.view();
}
Insert cell
viewof zeroShotResultsTable = {
let df = aq.from(zeroShotArray);

return df.view();
}
Insert cell
attribs_zeroShot = Object.keys(zeroShotArray[0])
Insert cell
Insert cell
selectedIncidents = {
const ids = [0,1,2,3,4,5,6,9,10,11,13,14,451,382,505,167,39]
const id_set = new Set(ids)
const selectedFieldsArray = mergedIncidentsArr.map(item => {
return {
title: item.title,
'incident id': item['incident id'],
description: item.description,
'date occurrence': item.date,
'date publicly known': item['date published'],
};
});
const selectedIncidentsArr = selectedFieldsArray.filter(item => id_set.has(+item['incident id']))

return selectedIncidentsArr
}
Insert cell
zeroShotArray
Insert cell
Insert cell
Insert cell
zeroShotArray
Insert cell
zeroShotArray = {
//zeroShotFile consists of 16 incidents, including the awful AI incident
const zeroShotFile = await FileAttachment("zero_shot_1_processed_results_2024_03_26_17_08.json").json();
//zeroShotFile2 consists of incident 39
const zeroShotFile2 = await FileAttachment("zero_shot_39_processed_results_2024_03_26_17_16.json").json();
const zeroShotArray = Object.entries(zeroShotFile).map(([key,value]) => {
return {id : key,
...value};
})

const obj_39 = Object.entries(zeroShotFile2).map(([key,value]) => {
return {id: key,
...value}
})

//merging the incidents together to one in zeroShotArray
zeroShotArray.push(obj_39[0])

// post-processing here to merge the rest of the fields from incident AI database, such as date, title, description, to the zeroShotArray results
let zeroShotMergedArray = zeroShotArray.map((item,index)=>{
const incident = selectedIncidents.find(i=> +i["incident id"] === +item.id)
if(incident){
return {
...item,
title: incident.title,
description: incident.description,
"date occurrence": incident["date occurrence"],
"date publicly known": incident["date publicly known"]
}
}
}
)
return zeroShotMergedArray
}
Insert cell
Insert cell
Insert cell
fewShotCOTArray = {
//fewShotFile consists of 15 incidents
const fewShotFile = await FileAttachment("cot_1_processed_results_2024_03_26_16_21.json").json();
//fewShotFile2 consists of incident 0 (from awful ai database)
const fewShotFile2 = await FileAttachment("cot_0_processed_results_2024_03_26_16_40.json").json();
//fewShotFile3 consists of incident 39
const fewShotFile3 = await FileAttachment("cot_39_processed_results_2024_03_26_17_19.json").json();
const fewShotArray = Object.entries(fewShotFile).map(([key,value]) => {
return {id : key,
...value};
})

const obj_39 = Object.entries(fewShotFile3).map(([key,value]) => {
return {id: key,
...value}
})
const obj_0 = Object.entries(fewShotFile2).map(([key,value]) => {
return {id: key,
...value}
})

//merging the incidents together to one in fewShotArray
fewShotArray.push(obj_39[0])
fewShotArray.push(obj_0[0])
// post-processing here to merge the rest of the fields from incident AI database, such as date, title, description, to the fewShotArray results
let fewShotMergedArray = fewShotArray.map((item,index)=>{
const incident = selectedIncidents.find(i=> +i["incident id"] === +item.id)
if(incident){
return {
...item,
title: incident.title,
description: incident.description,
"date occurrence": incident["date occurrence"],
"date publicly known": incident["date publicly known"]
}
}
}
)
return fewShotMergedArray
}
Insert cell
Insert cell
Insert cell
ToTFewShotsArray = {
//ToTFile consists of 16 incidents including one awful AI data (incident id 0)
const ToTFile = await FileAttachment("tot_1_processed_results_2024_03_26_16_58.json").json();
//ToTFile2 consists of incident 39 (from awful ai database)
const ToTFile2 = await FileAttachment("tot_39_processed_results_2024_03_26_17_26.json").json();

const ToTArray = Object.entries(ToTFile).map(([key,value]) => {
return {id : key,
...value};
})

const obj_39 = Object.entries(ToTFile2).map(([key,value]) => {
return {id: key,
...value}
})

//merging the incidents together to one in ToTArray
ToTArray.push(obj_39[0])
// post-processing here to merge the rest of the fields from incident AI database, such as date, title, description, to the ToTArray results
let ToTMergedArray = ToTArray.map((item,index)=>{
const incident = selectedIncidents.find(i=> +i["incident id"] === +item.id)
if(incident){
return {
...item,
title: incident.title,
description: incident.description,
"date occurrence": incident["date occurrence"],
"date publicly known": incident["date publicly known"]
}
}
}
)
return ToTMergedArray
}
Insert cell
selectedIncidents
Insert cell
// mergedIncidentsArray = [...mergedIncidents.values()]
mergedIncidentsArray = incidents

Insert cell
mergedIncidentsArr = {
const obj_0 = {"title":"AI's Environmental Footprint","incident id":0,"url":"https://earth.org/the-green-dilemma-can-ai-fulfil-its-potential-without-harming-the-environment/","news":null,"description":"The environmental footprint of AI, particularly in training large models, is significant. According to a study by researchers at the University of Massachusetts, the energy used in training certain popular large AI models can produce about 626,000 pounds of carbon dioxide. This amount is equivalent to roughly 300 round-trip flights between New York and San Francisco, highlighting the substantial carbon footprint associated with advanced AI technologies. This data underscores the need for more sustainable practices in the field of AI to mitigate its impact on climate change.","awful-ai md":null,"date":"2023-07-18","date published":"2023-07-18","Affected Population":"General Human","Actual Impact":"unknown","Potential Impact":"unknown","Application":"AI training","Area":"tech","class":"environmental impact","subclass":null,"subsubclass":null,"city":null,"state":null,"country":"United States of America","continent":"North America","company ":null,"company city":null,"company state":null,"company country":null,"Online":"Not online","source":"awful-ai","thumb":null,"tags":null,"curated":null,"Researcher":null,"Comments":null,"News Outlet":null}
// mergedIncidentsArray.push(obj_0)
let mergedIncidentsArr = []
mergedIncidentsArr = [...mergedIncidentsArray,obj_0]
const i = mergedIncidentsArray.find(i=> +i["incident id"]===0)
return mergedIncidentsArr
}
Insert cell
import {mergedIncidents,incidents} from "126c228131c034d7"
Insert cell
import {aq, op} from "@uwdata/arquero"
Insert cell
// import { BubbleChart } from "@d3/bubble-chart-component"
import {Pack } from "@d3/pack-component"
Insert cell
import {Icicle} from "@d3/icicle-component"
Insert cell
import {multiAutoSelect} from "@john-guerra/multi-auto-select"
Insert cell
import {SpaceTree} from "@john-guerra/spacetree"
Insert cell
// d3 = require("d3@7")
Insert cell
import {navio} from "@john-guerra/navio"
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more