Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

roman/cli infer table arg #1685

Merged
merged 5 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
## 0.10.22-dev3
## 0.10.22-dev4

### Enhancements

* **Expose skip_infer_table_types in ingest CLI** For each connector a new `--skip-infer-table-types` parameter was added to map to the `skip_infer_table_types` partition argument. This gives more granular control to unstructured-ingest users, allowing them to specify which file types for which we should attempt table extraction.

### Features

### Fixes
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
[
{
"type": "Title",
"element_id": "5fc3b3d02c954fce8bdb8742665da14d",
"metadata": {
"data_source": {},
"filetype": "image/jpeg",
"page_number": 1
},
"text": "LayoutParser: A Unified Toolkit for DL-Based DIA 5,"
},
{
"type": "FigureCaption",
"element_id": "53522497f48d7f32acd862a28dee0253",
"metadata": {
"data_source": {},
"filetype": "image/jpeg",
"page_number": 1
},
"text": "‘Table 1: Current layout detection models in the LayoutParser model z00"
},
{
"type": "Table",
"element_id": "0f0bad1db94e5aaa06c7ff033f7a27cf",
"metadata": {
"data_source": {},
"filetype": "image/jpeg",
"page_number": 1
},
"text": "Dataset | Bare Model! Large Mode! | Noter PablagNee [5] P/M M_|Tayous of moder scientie documents Rima [) « = | tagout of scanned modern magains and cee reports Newspaper [IT]| FP {Layout of ranned US nemepapers fom the 2h entry ‘Thbtebenk (i) | ‘able epon cn modern aciente and business document apace 1) |_P/M =| tagout of itary Inpanere documents"
},
{
"type": "FigureCaption",
"element_id": "37a781e7327333b86b022ed7fb12d620",
"metadata": {
"data_source": {},
"filetype": "image/jpeg",
"page_number": 1
},
"text": "Sek ca pe ogee ile Se riot (ade ines ores Tsbooe 09, pect, One ca nin moose cet acct ie Ptr LOND Bi (7) and Mask ‘hay tn Hee tens Te platen etd sete it bem ee me"
},
{
"type": "NarrativeText",
"element_id": "62253f3b9ad80b81d9fe3656d597ba21",
"metadata": {
"data_source": {},
"filetype": "image/jpeg",
"page_number": 1
},
"text": "layout data structures, which are optimized for efficiency and versatility. 3) When necessary, users can employ existing or customized OCR models via the unified API provided in the OCR module. 4) LayoutParser comes with a set of utility fanctions for the visualization and storage of the layout data. 5) LayoutParser is also highly customizable, via its integration with functions for layout data annotation and model training We now provide detailed descriptions for each component."
},
{
"type": "Title",
"element_id": "958174bfb8153f0b2c1d247196bcf8b1",
"metadata": {
"data_source": {},
"filetype": "image/jpeg",
"page_number": 1
},
"text": "3.1 Layout Detection Models"
},
{
"type": "NarrativeText",
"element_id": "f72c039d55d8062b540b8f075bf697fb",
"metadata": {
"data_source": {},
"filetype": "image/jpeg",
"page_number": 1
},
"text": "In LayoutParser, a layout model takes a document image as an input and generates a list of rectangular boxes for the target content regions. Different from traditional methods, it relies on deep convolutional neural networks rather than manually curated rules to identify content regions. It is formulated as an object detection problem and state-of-the-art’ models like Faster R-CNNY [28] and Mask R-CNN [12] are used. ‘This yields prediction results of high accuracy and makes it possible to build a concise, generalized interface for layout detection. LayoutParser, built upon Detectron? [38], provides a minimal API that can perform layout detection with only four lines of code in Python:"
},
{
"type": "ListItem",
"element_id": "742f93af10c235d2612a2b85c7ce9294",
"metadata": {
"data_source": {},
"filetype": "image/jpeg",
"page_number": 1
},
"text": "\\ import layoutparser as 1p"
},
{
"type": "ListItem",
"element_id": "44723386662ffb524ec7b20b0ddf2382",
"metadata": {
"data_source": {},
"filetype": "image/jpeg",
"page_number": 1
},
"text": "2 image = cv2.imread(\"image_file\") # load images"
},
{
"type": "UncategorizedText",
"element_id": "32ebb1abcc1c601ceb9c4e3c4faba0ca",
"metadata": {
"data_source": {},
"filetype": "image/jpeg",
"page_number": 1
},
"text": "("
},
{
"type": "ListItem",
"element_id": "cd84964c612152f5362ee38fab9cad62",
"metadata": {
"data_source": {},
"filetype": "image/jpeg",
"page_number": 1
},
"text": "» model = 1p. Detectron2LayoutModel"
},
{
"type": "ListItem",
"element_id": "868ea4c7705456b218188afb4e2a04ab",
"metadata": {
"data_source": {},
"filetype": "image/jpeg",
"page_number": 1
},
"text": "\"1p: //PubLayllet /faster_renn_t |-50_FPI_3x/config\")"
},
{
"type": "UncategorizedText",
"element_id": "4b227777d4dd1fc61c6f884f48641d02",
"metadata": {
"data_source": {},
"filetype": "image/jpeg",
"page_number": 1
},
"text": "4"
},
{
"type": "Title",
"element_id": "cfacfd3ec33b9608b59a343d05da204c",
"metadata": {
"data_source": {},
"filetype": "image/jpeg",
"page_number": 1
},
"text": "detect"
},
{
"type": "ListItem",
"element_id": "ec23428744214fb4e7dd4d5d25939ae9",
"metadata": {
"data_source": {},
"filetype": "image/jpeg",
"page_number": 1
},
"text": "layout = model. (image)"
},
{
"type": "NarrativeText",
"element_id": "9e7beafe373dc2fbff761d7997defec9",
"metadata": {
"data_source": {},
"filetype": "image/jpeg",
"page_number": 1
},
"text": "LayoutParser provides a wealth of pre-trained model weights using various datasets covering different languages, time periods, and document types. Due to domain shift [7], the prediction performance can notably drop when models are ap- plied to target samples that are significantly different from the training dataset. As document structures and layouts vary greatly in different domains, itis important to select models trained on adataset similar to the test samples. A semantic syntax is used for initializing the model weights in LayoutParser, using both the dataset name and model name 1p://<dataset-nane>/<nodel-archi tecture-nane>."
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ PYTHONPATH=. ./unstructured/ingest/main.py \
--num-processes "$max_processes" \
--metadata-exclude coordinates,filename,file_directory,metadata.data_source.date_processed,metadata.last_modified,metadata.detection_class_prob,metadata.parent_id,metadata.category_depth \
--output-dir "$OUTPUT_DIR" \
--skip-infer-table-types "jpg" \
--pdf-infer-table-structure true \
--strategy hi_res \
--verbose \
--reprocess \
--input-path example-docs/layout-parser-paper.pdf \
--input-path "$SCRIPT_DIR"/example-docs/ \
--work-dir "$WORK_DIR"

set +e
Expand Down
2 changes: 1 addition & 1 deletion unstructured/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.10.22-dev3" # pragma: no cover
__version__ = "0.10.22-dev4" # pragma: no cover
6 changes: 6 additions & 0 deletions unstructured/ingest/cli/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ class CliPartitionConfig(PartitionConfig, CliMixin):
@staticmethod
def add_cli_options(cmd: click.Command) -> None:
options = [
click.Option(
["--skip-infer-table-types"],
type=DelimitedString(),
default=None,
help="Optional list of document types to skip table extraction on",
),
click.Option(
["--pdf-infer-table-structure"],
default=False,
Expand Down
1 change: 1 addition & 0 deletions unstructured/ingest/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class BaseConfig(DataClassJsonMixin, ABC):
class PartitionConfig(BaseConfig):
# where to write structured data outputs
pdf_infer_table_structure: bool = False
skip_infer_table_types: t.Optional[t.List[str]] = None
strategy: str = "auto"
ocr_languages: str = "eng"
encoding: t.Optional[str] = None
Expand Down
15 changes: 11 additions & 4 deletions unstructured/ingest/pipeline/partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,19 @@ def run(self, ingest_doc_json) -> str:
if self.partition_config.ocr_languages
else []
)
partition_kwargs = {
"strategy": self.partition_config.strategy,
"languages": languages,
"encoding": self.partition_config.encoding,
"pdf_infer_table_structure": self.partition_config.pdf_infer_table_structure,
}
if self.partition_config.skip_infer_table_types:
partition_kwargs[
"skip_infer_table_types"
] = self.partition_config.skip_infer_table_types
elements = doc.process_file(
partition_config=self.partition_config,
strategy=self.partition_config.strategy,
languages=languages,
encoding=self.partition_config.encoding,
pdf_infer_table_structure=self.partition_config.pdf_infer_table_structure,
**partition_kwargs,
)
with open(json_path, "w", encoding="utf8") as output_f:
logger.info(f"writing partitioned content to {json_path}")
Expand Down
Loading