Skip to main content

特許PDFからマルチモーダル生成AIを使用して構造化JSONを抽出するライブラリ

Project description

特許PDF構造化ライブラリ

特許PDFからマルチモーダル生成AIを使用して構造化されたJSONを抽出するPythonライブラリです。

機能

  • 特許PDFをマルチモーダル生成AIに直接送信して構造化情報を抽出
  • 複数の生成AIプロバイダーをサポート:
    • Google Gemini
    • OpenAI GPT Vision
    • Anthropic Claude
  • カスタマイズ可能なJSONスキーマ
  • 生成AI設定の調整(temperature、max_tokens)

インストール

pip install -r requirements.txt

使用方法

ライブラリとして使用

from patent_extractor import PatentExtractor

# 基本的な使用法
extractor = PatentExtractor(
    model_name="gemini-1.5-pro",  # デフォルトモデル
    api_key="YOUR_API_KEY"
)
result = extractor.process_patent_pdf("path/to/patent.pdf")

# 結果を保存
import json
with open("output.json", "w", encoding="utf-8") as f:
    json.dump(result, f, indent=2, ensure_ascii=False)

カスタムJSONスキーマの指定

import json
from patent_extractor import PatentExtractor

# JSONスキーマを読み込み
with open("schema.json", "r", encoding="utf-8") as f:
    schema = json.load(f)

# スキーマを指定してエクストラクタを初期化
extractor = PatentExtractor(
    model_name="gpt-4o",
    api_key="YOUR_API_KEY",
    json_schema=schema
)

# PDFを処理
result = extractor.process_patent_pdf("patent.pdf")

カスタムプロンプトと生成設定の指定

from patent_extractor import PatentExtractor

# カスタムプロンプトと生成設定を指定
extractor = PatentExtractor(
    model_name="claude-3-opus-20240229",
    api_key="YOUR_API_KEY",
    user_prompt="特許文書から次のセクションを重点的に抽出してください:請求項、発明の詳細な説明、図面の簡単な説明",
    temperature=0.2,    # より創造的な出力(デフォルトは0.1)
    max_tokens=8192     # より長い出力を許可(デフォルトは4096)
)

# PDFを処理
result = extractor.process_patent_pdf("patent.pdf")

コマンドラインからの使用

# 基本的な使用法
python patent_extractor.py path/to/patent.pdf --api-key YOUR_API_KEY

# モデルと生成パラメータを指定
python patent_extractor.py path/to/patent.pdf --model gpt-4o --api-key YOUR_API_KEY --temperature 0.3 --max-tokens 8192

# スキーマとカスタムプロンプトを指定して結果を保存
python patent_extractor.py path/to/patent.pdf --model claude-3-opus-20240229 --api-key YOUR_API_KEY --schema schema.json --prompt "カスタム指示" --output result.json

環境変数の使用

APIキーは環境変数からも取得できます:

import os
from patent_extractor import PatentExtractor

# 環境変数を設定(必要に応じて)
os.environ["GOOGLE_API_KEY"] = "your-api-key"
# または
os.environ["OPENAI_API_KEY"] = "your-api-key"
# または
os.environ["ANTHROPIC_API_KEY"] = "your-api-key"

# APIキーを明示的に指定せずに初期化
extractor = PatentExtractor(model_name="gemini-1.5-pro")  # 環境変数からAPIキーを取得

サポートされるモデル

Google Gemini

  • gemini-1.5-pro
  • gemini-1.5-flash

OpenAI

  • gpt-4o
  • gpt-4-vision-preview

Anthropic Claude

  • claude-3-opus-20240229
  • claude-3-sonnet-20240229

生成パラメータの調整

temperature

  • 範囲: 0.0〜1.0
  • 低い値(0.0〜0.3): より確定的で一貫性のある出力
  • 高い値(0.7〜1.0): より多様でクリエイティブな出力
  • デフォルト: 0.1(安定した構造化データに適切)

max_tokens

  • 生成AIが出力できる最大トークン数
  • より大きな値: より詳細で長い出力が可能
  • より小さな値: 簡潔な出力を強制
  • デフォルト: 4096

必要条件

  • Python 3.8+
  • google-generativeai / openai / anthropic パッケージ(APIに応じて)

ライセンス

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

patent_extractor-0.2.0.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

patent_extractor-0.2.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file patent_extractor-0.2.0.tar.gz.

File metadata

  • Download URL: patent_extractor-0.2.0.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for patent_extractor-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1ed0311a289bcd953d7ab4f360ef45c2bb8a397e2194ebcfeb21875d77024768
MD5 11fdd6c6d8bf5bf740127ae036e0ea4a
BLAKE2b-256 7d7258ee3855596e533081d79d68c02f167fb6d0ce39f1682062ea2ac51cfc4a

See more details on using hashes here.

File details

Details for the file patent_extractor-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for patent_extractor-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 880d5ad53a67aad6beb3ec7e19de61ff67373be0a56fc69286e7987f4c3e2272
MD5 4c33c765ccfc04f7068a016c19746fc1
BLAKE2b-256 45539973820d64429d05d2a419694a56dcd7bf1fa912eefaae85ae1f7e7df9b2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page