Published
Edited
Apr 14, 2020
2 stars
Insert cell
md`# Tensorflow JS Toxicity Model

Example based on code provided at: https://github.com/tensorflow/tfjs-models/tree/master/toxicity`
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
parse_predictions(0)
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
viewof text_input = html`<textarea rows=10 cols=150>Google LLC is an American multinational technology company that specializes in Internet-related services and products, which include online advertising technologies, search engine, cloud computing, software, and hardware. It is considered one of the Big Four technology companies, alongside Amazon, Apple, and Facebook. Google was founded in September 1998 by Larry Page and Sergey Brin while they were Ph.D. students at Stanford University in California. Together they own about 14 percent of its shares and control 56 percent of the stockholder voting power through supervoting stock. They incorporated Google as a California privately held company on September 4, 1998, in California. Google was then reincorporated in Delaware on October 22, 2002. An initial public offering (IPO) took place on August 19, 2004, and Google moved to its headquarters in Mountain View, California, nicknamed the Googleplex. In August 2015, Google announced plans to reorganize its various interests as a conglomerate called Alphabet Inc. Google is Alphabet's leading subsidiary and will continue to be the umbrella company for Alphabet's Internet interests. Sundar Pichai was appointed CEO of Google, replacing Larry Page who became the CEO of Alphabet.</textarea>`
Insert cell
Insert cell
// Load the model.
model = toxicity.load();
Insert cell
toxicity = require('@tensorflow-models/toxicity');
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more