2024-03-25 11:23:54 +00:00
📄 English | <a href="./assets/README_zh.md">中文</a>
2024-02-12 08:41:33 +00:00
<div align="center">
2024-03-18 15:48:04 +00:00
<h1>
2025-08-14 22:35:24 +08:00
<img src="./assets/fire.svg" width=60, height=60>
2024-03-18 15:48:04 +00:00
𝚃 𝚎 𝚡 𝚃 𝚎 𝚕 𝚕 𝚎 𝚛
2025-08-14 22:35:24 +08:00
<img src="./assets/fire.svg" width=60, height=60>
2024-03-18 15:48:04 +00:00
</h1>
2024-06-05 16:55:42 +00:00
2025-04-23 04:47:51 +00:00
[](https://oleehyo.github.io/TexTeller/)
2025-08-14 22:35:24 +08:00
[](https://arxiv.org/abs/2508.09220)
2025-08-13 22:01:17 +08:00
[](https://huggingface.co/datasets/OleehyO/latex-formulas-80M)
2024-06-11 13:20:32 +08:00
[](https://huggingface.co/OleehyO/TexTeller)
2025-08-14 22:35:24 +08:00
[](https://hub.docker.com/r/oleehyo/texteller)
2025-04-23 04:47:51 +00:00
[](https://opensource.org/licenses/Apache-2.0)
2024-06-05 16:55:42 +00:00
2024-03-18 15:48:04 +00:00
</div>
2024-02-12 08:41:33 +00:00
2024-06-05 16:55:42 +00:00
https://github.com/OleehyO/TexTeller/assets/56267907/532d1471-a72e-4960-9677-ec6c19db289f
2025-04-23 04:47:51 +00:00
TexTeller is an end-to-end formula recognition model, capable of converting images into corresponding LaTeX formulas.
2024-06-05 16:55:42 +00:00
TexTeller was trained with **80M image-formula pairs ** (previous dataset can be obtained [here ](https://huggingface.co/datasets/OleehyO/latex-formulas )), compared to [LaTeX-OCR ](https://github.com/lukas-blecher/LaTeX-OCR ) which used a 100K dataset, TexTeller has **stronger generalization abilities ** and **higher accuracy ** , covering most use cases.
>[!NOTE]
> If you would like to provide feedback or suggestions for this project, feel free to start a discussion in the [Discussions section](https://github.com/OleehyO/TexTeller/discussions).
---
<table>
<tr>
<td>
## 🔖 Table of Contents
- [Getting Started ](#-getting-started )
- [Web Demo ](#-web-demo )
2025-04-23 04:47:51 +00:00
- [Server ](#-server )
- [Python API ](#-python-api )
2024-06-05 16:55:42 +00:00
- [Formula Detection ](#-formula-detection )
- [Training ](#️ ️ -training )
</td>
<td>
2024-03-25 16:34:46 +08:00
2024-06-05 16:55:42 +00:00
<div align="center">
<figure>
<img src="assets/cover.png" width="800">
<figcaption>
<p>Images that can be recognized by TexTeller</p>
</figcaption>
</figure>
<div>
</div>
</div>
2024-02-12 08:41:33 +00:00
2024-06-05 16:55:42 +00:00
</td>
</tr>
</table>
2024-02-11 08:06:50 +00:00
2025-04-25 11:59:03 +00:00
## 📮 Change Log
2024-04-11 16:44:19 +00:00
2025-04-25 11:59:03 +00:00
- [2024-06-06] **TexTeller3.0 released! ** The training data has been increased to **80M ** (**10x more than** TexTeller2.0 and also improved in data diversity). TexTeller3.0's new features:
2024-05-02 08:56:53 +00:00
2024-06-05 16:55:42 +00:00
- Support scanned image, handwritten formulas, English(Chinese) mixed formulas.
2024-02-12 08:41:33 +00:00
2024-06-05 16:55:42 +00:00
- OCR abilities in both Chinese and English for printed images.
2024-02-12 08:41:33 +00:00
2025-04-25 11:59:03 +00:00
- [2024-05-02] Support **paragraph recognition ** .
2024-06-05 16:55:42 +00:00
2025-04-25 11:59:03 +00:00
- [2024-04-12] **Formula detection model ** released!
2024-06-05 16:55:42 +00:00
2025-04-25 11:59:03 +00:00
- [2024-03-25] TexTeller2.0 released! The training data for TexTeller2.0 has been increased to 7.5M (15x more than TexTeller1.0 and also improved in data quality). The trained TexTeller2.0 demonstrated **superior performance ** in the test set, especially in recognizing rare symbols, complex multi-line formulas, and matrices.
2024-06-05 16:55:42 +00:00
> [Here](./assets/test.pdf) are more test images and a horizontal comparison of various recognition models.
2024-03-18 15:48:04 +00:00
## 🚀 Getting Started
2024-02-12 08:41:33 +00:00
2025-04-25 11:59:03 +00:00
1. Install uv:
2024-02-12 08:41:33 +00:00
2024-05-28 07:32:26 +00:00
```bash
2025-04-25 11:59:03 +00:00
pip install uv
2024-05-28 07:32:26 +00:00
```
2024-02-12 08:41:33 +00:00
2025-04-25 11:59:03 +00:00
2. Install the project's dependencies:
2024-02-12 08:41:33 +00:00
2024-05-28 07:32:26 +00:00
```bash
2025-04-25 11:59:03 +00:00
uv pip install texteller
2024-05-28 07:32:26 +00:00
```
2024-02-12 08:41:33 +00:00
2025-04-25 11:59:03 +00:00
3. If your are using CUDA backend, you may need to install `onnxruntime-gpu` :
```bash
uv pip install texteller[onnxruntime-gpu]
```
4. Run the following command to start inference:
2024-02-12 08:41:33 +00:00
2024-06-05 16:55:42 +00:00
```bash
2025-04-23 04:47:51 +00:00
texteller inference "/path/to/image.{jpg,png}"
2024-06-05 16:55:42 +00:00
```
2024-04-12 06:13:58 +00:00
2025-04-23 04:47:51 +00:00
> See `texteller inference --help` for more details
2024-04-11 16:44:19 +00:00
2024-06-05 16:55:42 +00:00
## 🌐 Web Demo
2024-04-12 06:13:58 +00:00
2025-04-23 04:47:51 +00:00
Run the following command:
2024-04-12 06:13:58 +00:00
```bash
2025-04-23 04:47:51 +00:00
texteller web
2024-04-12 06:13:58 +00:00
```
2024-06-05 16:55:42 +00:00
Enter `http://localhost:8501` in a browser to view the web demo.
> [!NOTE]
2025-04-23 04:47:51 +00:00
> Paragraph recognition cannot restore the structure of a document, it can only recognize its content.
2024-04-11 16:44:19 +00:00
2025-04-23 04:47:51 +00:00
## 🖥️ Server
2024-06-05 16:55:42 +00:00
2025-04-23 04:47:51 +00:00
We use [ray serve ](https://github.com/ray-project/ray ) to provide an API server for TexTeller. To start the server, run the following command:
2024-06-05 16:55:42 +00:00
2025-04-23 04:47:51 +00:00
```bash
texteller launch
```
2024-04-12 06:13:58 +00:00
2025-04-23 04:47:51 +00:00
| Parameter | Description |
| --------- | -------- |
| `-ckpt` | The path to the weights file,*default is TexTeller's pretrained weights*. |
| `-tknz` | The path to the tokenizer,*default is TexTeller's tokenizer*. |
| `-p` | The server's service port,*default is 8000*. |
| `--num-replicas` | The number of service replicas to run on the server,*default is 1 replica*. You can use more replicas to achieve greater throughput.|
| `--ncpu-per-replica` | The number of CPU cores used per service replica,*default is 1*.|
| `--ngpu-per-replica` | The number of GPUs used per service replica,*default is 1*. You can set this value between 0 and 1 to run multiple service replicas on one GPU to share the GPU, thereby improving GPU utilization. (Note, if --num_replicas is 2, --ngpu_per_replica is 0.7, then 2 GPUs must be available) |
| `--num-beams` | The number of beams for beam search,*default is 1*. |
| `--use-onnx` | Perform inference using Onnx Runtime, * disabled by default * |
2024-04-12 06:13:58 +00:00
2025-04-23 04:47:51 +00:00
To send requests to the server:
2024-04-12 06:13:58 +00:00
2025-04-23 04:47:51 +00:00
```python
# client_demo.py
2024-06-05 16:55:42 +00:00
2025-04-23 04:47:51 +00:00
import requests
2024-04-11 16:44:19 +00:00
2025-04-23 04:47:51 +00:00
server_url = "http://127.0.0.1:8000/predict"
2024-02-12 08:41:33 +00:00
2025-04-23 04:47:51 +00:00
img_path = "/path/to/your/image"
with open(img_path, 'rb') as img:
files = {'img': img}
response = requests.post(server_url, files=files)
2024-02-12 08:41:33 +00:00
2025-04-23 04:47:51 +00:00
print(response.text)
2024-02-12 08:41:33 +00:00
```
2025-04-23 04:47:51 +00:00
## 🐍 Python API
2024-02-12 08:41:33 +00:00
2025-04-23 04:47:51 +00:00
We provide several easy-to-use Python APIs for formula OCR scenarios. Please refer to our [documentation ](https://oleehyo.github.io/TexTeller/ ) to learn about the corresponding API interfaces and usage.
2024-02-12 08:41:33 +00:00
2025-04-23 04:47:51 +00:00
## 🔍 Formula Detection
2024-02-12 08:41:33 +00:00
2025-04-23 04:47:51 +00:00
TexTeller's formula detection model is trained on 3,415 images of Chinese materials and 8,272 images from the [IBEM dataset ](https://zenodo.org/records/4757865 ).
2024-02-12 08:41:33 +00:00
2025-04-23 04:47:51 +00:00
<div align="center">
<img src="./assets/det_rec.png" width=250>
</div>
2024-02-12 08:41:33 +00:00
2025-04-23 04:47:51 +00:00
We provide a formula detection interface in the Python API. Please refer to our [API documentation ](https://oleehyo.github.io/TexTeller/ ) for more details.
2024-02-12 08:41:33 +00:00
2025-04-23 04:47:51 +00:00
## 🏋️♂️ Training
2024-02-12 08:41:33 +00:00
2025-04-23 04:47:51 +00:00
Please setup your environment before training:
2024-02-12 08:41:33 +00:00
2025-04-23 04:47:51 +00:00
1. Install the dependencies for training:
2024-02-12 08:41:33 +00:00
2025-04-23 04:47:51 +00:00
```bash
2025-04-25 11:59:03 +00:00
uv pip install texteller[train]
2025-04-23 04:47:51 +00:00
```
2. Clone the repository:
2024-02-12 08:41:33 +00:00
2024-05-28 07:32:26 +00:00
```bash
2025-04-23 04:47:51 +00:00
git clone https://github.com/OleehyO/TexTeller.git
2024-05-28 07:32:26 +00:00
```
2024-02-12 08:41:33 +00:00
2025-04-23 04:47:51 +00:00
### Dataset
We provide an example dataset in the `examples/train_texteller/dataset/train` directory, you can place your own training data according to the format of the example dataset.
2024-03-18 15:48:04 +00:00
### Training the Model
2024-02-12 08:41:33 +00:00
2025-04-23 04:47:51 +00:00
In the `examples/train_texteller/` directory, run the following command:
2024-05-07 07:28:16 +00:00
```bash
2025-04-23 04:47:51 +00:00
accelerate launch train.py
2024-05-07 07:28:16 +00:00
```
2024-02-12 08:41:33 +00:00
2025-04-23 04:47:51 +00:00
Training arguments can be adjusted in [`train_config.yaml` ](./examples/train_texteller/train_config.yaml ).
2024-02-12 08:41:33 +00:00
2024-03-18 15:48:04 +00:00
## 📅 Plans
2024-06-05 16:55:42 +00:00
- [X] ~~Train the model with a larger dataset~~
- [X] ~~Recognition of scanned images~~
- [X] ~~Support for English and Chinese scenarios~~
- [X] ~~Handwritten formulas support~~
2024-05-28 07:32:26 +00:00
- [ ] PDF document recognition
2024-03-18 15:48:04 +00:00
- [ ] Inference acceleration
2024-02-12 08:41:33 +00:00
2024-04-12 07:29:36 +00:00
## ⭐️ Stargazers over time
[](https://starchart.cc/OleehyO/TexTeller)
## 👥 Contributors
2024-03-18 15:48:04 +00:00
2024-04-12 07:29:36 +00:00
<a href="https://github.com/OleehyO/TexTeller/graphs/contributors">
<a href="https://github.com/OleehyO/TexTeller/graphs/contributors">
<img src="https://contrib.rocks/image?repo=OleehyO/TexTeller" />
</a>
</a>