ユーザー生成コンテンツ (UGC) プラットフォームのインタラクティブ性と予測不可能性が、プラットフォームが非常に人気がある理由の大きな部分を占めています。ただし、予測不可能であるということは、コミュニティがコンテンツを熱心に監視して、コンテンツがコミュニティ ガイドラインや利用規定に準拠し、すべてのユーザーにとって適切で安全で歓迎的なものであることを確認する必要があることを意味します。これにより、ユーザーがコミュニティ ガイドラインに違反の可能性を報告し、モデレーターまたは管理者が必要に応じて措置を講じるというモデレーション システムが導入されることがよくあります。多くの場合、これは手動のプロセスであり、多くの点が望まれます。 ライブ ストリーミング 近年、 (AI) および機械学習 (ML) ツールが改良されており、開発者はこれらのツールを使用してコミュニティのモデレートを支援できます。この投稿では、Amazon Interactive Video Service (Amazon IVS) と Amazon Rekognition を使用してこれを行う 1 つの方法を見ていきます。 人工知能 ソリューションの概要 を使用してアプリケーション内のすべてのライブ ストリームのすべてのフレームを分析することは、非常にコストがかかり、困難な作業になります。代わりに、開発者はアプリケーション内のライブ ストリームのサンプルを指定された頻度で分析し、人間のモデレーターによるさらなるレビューが必要なコンテンツがある場合に警告を発してモデレーターを支援できます。これは 100% 完璧なソリューションではありませんが、コンテンツのモデレーションを自動化し、モデレーターの仕事を容易にする 1 つの方法です。 AI/ML この解決策には次の手順が含まれます。 構成、設定 Amazon IVS チャネルで指定した頻度でサムネイル画像を保存します Amazon Simple Storage Service (Amazon S3) へのライブストリームの自動録画 Amazon S3 バケットに新しいオブジェクトが作成されたときに起動する Amazon EventBridge ルールを作成する EventBridge ルールによってトリガーされ、Amazon Rekognition を使用して人間のモデレーターによる管理が必要なヌード、暴力、ギャンブルなどのコンテンツを検出する AWS Lambda 関数を作成します。 AWS Lambda 関数を作成し、Amazon API Gateway 経由で公開して、必要に応じてライブストリームを停止する手段を提供します。 カスタム イベントを 分析結果を含む Amazon IVS チャット ルーム Amazon EventBridge ルールと AWS Lambda 関数の作成 ルールと関数の作成を簡単にするために、AWS サーバーレス アプリケーション モデル (SAM) を使用します。これは、必要なアクセス許可、Amazon EventBridge ルール、AWS Lambda レイヤー (AWS SDK 依存関係用)、および関数定義を記述した ファイル全体です。以下で詳しく説明します。 template.yaml AWSTemplateFormatVersion: '2010-09-09' Transform: 'AWS::Serverless-2016-10-31' Description: Amazon IVS Moderation Functions Globals: Function: Runtime: nodejs18.x Timeout: 30 MemorySize: 128 Api: EndpointConfiguration: Type: REGIONAL Cors: AllowMethods: "'GET, POST, OPTIONS'" AllowHeaders: "'Content-Type'" AllowOrigin: "'*'" MaxAge: "'600'" Resources: IvsChatLambdaRefLayer: Type: AWS::Serverless::LayerVersion Properties: LayerName: sam-app-dependencies Description: Dependencies for sam app ContentUri: dependencies/ CompatibleRuntimes: - nodejs18.x LicenseInfo: "MIT" RetentionPolicy: Retain IVSAccessPolicy: Type: AWS::IAM::Policy Properties: PolicyName: IVSModerationAccessPolicy PolicyDocument: Version: "2012-10-17" Statement: - Effect: Allow Action: - 's3:GetObject' - 's3:GetObjectAcl' - 'ivschat:SendEvent' - 'ivs:StopStream' - 'rekognition:DetectModerationLabels' Resource: '*' Roles: - Ref: ModerateImageRole - Ref: StopStreamRole ApiAccessPolicy: Type: AWS::IAM::Policy Properties: PolicyName: ApiAccessPolicy PolicyDocument: Version: "2012-10-17" Statement: - Effect: Allow Action: - 'sts:AssumeRole' Resource: '*' Roles: - Ref: ModerateImageRole - Ref: StopStreamRole EventRule: Type: AWS::Events::Rule Properties: Description: EventRule State: ENABLED EventPattern: source: - aws.s3 detail-type: - "Object Created" detail: bucket: name: - ivs-demo-channel-stream-archive object: key: - suffix: .jpg Targets: - Arn: !GetAtt ModerateImage.Arn Id: MyLambdaFunctionTarget PermissionForEventsToInvokeLambda: Type: AWS::Lambda::Permission Properties: FunctionName: !Ref ModerateImage Action: lambda:InvokeFunction Principal: events.amazonaws.com SourceArn: !GetAtt EventRule.Arn ModerateImage: Type: 'AWS::Serverless::Function' Properties: Environment: Variables: DEMO_CHAT_ARN: 'arn:aws:ivschat:us-east-1:[redacted]:room/[redacted]' DEMO_CHANNEL_ARN: 'arn:aws:ivs:us-east-1:[redacted]:channel/[redacted]' Handler: index.moderateImage Layers: - !Ref IvsChatLambdaRefLayer CodeUri: lambda/ StopStream: Type: 'AWS::Serverless::Function' Properties: Environment: Variables: DEMO_CHAT_ARN: 'arn:aws:ivschat:us-east-1:[redacted]:room/[redacted]' DEMO_CHANNEL_ARN: 'arn:aws:ivs:us-east-1:[redacted]:channel/[redacted]' Handler: index.stopStream Layers: - !Ref IvsChatLambdaRefLayer CodeUri: lambda/ Events: Api1: Type: Api Properties: Path: /stop-stream Method: POST Outputs: ApiURL: Description: "API endpoint URL for Prod environment" Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/" このファイルでは多くのことが行われているので、少し詳しく見てみましょう。まず、関数に AWS SDK for JavaScript (v3) を含めることを可能にするレイヤーを作成します。 IvsChatLambdaRefLayer: Type: AWS::Serverless::LayerVersion Properties: LayerName: sam-app-dependencies Description: Dependencies for sam app ContentUri: dependencies/ CompatibleRuntimes: - nodejs18.x LicenseInfo: "MIT" RetentionPolicy: Retain ディレクトリには、関数に必要なモジュールを含む ファイルがあります。 dependencies/nodejs package.json { "dependencies": { "@aws-sdk/client-ivs": "^3.289.0", "@aws-sdk/client-ivschat": "^3.289.0", "@aws-sdk/client-rekognition": "^3.289.0" } } キー と で識別される次のセクションでは、サーバーレス アプリケーションが必要な API ( 、 、 、 、および ) にアクセスし、stop stream メソッドを公開できるようになります。以下では Amazon API Gateway 経由で作成します。 IVSAccessPolicy APIAccessPolicy s3:GetObject s3:GetObjectAcl ivschat:SendEvent ivs:StopStream rekognition:DetectModerationLabels 次に、Amazon EventBridge ルールを作成します。 の下の プロパティは、記録設定で設定した Amazon S3 バケットの名前と一致する必要があります。 Amazon S3 に記録すると、プレイリストや HLS メディアなどのさまざまなファイルが作成されるため、 の下の ようにこのルールをフィルターできます。 bucket name object key suffix: jpg EventRule: Type: AWS::Events::Rule Properties: Description: EventRule State: ENABLED EventPattern: source: - aws.s3 detail-type: - "Object Created" detail: bucket: name: - ivs-demo-channel-stream-archive object: key: - suffix: .jpg Targets: - Arn: !GetAtt ModerateImage.Arn Id: MyLambdaFunctionTarget 次に、AWS Lambda 関数を呼び出すために必要なアクセス許可をルールに与えます。 PermissionForEventsToInvokeLambda: Type: AWS::Lambda::Permission Properties: FunctionName: !Ref ModerateImage Action: lambda:InvokeFunction Principal: events.amazonaws.com SourceArn: !GetAtt EventRule.Arn これで、Amazon EventBridge ルールによって呼び出される関数を定義できます。 ModerateImage: Type: 'AWS::Serverless::Function' Properties: Environment: Variables: DEMO_CHAT_ARN: 'arn:aws:ivschat:us-east-1:[redacted]:room/[redacted]' DEMO_CHANNEL_ARN: 'arn:aws:ivs:us-east-1:[redacted]:channel/[redacted]' Handler: index.moderateImage Layers: - !Ref IvsChatLambdaRefLayer CodeUri: lambda/ と 環境変数として宣言していますが、この機能は複数の Amazon IVS チャネルで使用される可能性が高いため、アプリケーションは関数に渡されたイベントから ARN 値を導出する可能性があります。 注: DEMO_CHAT_ARN DEMO_CHANNEL_ARN 最後に、必要に応じてストリームを停止するために使用される関数を定義できます。 StopStream: Type: 'AWS::Serverless::Function' Properties: Environment: Variables: DEMO_CHAT_ARN: 'arn:aws:ivschat:us-east-1:[redacted]:room/[redacted]' DEMO_CHANNEL_ARN: 'arn:aws:ivs:us-east-1:[redacted]:channel/[redacted]' Handler: index.stopStream Layers: - !Ref IvsChatLambdaRefLayer CodeUri: lambda/ Events: Api1: Type: Api Properties: Path: /stop-stream Method: POST AWS Lambda 関数の作成 AWS SAM を使用したインフラストラクチャについて説明したので、説明した関数を作成しましょう。 では、SDK クラス 、渡した環境変数から 値を取得し、関数に必要なクライアントのインスタンスを作成します。 index.mjs import Arn import { IvsClient, StopStreamCommand } from "@aws-sdk/client-ivs"; import { IvschatClient, SendEventCommand } from "@aws-sdk/client-ivschat"; import { RekognitionClient, DetectModerationLabelsCommand } from "@aws-sdk/client-rekognition"; const chatArn = process.env.DEMO_CHAT_ARN; const channelArn = process.env.DEMO_CHANNEL_ARN; const ivsClient = new IvsClient(); const ivsChatClient = new IvschatClient(); const rekognitionClient = new RekognitionClient(); 関数は、Amazon EventBridge イベントを受信し、イベントから と を抽出し、 経由で を送信して、カテゴリに基づいて画像内の不適切または不快なコンテンツを検出します。 。 moderateImage bucket key rekognitionClient DetectModerationLabelsCommand ここにリストされています export const moderateImage = async (event) => { console.log('moderateImage:', JSON.stringify(event, null, 2)); const bucket = event.detail.bucket.name; const key = event.detail.object.key; const detectLabelsCommandInput = { Image: { S3Object: { Bucket: bucket, Name: key, } }, }; const detectLabelsRequest = new DetectModerationLabelsCommand(detectLabelsCommandInput); const detectLabelsResponse = await rekognitionClient.send(detectLabelsRequest); if (detectLabelsResponse.ModerationLabels) { sendEvent('STREAM_MODERATION', detectLabelsResponse.ModerationLabels); } }; 必要に応じて、 関数は を呼び出し、特定の Amazon IVS チャット ルームに接続されているフロントエンドのクライアントにカスタム イベントを発行します。 moderateImage sendEvent const sendEvent = async (eventName, eventDetails) => { const sendEventInput = { roomIdentifier: chatArn, attributes: { streamModerationEvent: JSON.stringify(eventDetails), }, eventName, }; const sendEventRequest = new SendEventCommand(sendEventInput); await ivsChatClient.send(sendEventRequest); }; フロントエンドはこのイベントの処理方法を決定でき、このイベントを公開するロジックはビジネス ニーズに応じて異なります。 CloudWatch でカスタム アラームをトリガーしたり、メールを送信したり、Amazon SNS 経由で通知を公開したりすることをお勧めしますか?アプリケーションごとにニーズは異なりますが、この時点でモデレーション データを利用して必要な処理を行うことができます。 メソッドは、 を使用して を送信します。繰り返しますが、これを実装するかどうかはあなた次第です。 Amazon Rekognition の結果が特定のカテゴリに一致するか、信頼レベルを超えている場合は、このコマンドを完全に自動化できる可能性もあります。 stopStream ivsClient StopStreamCommand export const stopStream = async (event) => { console.log('stopStream:', JSON.stringify(event, null, 2)); try { const stopStreamRequest = new StopStreamCommand({ channelArn }); const stopStreamResponse = await ivsClient.send(stopStreamRequest); responseObject.body = JSON.stringify(stopStreamResponse); } catch (err) { responseObject.statusCode = err?.name === 'ChannelNotBroadcasting' ? 404 : 500; responseObject.body = JSON.stringify(err); } return responseObject; }; デモ 私のデモでは、カスタム イベントをリッスンし、検出された項目と信頼レベルを示すモデレーター ビューに結果を表示することにしました。また、公開された Amazon API Gateway 経由で メソッドを呼び出す「ストリームの停止」ボタンをモデレータに提示します。 stopStream まとめ この投稿では、Amazon Rekognition を使用して、人間のモデレーターが Amazon IVS を使用して構築したアプリケーションのコンテンツを管理するのを支援する方法を学びました。 Amazon IVS がより安全な UGC コミュニティの作成にどのように役立つかについて詳しく知りたい場合は、次のブログ投稿をご覧ください。 AWS Lambda 関数を使用した Amazon IVS チャット メッセージのモデレート Amazon IVS チャット メッセージの手動モデレート