Share
Embed
使ってみよう Azure AI Document Intelligence
2024-04-20
Global Azure 2024 in Fukuoka
@kosmosebi
kosmosebi
April 20, 2024
Annual Pro sale · Save $30
Have presentations of your own?
Share with private links, password protection, and more control over your work.
Transcript
20 slides
-
使ってみよう Azure AI Document Intelligence 2024-04-20 Global Azure 2024 in
Fukuoka @kosmosebi -
Self Introduction { "name": "Keiji KAMEBUCHI", "corporation": "pnop Inc.", "web":
"https://azure.moe/", "web (a.k.a.)": "ブチザッキ", "X": "@kosmosebi", "awards": ["Microsoft MVP for Microsoft Azure", "Microsoft Regional Director"], "location": "Osaka, Japan", "YouTube": "https://www.youtube.com/c/kosmosebi" } Copyright© 2024, @kosmosebi All Rights Reserved. 2 Senior Fellow @kosmosebi -
Agenda 前書き Azure AI Document Intelligence まとめ Copyright© 2024, @kosmosebi
All Rights Reserved. 3 このスライドは2024年4月20日時点のうんたらかんたら -
前書き RAG (Retrieval-Augmented Generation) 流行ってますね Azure OpenAI Service で RAG
とかとてもよく聞く話 よっしゃイッチョやったるで Azure OpenAI Service と Azure AI Searchでベクター検索! なんだか利用者の反応が微妙 欲しい答えにならない(ほしい答えってそもそも何) 嘘つき!(嘘て( 終わらない改善のはじまり Copyright© 2024, @kosmosebi All Rights Reserved. 4 -
RAGで思うこと(個人的な感想) 目的やUI/UXによるけど ほぼほぼデータソースと検索の話だな 検索インデックス • 欲しい情報がそもそもない • 欲しい情報が検索できるところにない • 欲しい情報がインデックスに向いていない
検索精度が悪い、重い • ベクター埋め込み、チャンク、ハイブリッド検索、量子化、etc, etc… LLM関連 意外とLLMなどの部分は少ないのでは?(プロンプトを蔑ろにしてい いわけではないが) ※ベクター埋め込みは除く Copyright© 2024, @kosmosebi All Rights Reserved. 5 今回はこのあたりの話 -
データが無いとどうにもならない 裏付けされる情報が適切に無いとLLMが生成するのでそりゃね 欲しい情報をデータ化してまず扱えるようにしよう ______上や_______に既にあったりするのだが? • → Microsoft Graph APIで検索すればいいんじゃないの( •
→ Microsoft Copilotでいいんじゃないの( • 絞り込みしにくい、精度がイマイチ、遅い、業務にそぐわない、みたいなのを 改善するために作りこんだりベクター検索したい要求はわかる Office形式やPDFでは存在するのだが? • よし、取り込もう • しかし構造化されてない電子データはそもそも辛みが… Copyright© 2024, @kosmosebi All Rights Reserved. 6 -
そこで Azure AI Document Intelligence AIを使ったドキュメントからデータを抽出するためのサービス Dockerコンテナーとしてエッジ上などで動作も可 自分でモデルを作ることもできる ドキュメント分析モデル 印刷テキストや手書きテキストの抽出
汎用ドキュメント用 事前構築済みモデル Microsoftがトレーニングした特定文書向けのモデル • 請求書や領収書、パスポートや納税フォームなど(主にUS用が多い) カスタムモデル 自身でラベル付きデータセットを使ってモデルをトレーニングする • 静的レイアウトや混在型ドキュメントからのデータ抽出モデル、カスタムの分類モデル アドオン機能 高解像度、フォント、数式、バーコード、言語識別、KVペア、クエリフィールドなど Copyright© 2024, @kosmosebi All Rights Reserved. 7 -
使い方 Azure AI Document Intelligence Studio https://documentintelligence.ai.azure.com/studio ブラウザ上で対話的に実行 動作確認やちょっとした評価に REST
API アプリ内からの利用 Azure上でホストされるエンドポイント Dockerコンテナーとして自分でホストを管理するエンドポイント • 利用状況をやり取りするためにAzureと通信する必要がある • コミットメントプランで切断された環境で実行することも一応可能 GA: 3.1 (2023-07-31) Preview: 4.0 (2024-02-29-preview) Copyright© 2024, @kosmosebi All Rights Reserved. 8 -
Copyright© 2024, @kosmosebi All Rights Reserved. 11 var client =
new DocumentIntelligenceClient(new Uri(endpoint), new AzureKeyCredential(apiKey), new DocumentIntelligenceClientOptions( DocumentIntelligenceClientOptions.ServiceVersion.V2024_02_29_Preview) ); var modelId = "prebuilt-layout"; var ops = await client.AnalyzeDocumentAsync( WaitUntil.Started, modelId, analyzeRequest: new AnalyzeDocumentContent() { UrlSource = new Uri(documentUri) }, features: [ DocumentAnalysisFeature.KeyValuePairs, DocumentAnalysisFeature.OcrHighResolution, ], outputContentFormat: ContentFormat.Markdown, cancellationToken: default ); var res = await ops.WaitForCompletionAsync(); var result = res.Value; -
Tips ドキュメントのURL Document Intelligenceから参照できればOK • Azure StorageのBlobなどの場合、SAS付きでもOK • Document IntelligenceのManaged
Identitiesを有効化してAzure Storageに 権限付与でもOK C#の場合 Preview版の Azure.AI.DocumentIntelligence (1.0.0-beta.2) を使う Copyright© 2024, @kosmosebi All Rights Reserved. 12 -
連携してみよう 抽出したオブジェクトは全部位置がわかる(Boundingとして ポリゴンが含まれる) PDFを画像に変換 ⇒ 1ページの画像内からポリゴンの座標を抽出 ⇒ 画像をOCRするのではなく、GPT-4VなどのLLMを使って内容のテ キストを生成させてチャンクする、などが可能 https://github.com/microsoft/Form-Recognizer-Toolkit/blob/main/SampleCode/Python/sample_figure_understanding.ipynb
Copyright© 2024, @kosmosebi All Rights Reserved. 13 -
図の例 Figure body bounding box in (x0, y0, x1, y1):
(2.8821, 1.3358, 7.2984, 5.2159) Original figure content in markdown: ups (NSG) は、イントラネット トラフィッ クのセグ メント化だけで なく、インターネットとの間で送受信されるトラフ ィックの制御にも使用 できます。 Network Security Groups は、VM またはサブネットのいずれか、また場合 によってはその 両方に対して適用できます。NSG には、以下のような重要な 特徴があります。 • 図5 に示すように、NSG のルールには 5 つのタプル(送信元 IP、送 信元のポート番号、 送信先 IP、送信先 のポート番号、プロトコル)が 含まれます。 • NSG のルールはステートフルです。つまり、特定のポートでのトラ フィックを許可す る受信ルールが Copyright© 2024, @kosmosebi All Rights Reserved. 15 -
図の例 Description of figure 8: The image depicts a layered
cybersecurity architecture designed to protect customer services and Azure infrastructure with multiple defense layers. At the top, there's a symbol representing global network or internet, connecting to the first layer labeled "Network Access." Below this are two more rows; the second row is labeled "IDS/IPS," suggesting intrusion detection and prevention systems. The third row is the "Cloud Access Layer," described by two sub-layers: "Host Firewall" on the left and "Distributed Virtual Firewall" on the right. Underneath this row, there is a dotted border enclosing representations of two firewall-protected areas. Each area has a brick firewall labeled with a fiery icon, with one marked "C" indicating "Guest Firewall" and housing a symbol of a VM (virtual machine). The other, marked with number "2," suggests a "Distributed Virtual Firewall" protecting another virtual machine labeled "Customer Cloud Service VMs." On the left is a callout with the letter "B," colored in red, leading to a box that reads "DDoS Defense," which is probably indicating a mechanism to protect against Distributed Denial-of-Service attacks. Above the dotted box, there are indicators connecting the Host Firewall and Distributed Virtual Firewall with the respective elements inside the dotted box: "1" leading to the Guest Firewall, and "2" to the Distributed Virtual Firewall around the Customer Cloud Service VMs. Copyright© 2024, @kosmosebi All Rights Reserved. 16 -
RAGに話を戻して… 単にテキスト抽出するだけならライブラリとか使えば簡単ではあるが… Azure AI Searchの組み込みインデクサーなど凄く便利 PDFなど辛みが多くて結局満足できない事になりがち 精度をあげるために まとまった情報に固めて、ノイズは除外 • Header,
Footerをのぞいたり、Sectionでまとめたり • 構造を無視したチャンクより、セマンティック チャンキング 表は表として、図は図として • Markdownで表をそのまま維持(セル結合…) • OCRされた図のテキストを使うもよし、画像として抽出後GPT-4VのようなLLMで説明させたテキストを使う もよし 得られた情報を基にインデックスを登録していけば…? • トピック外のノイズを減らせる • トピック内の必要情報を増やせる Copyright© 2024, @kosmosebi All Rights Reserved. 17 -
辛みを解消 Copyright© 2024, @kosmosebi All Rights Reserved. 18 意味のある単位で取りたいけど… ・改ページが邪魔
・ヘッダー、フッターが邪魔 ⇒ それぞれを認識してコンテンツ だけ抽出できる 図も図として認識できる 図中のテキストが抜き出せる -
まとめ 結局やることは、昔からあまり変わってない感… けど、精度やら連携やら取り回しは格別に良くなってる 適切なサービスを適切な箇所で使いましょう Azure AI servicesのような事前構築済みモデルは目的に合致すれば 強い 最新のPreview APIが機能が豊富で良い(リージョンは限定的)
あれこれカスタムするかどうかは目的や労力、見返り次第で Copyright© 2024, @kosmosebi All Rights Reserved. 19 -
Appendix Azure AI Document Intelligence https://azure.microsoft.com/ja-jp/products/ai-services/ai-document-intelligence Transparency note and use
cases for Document Intelligence https://learn.microsoft.com/ja-jp/legal/cognitive-services/document-intelligence/transparency-note Data, privacy, and security for Document Intelligence https://learn.microsoft.com/ja-jp/legal/cognitive-services/document-intelligence/data-privacy-security Azure AI Document Intelligence の新機能 https://learn.microsoft.com/ja-jp/azure/ai-services/document-intelligence/whats-new デモなど https://github.com/buchizo/Demos Copyright© 2024, @kosmosebi All Rights Reserved. 20