Page 25 - MSDN Magazine, May 2017
P. 25

Raw Content
different classifiers for image, text, and video, and CSAM, which stands for Child Sexual Abuse Material. PhotoDNA is the technol- ogy that helps organizations fight the spread of these images. The CSAM “classifier” works a little differently from the ones I mentioned previously: PhotoDNA uses a hash and match technology that compares against a database of known images. Within Content Moder- ator, you can set up workflows that connect several filters (for example, first check for CSAM, then for Adult/Racy in images). The workflow can call out to humans for review, as well. Finally, the Content Moderator pipe-
Content Moderator APIs
[ Moderation | Jobs | Reviews | Workflows ]
CSAM
• Detection • Reporting
Image
• Adult • Racy • OCR
Text
• Profanity • Adult
• Racy
• Offensive • Malware
Video
• Adult • Racy
Other APIs Review
Human- in-the-Loop Review UX
API
...
Filtered
Content line is flexible and in the future other APIs
Figure 1 User Content Flows Through Content Moderator, Where Machine Learning Models and Humans Work Together to Filter out Indecent Material
can be hooked in, as well.
Moderate Your Users’ Content
enforcement worldwide with curbing child exploitation. Microsoft has offered PhotoDNA as a free service since 2009, and the same team now also presents content moderation.
Content moderation is an area of machine learning where comput- ers can help humans tremendously. The amount of data generated by users is simply too much for humans to review quickly and in a cost- effective way. More important, content moderation isn’t a pleasant activity for humans. For a little background, see tcrn.ch/2n1d9M0.
Content Moderation is a member of the growing set of the Microsoft Cognitive Services APIs that run in Azure. These APIs are all specific implementations of machine learning models, which means Microsoft has trained these models with lots of data. As a developer, you just call one of the APIs to get a result, whether for computer vision, speaker recognition or language understanding, to name but a few. The Content Moderator Image API uses image recognition—an area of machine learning where a lot of progress has been made in recent years.
Figure 1 shows how the Content Moderator pipeline is set up. Depending on your needs, content moderation offers different APIs to call, including moderation, review and jobs in increasing levels of customizability. For example, the workflow API allows you to program- matically modify workflows that are used for jobs. Next, you can see the
Figure 2 Dialog Code
Now that you have some understanding of the moderation technology, let’s plug it into our Butterfly bot. We’ll build the bot with the Microsoft Bot Framework, using the Node. js flavor of the Bot Framework for Butterfly. Because all of these APIs are mere REST API calls, you could moderate your content just as easily from C#; actually, this could arguably even be easier
as there’s a .NET SDK for Content Moderator (bit.ly/2mXQqQV). There have been several articles in this magazine that give excellent overviews of bots. If you haven’t built one yet, I highly
recommend checking out the following:
• “Solving Business Problems with the Microsoft Bot
Framework” (msdn.com/magazine/mt788623)
• “Use Bot Framework for Anytime, Anywhere Access to
Application Data” (msdn.com/magazine/mt790202)
• “Making Bots More Intelligent” (msdn.com/magazine/mt795186) Alternatively, the quick starts on dev.botframework.com will have you
up and running in no time.
Here, we’ll use the simple starter solution for Node.js. We use
the dialog model that the Node.js framework provides to separate the conversation into separate dialogs. In the dialog code shown in Figure 2, the bot prompts the user for a URL to a picture in the first function. Control is then passed back to the user. When the user sends some text, the dialog flow passes the user input to the second function. The bot then forwards the input for evaluation in moderate.js. In our first attempt, we call the simple Moderator API (as opposed to the more sophisticated Review and Job APIs).
To call the Content Moderator API, you need credentials, which you can get from either the Content Moderator Web site or from Azure. Here, we’ll take the latter approach. In the Azure Portal (portal.azure.com), create a new Cognitive Services account by clicking on the green plus sign and specifying Cognitive Services. After you click Create, specify Content Moderator as the API type (see Figure 3). Use the F0 tier because it’s free and allows for one call per second, which should be enough to play around with for now. Once the account is created, you’ll find the Account Name and Key under Keys in Resource Management. Note that you’ll use one of the Keys and the Resource ID string (from Properties)
bot.dialog('/moderateImage', [ function (session, args) {
builder.Prompts.text(session, 'Give me a picture URL to moderate, please.'); },
function (session, results){
var input = session.message.text;
var cm = require('./moderate.js');
cm( 'ImageUrl', input, function(err, body) {
if (err) {
session.send('Oops. Something went wrong.'); return;
}
var output = JSON.stringify(body); session.endDialog(output);
}); }
]);
msdnmagazine.com
May 2017 21


































































































   23   24   25   26   27