Published
Edited
Mar 5, 2020
1 star
Also listed in…
NLP
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
normalizedDoc = nlp(text.value).normalize({
whitespace: true, // remove hyphens, newlines, and force one space between words
punctuation: true, // remove commas, semicolons - but keep sentence-ending punctuation
case: true, // keep only first-word, and 'entity' titlecasing
numbers: true, // 'one' → '1'
plurals: true, // 'eyes' → 'eye'
verbs: true, // 'swtiched' → 'switch'
})
Insert cell
lines = text.value.split('\n')
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
md `${await printTable(headers, lines)}`
Insert cell
async function printTable(headers, lines) {
// header row
let markdown = `| ${headers.join(' | ')} |\n|`;
headers.forEach(header => { markdown += ' --- |'});
// run text lines through toxicity model classifier
const table = toxicityModel.classify(lines).then(predictions => {
for (let i=0; i<lines.length; i++) {
markdown += '\n| ' + lines[i] + ' |';
for (let k=0; k < labels.length; k++) {
// convert toxicity classifier predictions to md cells with ✔️
markdown += predictions[k].results[i].match ? ' ✔️ |': ' . |';
}
}
console.log(predictions);
return Promise.resolve(markdown);
});
return table;
}
Insert cell
Insert cell
tf = require('@tensorflow/tfjs@1.0')
Insert cell
toxicity = require('https://cdn.jsdelivr.net/npm/@tensorflow-models/toxicity')
Insert cell
nlp = require('compromise@11.14.3')
Insert cell
Insert cell
Insert cell
Insert cell
nlpStyles = html `
<style>
.scrollable-container {
max-height: 400px;
overflow: auto;
}
.short-list {
max-height: 200px;
}
.big{
font-size:1.5rem;
color:cornflowerblue;
}
.small{
color:grey;
margin-top:30px;
}
.term { color:grey; cursor:pointer;}
.nl-Person { border-bottom:2px solid #6393b9; }
.nl-Pronoun { border-bottom:2px solid #81acce; }
.nl-Plural { border-bottom:2px solid steelblue; }
.nl-Singular { border-bottom:2px solid lightsteelblue; }
.nl-Verb { border-bottom:2px solid palevioletred; }
.nl-Adverb { border-bottom:2px solid #f39c73; }
.nl-Adjective { border-bottom:2px solid #b3d3c6; }
.nl-Determiner { border-bottom:2px solid #d3c0b3; }
.nl-Preposition { border-bottom:2px solid #9794a8; }
.nl-Conjunction { border-bottom:2px solid #c8c9cf; }
.nl-Value { border-bottom:2px solid palegoldenrod; }
.nl-QuestionWord { border-bottom:2px solid lavender; }
.nl-Acronym { border-bottom:2px solid violet; }
.nl-Possessive { border-bottom:2px solid #7990d6; }
.nl-Noun { border-bottom:2px solid #7990d6; }
.nl-Expression { border-bottom:2px solid #b3d3c6; }
.nl-Negative { border-bottom:2px solid #b4adad; }
</style>
`
Insert cell
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