Platform
Resources
Pricing
Sign in
Contact us
Matteo Abrate
Web Datavis researcher by day, Indie Game designer by night
Workspace
Fork
Public
By
Matteo Abrate
Edited
Feb 28
Fork of
Tensorflow JS Toxicity Model
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
format_count
=
d3
.
format
(
".0%"
)
Insert cell
color
=
d3
.
scaleOrdinal
(
results
.
map
(
d
=>
d
.
label
)
,
d3
.
schemeCategory10
)
Insert cell
results
=
predictions
[
0
]
.
results
.
length
<=
0
?
[
]
:
predictions
.
map
(
d
=>
(
{
label
:
d
.
label
,
probability
:
d
.
results
[
0
]
.
probabilities
[
1
]
}
)
)
Insert cell
predictions
Insert cell
/*html`<div class="predictions">
${comments.map((c, i) => {
return `<div class="prediction"><p>${c}</p><div class="labels">${parse_predictions(i)}</div></div>`
})}
</div>`*/
Insert cell
function
parse_predictions
(
i
)
{
return
predictions
.
map
(
l
=>
`<span class="${
l
.
label
}">${
l
.
label
}=${
l
.
results
[
i
]
.
match
} (${
l
.
results
[
i
]
.
probabilities
[
1
]
.
toFixed
(
2
)
})</span>`
)
.
join
(
" "
)
}
Insert cell
// Finding the answers
predictions
=
model
.
classify
(
comments
)
;
Insert cell
model
.
tokenizer
Insert cell
comments
=
text_input
.
replace
(
/\.\s+([A-Z])/g
,
".\n$1"
)
.
split
(
"\n"
)
.
filter
(
x
=>
x
.
length
>
0
)
Insert cell
text_input
Insert cell
Insert cell
// Load the model.
model
=
toxicity
.
load
(
)
;
Insert cell
toxicity
=
require
(
'@tensorflow-models/toxicity'
)
;
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.
Try it for free
Learn more
Compare fork
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
text_input
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
format_count
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
color
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
results
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
parse_predictions
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
predictions
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
comments
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
model
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
toxicity
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML