Skip to content
This repository has been archived by the owner on Oct 11, 2022. It is now read-only.

Commit

Permalink
Merge pull request #4409 from withspectrum/remove-spectrum
Browse files Browse the repository at this point in the history
Remove getspectrum as a toxicity check provider
  • Loading branch information
brianlovin authored Dec 4, 2018
2 parents c3751a9 + 22d32d5 commit 54e685e
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 91 deletions.
11 changes: 3 additions & 8 deletions api/mutations/thread/publishThread.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
_adminProcessToxicThreadQueue,
_adminProcessUserSpammingThreadsQueue,
} from 'shared/bull/queues';
import getSpectrumScore from 'athena/queues/moderationEvents/spectrum';
import getPerspectiveScore from 'athena/queues/moderationEvents/perspective';
import { events } from 'shared/analytics';
import { trackQueue } from 'shared/bull/queues';
Expand Down Expand Up @@ -275,27 +274,23 @@ export default requireAuth(
const title = thread.content.title;
const text = `${title} ${body}`;

const scores = await Promise.all([
getSpectrumScore(text, dbThread.id, dbThread.creatorId).catch(err => 0),
getPerspectiveScore(text).catch(err => 0),
]).catch(err =>
const scores = await getPerspectiveScore(text).catch(err =>
console.error(
'Error getting thread moderation scores from providers',
err.message
)
);

const spectrumScore = scores && scores[0];
const perspectiveScore = scores && scores[1];

// if neither models returned results
if (!spectrumScore && !perspectiveScore) {
if (!perspectiveScore) {
debug('Toxicity checks from providers say not toxic');
return false;
}

// if both services agree that the thread is >= 98% toxic
if ((spectrumScore + perspectiveScore) / 2 >= 0.9) {
if (perspectiveScore >= 0.9) {
debug('Thread is toxic according to both providers');
return true;
}
Expand Down
15 changes: 3 additions & 12 deletions athena/queues/moderationEvents/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { getThreadById } from '../../models/thread';
import { getCommunityById } from '../../models/community';
import { getChannelById } from '../../models/channel';
import { toState, toPlainText } from 'shared/draft-utils';
import getSpectrumScore from './spectrum';
import getPerspectiveScore from './perspective';
import { _adminSendToxicContentEmailQueue } from 'shared/bull/queues';
import type { Job, AdminToxicMessageJobData } from 'shared/bull/types';
Expand All @@ -21,11 +20,8 @@ export default async (job: Job<AdminToxicMessageJobData>) => {
? toPlainText(toState(JSON.parse(message.content.body)))
: message.content.body;

const scores = await Promise.all([
getSpectrumScore(text, message.id, message.senderId),
getPerspectiveScore(text),
]).catch(err =>
console.error('Error getting message moderation scores from providers', {
const perspectiveScore = await getPerspectiveScore(text).catch(err =>
console.error('Error getting message moderation score from providers', {
error: err.message,
data: {
text,
Expand All @@ -34,11 +30,7 @@ export default async (job: Job<AdminToxicMessageJobData>) => {
})
);

const spectrumScore = scores && scores[0];
const perspectiveScore = scores && scores[1];

// if neither models returned results
if (!spectrumScore && !perspectiveScore) return;
if (!perspectiveScore) return;

const [user, thread] = await Promise.all([
getUserById(message.senderId),
Expand All @@ -58,7 +50,6 @@ export default async (job: Job<AdminToxicMessageJobData>) => {
community,
channel,
toxicityConfidence: {
spectrumScore,
perspectiveScore,
},
});
Expand Down
2 changes: 1 addition & 1 deletion athena/queues/moderationEvents/perspective.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default async (text: string) => {
});

// if something failed?
if (!request || !request.data) return;
if (!request || !request.data) return null;

// get the scores from the request
const { attributeScores } = request.data;
Expand Down
42 changes: 0 additions & 42 deletions athena/queues/moderationEvents/spectrum.js

This file was deleted.

12 changes: 2 additions & 10 deletions athena/queues/moderationEvents/thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { getUserById } from 'shared/db/queries/user';
import { getCommunityById } from '../../models/community';
import { getChannelById } from '../../models/channel';
import { toState, toPlainText } from 'shared/draft-utils';
import getSpectrumScore from './spectrum';
import getPerspectiveScore from './perspective';
import { _adminSendToxicContentEmailQueue } from 'shared/bull/queues';
import type { Job, AdminToxicThreadJobData } from 'shared/bull/types';
Expand All @@ -26,10 +25,7 @@ export default async (job: Job<AdminToxicThreadJobData>) => {
const title = thread.content.title;
const text = `${title} ${body}`;

const scores = await Promise.all([
getSpectrumScore(text, thread.id, thread.creatorId),
getPerspectiveScore(text),
]).catch(err =>
const perspectiveScore = await getPerspectiveScore(text).catch(err =>
console.error('Error getting thread moderation scores from providers', {
error: err.message,
data: {
Expand All @@ -39,11 +35,8 @@ export default async (job: Job<AdminToxicThreadJobData>) => {
})
);

const spectrumScore = scores && scores[0];
const perspectiveScore = scores && scores[1];

// if neither models returned results
if (!spectrumScore && !perspectiveScore) return;
if (!perspectiveScore) return;

const [user, community, channel] = await Promise.all([
getUserById(thread.creatorId),
Expand All @@ -59,7 +52,6 @@ export default async (job: Job<AdminToxicThreadJobData>) => {
community,
channel,
toxicityConfidence: {
spectrumScore,
perspectiveScore,
},
});
Expand Down
4 changes: 0 additions & 4 deletions email-templates/adminToxicContent.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@

<p><strong>Info:</strong></p>
<ul>
{{#data.toxicityConfidence.spectrumPercent}}
<li><strong>Spectrum:</strong> {{.}}% confident</li>
{{/data.toxicityConfidence.spectrumPercent}}

{{#data.toxicityConfidence.perspectivePercent}}
<li><strong>Perspective:</strong> {{.}}% confident</li>
{{/data.toxicityConfidence.perspectivePercent}}
Expand Down
17 changes: 4 additions & 13 deletions hermes/queues/send-admin-toxic-content-email.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,14 @@ export default job => {
thread,
community,
channel,
toxicityConfidence: { spectrumScore, perspectiveScore },
toxicityConfidence: { perspectiveScore },
} = job.data;

const toPercent = (num: number) => Math.round(num * 100);
const spectrumPercent = spectrumScore ? toPercent(spectrumScore) : null;
const perspectivePercent = perspectiveScore
? toPercent(perspectiveScore)
: null;
let avgPercent;
if (spectrumPercent && perspectivePercent) {
avgPercent = (spectrumPercent + perspectivePercent) / 2;
} else {
avgPercent = spectrumPercent || perspectivePercent || 0;
}

const subject = `Toxic alert (${avgPercent.toString()}%): ${text}`;
const perspectivePercent = perspectiveScore.toPercent(perspectiveScore);

const subject = `Toxic alert (${perspectivePercent.toString()}%): ${text}`;

try {
return sendEmail({
Expand All @@ -50,7 +42,6 @@ export default job => {
community,
channel,
toxicityConfidence: {
spectrumPercent,
perspectivePercent,
},
},
Expand Down
2 changes: 1 addition & 1 deletion now.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"API_TOKEN_SECRET": "@api-token-secret",
"SENTRY_DSN_CLIENT": "@sentry-dsn-client",
"SENTRY_DSN_SERVER": "@sentry-dsn-server",
"SPECTRUM_MODERATION_API_KEY": "@spectrum-moderation-api-key",

"AMPLITUDE_API_KEY": "@amplitude-api-key",
"AMPLITUDE_API_KEY_DEVELOPMENT": "@amplitude-api-key-development",
"ENCRYPTION_KEY": "@encryption-key",
Expand Down

0 comments on commit 54e685e

Please sign in to comment.