### Start vLLM Server with Qwen3-4B-AWQ Example Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/extractor.en.md Example command to start the vLLM server using the Qwen3-4B-AWQ model, configured for document extraction. ```bash vllm serve Qwen/Qwen3-4B-AWQ \ --host 0.0.0.0 \ --port 8000 \ --quantization awq \ --dtype float16 \ --max-model-len 8192 \ --gpu-memory-utilization 0.5 ``` -------------------------------- ### Start vLLM Server with Qwen3-4B-AWQ Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/extractor.ja.md Example command to start a vLLM server using the Qwen/Qwen3-4B-AWQ model, suitable for LLM-based extraction. ```bash vllm serve Qwen/Qwen3-4B-AWQ \ --host 0.0.0.0 \ --port 8000 \ --quantization awq \ --dtype float16 \ --max-model-len 8192 \ --gpu-memory-utilization 0.5 ``` -------------------------------- ### Install Yomitoku Basic Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/extractor.en.md Install the Yomitoku library using pip. ```bash pip install yomitoku ``` -------------------------------- ### Install YomiToku with uv Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/installation.ja.md Install YomiToku using the uv package manager after cloning the repository. This method is recommended by the project. ```bash uv sync ``` -------------------------------- ### Install YomiToku with uv (GPU) Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/installation.ja.md Install YomiToku using uv with extra GPU support. This command ensures that GPU-compatible dependencies are installed. ```bash uv sync --extra gpu ``` -------------------------------- ### Start vLLM Server Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/extractor.ja.md Launch a vLLM server with specified model and configurations. This command starts a server for LLM-based extraction. ```bash vllm serve \ --host 0.0.0.0 \ --port 8000 \ --quantization awq \ --dtype float16 \ --max-model-len 8192 \ --gpu-memory-utilization 0.5 ``` -------------------------------- ### Start vLLM Server with Model Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/extractor.en.md Start the vLLM server with specified model and configuration options. This command is used for LLM-based extraction. ```bash vllm serve \ --host 0.0.0.0 \ --port 8000 \ --quantization awq \ --dtype float16 \ --max-model-len 8192 \ --gpu-memory-utilization 0.5 ``` -------------------------------- ### Install Yomitoku with LLM Extraction Support Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/extractor.ja.md Install yomitoku with the 'extract' option to enable LLM-based extraction. This also installs openai and pyyaml. ```bash pip install "yomitoku[extract]" ``` -------------------------------- ### Install Yomitoku with LLM Extraction Support Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/extractor.en.md Install Yomitoku with the 'extract' option to include dependencies for LLM-based extraction. ```bash pip install "yomitoku[extract]" ``` -------------------------------- ### Start SSE Server for YomiToku MCP Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/mcp.ja.md Launch the SSE server using this command. The server will be accessible at http://127.0.0.1:8000/sse. ```bash uv run yomitoku_mcp -t sse ``` -------------------------------- ### Install YomiToku via Pip Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/installation.ja.md Use this command to install the YomiToku package from PyPI. Ensure you have Python 3.10+ and PyTorch installed. ```bash pip install yomitoku ``` -------------------------------- ### LLM-Based Extraction CLI Examples Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/extractor.ja.md Demonstrates typical LLM-based extraction scenarios. Examples include using a vLLM server, batch processing, specifying custom API endpoints and keys, and using the `--prompt-only` flag for debugging. ```bash # vLLMサーバーを使用した抽出 yomitoku_extract_with_llm input.jpg -s schema.yaml -m Qwen/Qwen3-4B-AWQ # ディレクトリ内の全ファイルを一括処理 yomitoku_extract_with_llm ./documents/ -s schema.yaml -m Qwen/Qwen3-4B-AWQ # APIベースURLとキーを指定 yomitoku_extract_with_llm input.jpg -s schema.yaml -m gpt-4o \ --api-base https://api.openai.com/v1 \ --api-key sk-xxxxx # プロンプトの確認(デバッグ) yomitoku_extract_with_llm input.jpg -s schema.yaml -m model_name --prompt-only ``` -------------------------------- ### Install YomiToku with MCP Support Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/mcp.ja.md Use this command to install YomiToku, ensuring the 'mcp' extra dependency is included for MCP server functionality. ```bash uv sync --extra mcp ``` -------------------------------- ### Example YAML Schema Generation Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/schema_generation_prompt.md Demonstrates the expected YAML output when using the schema generation prompt with a specific input. This example shows how fields like 'contractor_name', 'address', and a 'usage_schedule' table are translated into YAML. ```yaml fields: - name: contractor_name structure: kv description: 契約者名 type: string normalize: strip_spaces - name: address structure: kv description: 住所 type: string normalize: strip_spaces - name: phone_number structure: kv description: 電話番号 type: string normalize: phone_jp - name: postal_code structure: kv description: 郵便番号 type: string normalize: postal_code_jp - name: usage_schedule structure: table description: 利用希望日 type: string columns: - name: date description: 日付 type: date normalize: date_jp - name: check_in_time description: 入室 type: string normalize: time_hms - name: check_out_time description: 退室 type: string normalize: time_hms - name: notes structure: kv description: 備考 type: string normalize: strip_spaces ``` -------------------------------- ### Install YomiToku Extractor Module Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/README.md Install the YomiToku package with the 'extract' extra to enable the structured data extraction functionality. ```bash pip install yomitoku[extract] ``` -------------------------------- ### Install vLLM for LLM-based Extraction Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/extractor.ja.md Install the vLLM library, which is recommended for running LLM servers compatible with the OpenAI API for LLM-based extraction. ```bash pip install vllm ``` -------------------------------- ### Rule-Based Extraction CLI Examples Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/extractor.ja.md Illustrates common use cases for the rule-based extraction CLI. Examples show extraction from an image file, processing specific pages of a PDF, batch processing files in a directory, and running on a CPU. ```bash # 画像ファイルから抽出 yomitoku_extract input.jpg -s schema.yaml -o results -v # PDFの特定ページのみ処理 yomitoku_extract document.pdf -s schema.yaml --pages 1,3-5 # ディレクトリ内の全ファイルを一括処理 yomitoku_extract ./documents/ -s schema.yaml -o results # CPU環境で実行 yomitoku_extract input.jpg -s schema.yaml -d cpu ``` -------------------------------- ### Run on CPU (Rule-based) Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/extractor.en.md Example of forcing rule-based extraction to run on the CPU. Use the `--device` option and specify 'cpu'. ```bash # Run on CPU yomitoku_extract input.jpg -s schema.yaml -d cpu ``` -------------------------------- ### Configure Different Devices for OCR and Layout Analysis Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/module.ja.md Customize model execution devices using a configurations dictionary. This example sets OCR to run on CUDA and layout analysis on CPU. ```python from yomitoku import DocumentAnalyzer if __name__ == "__main__": configs = { "ocr": { "text_detector": { "device": "cuda", }, "text_recognizer": { "device": "cuda", }, }, "layout_analyzer": { "layout_parser": { "device": "cpu", }, "table_structure_recognizer": { "device": "cpu", }, }, } DocumentAnalyzer(configs=configs) ``` -------------------------------- ### Configure OCR and Layout Analysis Devices Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/module.en.md This example shows how to set up a configuration dictionary to run OCR tasks on a GPU (cuda) and layout analysis on a CPU. It demonstrates specifying devices for text detection, text recognition, layout parsing, and table structure recognition. ```python from yomitoku import DocumentAnalyzer if __name__ == "__main__": configs = { "ocr": { "text_detector": { "device": "cuda", }, "text_recognizer": { "device": "cuda", }, }, "layout_analyzer": { "layout_parser": { "device": "cpu", }, "table_structure_recognizer": { "device": "cpu", }, }, } DocumentAnalyzer(configs=configs) ``` -------------------------------- ### Simple Document Analysis Example Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/module.en.md Demonstrates basic usage of the Document Analyzer for OCR and layout analysis. Set visualize to False for production environments. ```Python from yomitoku.analyzer import DocumentAnalyzer # Initialize the analyzer analyzer = DocumentAnalyzer() # Analyze a document results = analyzer.analyze("path/to/your/document.pdf") # Export results to JSON results.to_json("output.json") ``` -------------------------------- ### Simple Layout Analyzer Example Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/module.en.md Demonstrates basic usage of the Layout Analyzer module for text, paragraph, figure/table detection, and table structure analysis. The `visualize` option can be set to `True` to also return layout analysis results as a second return value, otherwise it returns `None`. ```Python from yomitoku.layout import LayoutAnalyzer layout = LayoutAnalyzer(visualize=False, device="cuda", configs={}) l = layout.layout("image.png") print(l.to_json()) ``` -------------------------------- ### Batch Process Directory (LLM-based) Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/extractor.en.md Example of batch processing files in a directory using LLM-based extraction. The tool recursively searches for supported file types. ```bash # Batch process all files in a directory yomitoku_extract_with_llm ./documents/ -s schema.yaml -m Qwen/Qwen3-4B-AWQ ``` -------------------------------- ### Simple AI-OCR Example Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/module.en.md Demonstrates basic usage of the AI-OCR module for text detection and recognition. The `visualize` option can be set to `True` to also return OCR results as a second return value, otherwise it returns `None`. ```Python from yomitoku.ocr import AIOCR ocr = AIOCR(visualize=False, device="cuda", configs={}) o = ocr.ocr("image.png") print(o.to_json()) ``` -------------------------------- ### Batch Process Directory (Rule-based) Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/extractor.en.md Example of batch processing all supported image and PDF files within a directory using rule-based extraction. The tool recursively searches subdirectories. ```bash # Batch process all files in a directory yomitoku_extract ./documents/ -s schema.yaml -o results ``` -------------------------------- ### Extract from Image File (Rule-based) Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/extractor.en.md Example of extracting data from a single image file using rule-based extraction. Ensure the schema file and output directory are specified. ```bash # Extract from an image file yomitoku_extract input.jpg -s schema.yaml -o results -v ``` -------------------------------- ### Check Prompt (Debugging LLM-based) Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/extractor.en.md Example for debugging LLM-based extraction by printing the generated prompt and exiting without performing extraction. Use the `--prompt-only` flag. ```bash # Check the prompt (debugging) yomitoku_extract_with_llm input.jpg -s schema.yaml -m model_name --prompt-only ``` -------------------------------- ### Extract using vLLM Server (LLM-based) Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/extractor.en.md Example of performing LLM-based extraction using a specified model name, likely hosted on a vLLM server. Ensure the model name is correctly provided. ```bash # Extract using vLLM server yomitoku_extract_with_llm input.jpg -s schema.yaml -m Qwen/Qwen3-4B-AWQ ``` -------------------------------- ### Set Resource Directory for SSE Server Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/mcp.ja.md Before starting the SSE server, set the RESOURCE_DIR environment variable to the absolute path of the directory containing the OCR target images. ```bash export RESOURCE_DIR="path of dataset" ``` -------------------------------- ### Simple Table Fields Output Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/extractor.en.md Example of table fields in the simple JSON output format, presenting an array of records without detailed metadata. ```json { "usage_date": [ { "date": "20240315", "entrance_time": "14時30分", "leave_time": "16:00:00" } ] } ``` -------------------------------- ### Specify API Base URL and Key (LLM-based) Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/extractor.en.md Example of configuring LLM-based extraction to use a custom API base URL and an API key. This is useful for connecting to external LLM services. ```bash # Specify API base URL and key yomitoku_extract_with_llm input.jpg -s schema.yaml -m gpt-4o \ --api-base https://api.openai.com/v1 \ --api-key sk-xxxxx ``` -------------------------------- ### Display Yomitoku Help Documentation Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/README_EN.md View the full list of command-line arguments and options available for Yomitoku by running the --help command. ```bash yomitoku --help ``` -------------------------------- ### Display Help Options Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/cli.en.md Displays all available command-line options for YomiToku. ```bash yomitoku -h ``` -------------------------------- ### Basic CLI Execution Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/cli.en.md Specifies the input data path, enables visualization, and sets the output directory. The model weights are downloaded from Hugging Face Hub during the first execution. ```bash yomitoku ${path_data} -v -o results ``` -------------------------------- ### KV (Scalar) Field Output Example Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/extractor.en.md Example of a key-value (scalar) field in the detailed JSON output. Includes normalized value, raw text, confidence, source, cell IDs, and bounding boxes. ```json { "fields": { "phone_number": { "structure": "kv", "value": "03-1234-5678", "raw_text": "0312345678", "confidence": "high", "source": "cell_id", "cell_ids": ["c43"], "bboxes": [[450, 120, 700, 160]] } } } ``` -------------------------------- ### Table Field Output Example Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/extractor.en.md Example of a table field in the detailed JSON output. Includes records, where each record is a dictionary of column data with normalized value, raw text, cell IDs, and bounding boxes. ```json { "fields": { "usage_date": { "structure": "table", "records": [ { "date": { "value": "20240315", "cell_ids": ["c20"], "raw_text": "令和6年3月15日", "bboxes": [[100, 200, 300, 240]] }, "entrance_time": { "value": "14時30分", "cell_ids": ["c21"], "raw_text": "14:30", "bboxes": [[310, 200, 450, 240]] } } ], "source": "grid" } } } ``` -------------------------------- ### YomiToku Command Line Help Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/README.md Display the help message for the YomiToku command-line tool to view all available options and arguments. ```bash yomitoku --help ``` -------------------------------- ### Configure MCP Servers in Claude Desktop Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/mcp.ja.md Add this configuration to your Claude Desktop settings file to define the 'yomitoku' MCP server. Specify the command, arguments including the absolute path to your YomiToku clone, and environment variables like RESOURCE_DIR. ```json { "mcpServers": { "yomitoku": { "command": "uv", "args": [ "--directory", "(YomiTokuをCloneしたディレクトリの絶対パス)", "run", "yomitoku_mcp" ], "env": { "RESOURCE_DIR": "(OCR対象のファイルがあるディレクトリの絶対パス)" } } } } ``` -------------------------------- ### Simple KV (Scalar) Fields Output Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/extractor.en.md Example of key-value (scalar) fields in the simple JSON output format, which omits metadata like bounding boxes and confidence scores. ```json { "phone_number": "03-1234-5678", "company_name": "Test Corporation" } ``` -------------------------------- ### Build Docker Image Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/installation.ja.md Build the Docker image for YomiToku. This command creates a Docker image tagged as 'yomitoku'. ```bash docker build -t yomitoku . ``` -------------------------------- ### Process Specific Pages from PDF (Rule-based) Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/extractor.en.md Example of processing only specific pages from a PDF document using rule-based extraction. Use the `--pages` option to define the page range. ```bash # Process specific pages from a PDF yomitoku_extract document.pdf -s schema.yaml --pages 1,3-5 ``` -------------------------------- ### Prompt Claude Desktop for OCR and Summarization Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/mcp.ja.md Use this prompt format in Claude Desktop to instruct the integrated YomiToku MCP server to perform OCR analysis and summarization on a specified PDF file. ```txt sample.pdfをOCRで解析して要約してください。 ``` -------------------------------- ### Run Docker Container (GPU) Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/installation.ja.md Run the YomiToku Docker container with GPU support enabled. This mounts the current directory and allocates all available GPUs. ```bash docker run -it --gpus all -v $(pwd):/workspace --name yomitoku yomitoku /bin/bash ``` -------------------------------- ### Run YomiToku with Normal Model Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/README.md Execute YomiToku for document analysis using the default, high-accuracy model. Specify input data path, output format, output directory, and enable visualization and figure extraction. ```bash yomitoku ${path_data} -f md -o results -v --figure ``` -------------------------------- ### Run YomiToku with Lightweight Model Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/README.md Perform document analysis using the lightweight model for faster inference, potentially with a slight decrease in accuracy. This option is suitable for CPU execution and has a line reading limit of 50 characters. ```bash yomitoku ${path_data} -f md --lite -d cpu -o results -v --figure ``` -------------------------------- ### Run in Lightweight Mode Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/cli.en.md Performs inference using a lightweight model for faster analysis, potentially at the cost of reduced accuracy. Includes visualization. ```bash yomitoku ${path_data} --lite -v ``` -------------------------------- ### Run Docker Container (CPU) Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/installation.ja.md Run the YomiToku Docker container for CPU-only execution. This mounts the current directory and runs the container in interactive mode. ```bash docker run -it -v $(pwd):/workspace --name yomitoku yomitoku /bin/bash ``` -------------------------------- ### Specify Output Device Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/cli.en.md Selects the device for running the model inference. Options include 'cuda', 'cpu', and 'mps'. Defaults to 'cuda' if available. ```bash yomitoku ${path_data} -d cpu ``` -------------------------------- ### Download Models Manually Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/installation.ja.md Manually download models for use in environments without internet access. This command initiates the model download process. ```bash download_model ``` -------------------------------- ### Text Recognizer Visualization Settings Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/configuration.ja.md Configure visualization for text recognizer output. Specify font path, color, and font size for displaying predicted strings. ```yaml visualize: # 予測結果文字列の可視化に用いるフォントのパス font: str # 予測結果文字列の可視化に用いるフォントの色 color: [BGR] # 予測結果文字列のフォントの大きさ font_size: int ``` -------------------------------- ### Configure Text Recognizer Visualization Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/configuration.en.md Specify the font path, font color (BGR format), and font size for visualizing predicted result strings. ```yaml visualize: # The path to the font used for visualizing the predicted result strings. font: str # The color of the font used for visualizing the predicted result strings. color: [BGR] # The font size of the predicted result strings. font_size: int ``` -------------------------------- ### Text Detector Visualization Settings Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/configuration.ja.md Configure visualization for the text detector. Set bounding box colors and whether to visualize the prediction heatmap. ```yaml visualize: # 検出領域のバウンディングボックスの色の設定 color: [B, G, R] # モデルの予測ヒートマップを可視化、描画するか heatmap: boolean ``` -------------------------------- ### Run Yomitoku in Efficient Mode Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/README_EN.md Execute Yomitoku in efficient mode using a lightweight model for fast inference, even on a CPU. This mode is suitable for CPU-based processing. ```bash yomitoku ${path_data} -f md --lite -d cpu -o results -v --figure ``` -------------------------------- ### Execute LLM-Based Extraction with vLLM Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/README.md Perform LLM-based extraction by connecting to a vLLM server. Specify the input image, schema file, and the LLM model to use. ```bash # LLMベース抽出(vLLMサーバー使用) yomitoku_extract_with_llm input.jpg -s schema.yaml -m Qwen/Qwen3-8B-Instruct ``` -------------------------------- ### Text Detector Input Image Size Configuration Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/configuration.ja.md Configure image scaling for the text detector. `shortest_size` expands images below a threshold, while `limit_size` shrinks images exceeding a threshold. ```yaml data: # 画像の短辺ピクセル数が設定した数値を下回る場合にここで設定した画像のピクセル数に以上になるように画像を拡大します。 shortest_size: int # 画像の長辺ピクセル数が設定した数値を上回る場合にここで設定した画像のピクセル数以下になるように画像を縮小します。 limit_size: int ``` -------------------------------- ### LLM-Based Extraction CLI Command Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/extractor.ja.md Command to initiate LLM-based extraction using `yomitoku_extract_with_llm`. Requires input, schema, and a model name. Additional options for LLM API configuration, generation parameters, and debugging are available. ```bash yomitoku_extract_with_llm -s -m [options] ``` -------------------------------- ### Specify Configuration File Path Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/cli.en.md Specifies the path to the YAML configuration file for the Text Detector (TD) module. ```bash yomitoku ${path_data} --td_cfg ${path_yaml} ``` -------------------------------- ### Visualization Image Filenames Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/extractor.en.md When the --vis option is specified, the following images are output: layout analysis, OCR results, and highlighted positions of extracted fields. ```text | Filename | Content | | :--- | :--- | | `*_layout.jpg` | Layout analysis result visualization | | `*_ocr.jpg` | OCR result visualization | | `*_extract_vis.jpg` | Highlighted positions of extracted fields (with field name labels) | ``` -------------------------------- ### Rule-Based Extraction CLI Command Source: https://github.com/kotaro-kinoshita/yomitoku/blob/main/docs/extractor.ja.md Command to initiate rule-based extraction using the `yomitoku_extract` tool. Requires input file/directory and a schema file. Various options control output directory, inference device, visualization, normalization, output format, page selection, DPI, and encoding. ```bash yomitoku_extract -s [options] ```