kaeken(嘉永島健司)のTech探究ブログ

主に情報科学/情報技術全般に関する知見をポストします。(最近は、特にData Science、機械学習、深層学習、統計学、Python、数学、ビッグデータ)

Safety best practices - OpenAI API まとめ

Safety best practices - OpenAI API

"OpenAI Platform" ドキュメントは、OpenAIのサービスを使用する際のいくつかの安全なベストプラクティスとガイドラインを概説しています:

  1. モデレーションAPIの使用: OpenAIの無料モデレーションAPIを使用して、アプリケーションの出力における安全でないコンテンツを減らすことが推奨されます。また、カスタムコンテンツフィルタリングシステムを開発することも可能です。

  2. 敵対的テスト: アプリケーションが敵対的な入力に対して頑健であることを確かめるために「レッドチーミング」を行うことが勧められます。これには、操作を試みるか「壊す」ことを目的としたユーザー行動を含む幅広い入力に対するテストが含まれます。

  3. Human in the Loop (HITL): 高リスク分野やコード生成において、出力に対する人間の監視が重要です。人間はシステムの限界を理解し、出力を検証するために必要な情報にアクセスできる必要があります。

  4. プロンプトエンジニアリング: 出力テキストのトピックとトーンを制約することで、望ましくないコンテンツの生成を減らすことができます。モデルに文脈と高品質の例を提供することで、望ましい方向に出力を導くことができます。

  5. 顧客を知る (KYC): ユーザーは通常、サービスにアクセスするために登録およびログインする必要があります。既存のアカウントへのリンクや、クレジットカードまたはIDカードの要求によりリスクが減少します。

  6. ユーザー入力の制約と出力トークンの制限: ユーザーの入力と出力トークンの数を制限することで、プロンプトインジェクションと不正使用を防ぐことができます。

  7. 入力/出力の範囲を狭める: 信頼できるソースからの入力や出力を使用することで、アプリケーション内での不正使用の可能性を減らすことができます。

  8. ユーザーに問題を報告させる: ユーザーはアプリケーションの挙動に関する不適切な機能性やその他の懸念を簡単に報告できる方法を一般的に持つべきです。この方法は人間によって監視され、適切に対応されるべきです。

  9. 制限とコミュニケーションの理解: 不正確な情報の幻覚、攻撃的な出力、偏見など、言語モデルは重大な変更がなければすべての用途に適しているわけではありません。APIの性能を幅広い潜在的な入力で評価し、APIの性能が低下する可能性のあるケースを特定します。顧客ベースと彼らが使用する入力の範囲を考慮し、適切に期待を調整することが重要です。

  10. 安全性とセキュリティ: APIやOpenAIに関連する他のもので安全性またはセキュリティの問題に気付いた場合は、OpenAIの調整済み脆弱性開示プログラムを通じて報告することが推奨されます。

  11. エンドユーザーID: APIリクエストで一意のエンドユーザーIDを送信することは、OpenAIが不正使用を監視し、検出するのに役立ちます。ユーザー識別のためにハッシュ化されたユーザー名またはメールアドレスの使用が推奨されます。

これらのガイドラインは、OpenAIのサービスを使用するアプリケーションの安全性、セキュリティ、および効果を向上させることを目的としています。

The "OpenAI Platform" document outlines several safety best practices and guidelines for using OpenAI's services:

  1. Use of Moderation API: It's recommended to use OpenAI's free Moderation API to reduce unsafe content in application outputs. Alternatively, one may develop a custom content filtration system.

  2. Adversarial Testing: It's advised to conduct "red-teaming" on applications to ensure they are robust against adversarial inputs. This includes testing across a wide range of inputs and user behaviors, including those attempting to manipulate or 'break' the application.

  3. Human in the Loop (HITL): For high-stakes domains and code generation, it is critical to have human oversight of outputs. Humans should understand the system's limitations and have access to necessary information for verifying outputs.

  4. Prompt Engineering: This involves constraining the topic and tone of output text to reduce the production of undesired content. Providing context and high-quality examples to the model can help steer outputs in desired directions.

  5. Know Your Customer (KYC): Users should typically register and log in to access services. Linking to existing accounts and requiring credit card or ID card can reduce risks.

  6. Constrain User Input and Limit Output Tokens: Limiting user input and the number of output tokens helps prevent prompt injections and misuse.

  7. Narrow Ranges of Inputs/Outputs: Using inputs or outputs from trusted sources and validated sets can reduce misuse.

  8. Allow Users to Report Issues: Users should have easy methods to report problems or concerns, which should be monitored and responded to by humans.

  9. Understand and Communicate Limitations: Acknowledge the limitations of language models, such as potential for inaccurate information, offensive outputs, or bias. Evaluate the API's performance across a range of inputs and communicate these limitations to users.

  10. Safety and Security: Users are encouraged to report any safety or security issues through OpenAI's Coordinated Vulnerability Disclosure Program.

  11. End-user IDs: Sending unique end-user IDs in API requests can help OpenAI monitor and detect abuse. It's recommended to use hashed usernames or email addresses for user identification.

These guidelines aim to enhance the safety, security, and effectiveness of applications using OpenAI's services.