AutoRegressive Transformer Model for Optical Character Recognition In Farasi
- Install Dependencies
$ pip install -r requirements.txt
- Download Pretrained Weights Here
- Project Structure
.
├── src
│ ├── nn
│ │ ├── decoder.py
│ │ ├── encoder.py
│ │ ├── __init__.py
│ ├── dataset.py
│ ├── misc.py
│ ├── schedule.py
│ ├── tokenizer.py
│ ├── tracker.py
│ ├── trainutils.py
│ ├── trabsforms.py
│ └── vocab.py
├── build.py
├── config.py
├── inference.py
└── main.py
Fig. 1. Proposed Model Architecture
ViT as Image Encoder: The bare ViT Model transformer outputting raw hidden-states without any specific head on top. This model is a PyTorch torch.nn.Module subclass. Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and behavior.
Positional Encoding: Since our model contains no recurrence and no convolution, in order for the model to make use of the order of the sequence, we must inject some information about the relative or absolute position of the tokens in the sequence. In this work, we use sine and cosine functions of different frequencies:
Multi-Head Attention: Multi-head Attention is a module for attention mechanisms which runs through an attention mechanism several times in parallel. The independent attention outputs are then concatenated and linearly transformed into the expected dimension. Intuitively, multipleattention heads allows for attending to parts of the sequence differently (e.g. longer-term dependencies versus shorter-term dependencies).
where
above
from src.tokenizer import loadTokenizer
from src.nn import TRnet
# load pretrained model
model, metadata = TRnet.from_pretrained('path/to/model.pth')
# load tokenizer
tokenizer = loadTokenizer('path/to/vocab.pkl')
python3 inference.py path/to/image/file.png
Project is distributed under MIT License