# Doc Transformers
Document processing using transformers. This is still in developmental phase, currently supports only extraction of form data i.e (key - value pairs)
```bash
pip install -q doc-transformers
```
## Pre-requisites
Please install the following seperately
```
pip install pip --upgrade
pip install -q git+https://github.com/huggingface/transformers.git
pip install pyyaml==5.1
# workaround: install old version of pytorch since detectron2 hasn't released packages for pytorch 1.9 (issue: https://github.com/facebookresearch/detectron2/issues/3158)
pip install torch==1.8.0+cu101 torchvision==0.9.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html
# install detectron2 that matches pytorch 1.8
# See https://detectron2.readthedocs.io/tutorials/install.html for instructions
pip install -q detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu101/torch1.8/index.html
```
## Implementation
```python
# loads the pretrained dataset also
from doc_transformers import parser
# loads the image and labels
image = parser.load_image(input_path_image)
labels = parser.load_tags()
# loads the model
feature_extractor, processor, model = parser.load_models()
# gets the bounding boxes, predictions, extracted words and image processed
kp = parser.process_image(image, feature_extractor, processor, model, labels)
```
## Results
**Input & Output**
<p float="left">
<img src="/bill7.png" width="350" height="600">
<img src="/output.png" width="350" height="600">
</p>
**Table**
- After saving to csv the result looks like the following
| LABEL | TEXT |
| ----- | ---------------------------------- |
| title | CREDIT CARD VOUCHER ANY RESTAURANT |
| title | ANYWHERE |
| key | DATE: |
| value | 02/02/2014 |
| key | TIME: |
| value | 11:11 |
| key | CARD |
| key | TYPE: |
| value | MC |
| key | ACCT: |
| value | XXXX XXXX XXXX |
| value | 1111 |
| key | TRANS |
| key | KEY: |
| value | HYU8789798234 |
| key | AUTH |
| key | CODE: |
| value | 12345 |
| key | EXP |
| key | DATE: |
| value | XX/XX |
| key | CHECK: |
| value | 1111 |
| key | TABLE: |
| value | 11/11 |
| key | SERVER: |
| value | 34 |
| value | MONIKA |
| key | Subtotal: |
| value | $1969 |
| value | .69 |
| key | Gratuity: Total: |
## Code credits
[@HuggingFace](https://huggingface.co/)
- Please note that this is still in development phase and will be improved in the near future
Raw data
{
"_id": null,
"home_page": "https://github.com/Vishnunkumar/doc_transformers/",
"name": "doc-transformers",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "doc_transformers",
"author": "Vishnu Nandakumar",
"author_email": "nkumarvishnu25@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/49/1a/bf348e38a5690bd2670c4639a996c2919542aa6b4ecc98d17ca8875b5b08/doc_transformers-1.0.2.tar.gz",
"platform": null,
"description": "# Doc Transformers\nDocument processing using transformers. This is still in developmental phase, currently supports only extraction of form data i.e (key - value pairs)\n\n```bash\npip install -q doc-transformers\n```\n\n## Pre-requisites\n\nPlease install the following seperately\n```\npip install pip --upgrade\npip install -q git+https://github.com/huggingface/transformers.git\n\npip install pyyaml==5.1\n\n# workaround: install old version of pytorch since detectron2 hasn't released packages for pytorch 1.9 (issue: https://github.com/facebookresearch/detectron2/issues/3158)\npip install torch==1.8.0+cu101 torchvision==0.9.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html\n\n# install detectron2 that matches pytorch 1.8\n# See https://detectron2.readthedocs.io/tutorials/install.html for instructions\npip install -q detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu101/torch1.8/index.html\n```\n\n## Implementation\n\n```python\n# loads the pretrained dataset also \nfrom doc_transformers import parser\n\n# loads the image and labels\nimage = parser.load_image(input_path_image)\nlabels = parser.load_tags()\n\n# loads the model\nfeature_extractor, processor, model = parser.load_models()\n\n# gets the bounding boxes, predictions, extracted words and image processed\nkp = parser.process_image(image, feature_extractor, processor, model, labels)\n```\n\n## Results\n\n**Input & Output**\n\n<p float=\"left\">\n<img src=\"/bill7.png\" width=\"350\" height=\"600\">\n<img src=\"/output.png\" width=\"350\" height=\"600\">\n</p>\n\n**Table**\n\n- After saving to csv the result looks like the following\n\n| LABEL | TEXT |\n| ----- | ---------------------------------- |\n| title | CREDIT CARD VOUCHER ANY RESTAURANT |\n| title | ANYWHERE |\n| key | DATE: |\n| value | 02/02/2014 |\n| key | TIME: |\n| value | 11:11 |\n| key | CARD |\n| key | TYPE: |\n| value | MC |\n| key | ACCT: |\n| value | XXXX XXXX XXXX |\n| value | 1111 |\n| key | TRANS |\n| key | KEY: |\n| value | HYU8789798234 |\n| key | AUTH |\n| key | CODE: |\n| value | 12345 |\n| key | EXP |\n| key | DATE: |\n| value | XX/XX |\n| key | CHECK: |\n| value | 1111 |\n| key | TABLE: |\n| value | 11/11 |\n| key | SERVER: |\n| value | 34 |\n| value | MONIKA |\n| key | Subtotal: |\n| value | $1969 |\n| value | .69 |\n| key | Gratuity: Total: |\n\n## Code credits\n\n[@HuggingFace](https://huggingface.co/)\n\n- Please note that this is still in development phase and will be improved in the near future\n",
"bugtrack_url": null,
"license": "MIT license",
"summary": "Deep learning for document processing",
"version": "1.0.2",
"split_keywords": [
"doc_transformers"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "491abf348e38a5690bd2670c4639a996c2919542aa6b4ecc98d17ca8875b5b08",
"md5": "57256940754696e97fc6e49e5e3dd0e1",
"sha256": "17ee79d4484bb319e79371c83cf8a1e266d16bd983806db37aade0a1bba9db9c"
},
"downloads": -1,
"filename": "doc_transformers-1.0.2.tar.gz",
"has_sig": false,
"md5_digest": "57256940754696e97fc6e49e5e3dd0e1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4673,
"upload_time": "2023-04-22T15:09:53",
"upload_time_iso_8601": "2023-04-22T15:09:53.544653Z",
"url": "https://files.pythonhosted.org/packages/49/1a/bf348e38a5690bd2670c4639a996c2919542aa6b4ecc98d17ca8875b5b08/doc_transformers-1.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-04-22 15:09:53",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "Vishnunkumar",
"github_project": "doc_transformers",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "doc-transformers"
}