Matthijs0 commited on
Commit
e8a3d93
·
verified ·
1 Parent(s): ff6cfdd

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +62 -3
README.md CHANGED
@@ -1,3 +1,62 @@
1
- ---
2
- license: agpl-3.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # im2latex_model
2
+
3
+ This model is a VisionEncoderDecoderModel trained on a dataset for generating LaTeX formulas from images.
4
+ This is part of a project that reproduces the following paper: https://arxiv.org/html/2408.04015v1.
5
+ NOTE: In the paper, the model is finetuned on handwritten data after training. This is the model before finetuning.
6
+
7
+ ## Model Details
8
+
9
+ - **Encoder**: Swin Transformer
10
+ - **Decoder**: GPT-2
11
+ - **Framework**: PyTorch
12
+
13
+ ## Training Data
14
+
15
+ The data is taken from [OleehyO/latex-formulas](https://huggingface.co/datasets/OleehyO/latex-formulas). The data was divided into 80:10:10 for train, val and test. The splits were made as follows:
16
+
17
+ ```python
18
+ dataset = load_dataset(OleehyO/latex-formulas, cleaned_formulas)
19
+ train_val_split = dataset["train"].train_test_split(test_size=0.2, seed=42)
20
+ train_ds = train_val_split["train"]
21
+ val_test_split = train_val_split["test"].train_test_split(test_size=0.5, seed=42)
22
+ val_ds = val_test_split["train"]
23
+ test_ds = val_test_split["test"]
24
+ ```
25
+
26
+ ## Evaluation Metrics
27
+
28
+ The model was evaluated on a test set with the following results:
29
+ - **Test Loss**: TBA
30
+ - **Test BLEU Score**: ~0.7
31
+
32
+ ## Usage
33
+
34
+ You can use the model directly with the `transformers` library:
35
+
36
+ ```python
37
+ from transformers import VisionEncoderDecoderModel, AutoTokenizer, AutoFeatureExtractor
38
+ import torch
39
+ from PIL import Image
40
+
41
+ # Load model, tokenizer, and feature extractor
42
+ model = VisionEncoderDecoderModel.from_pretrained("your-username/your-model-name")
43
+ tokenizer = AutoTokenizer.from_pretrained("your-username/your-model-name")
44
+ feature_extractor = AutoFeatureExtractor.from_pretrained("your-username/your-model-name")
45
+
46
+ # Prepare an image
47
+ image = Image.open("path/to/your/image.png")
48
+ pixel_values = feature_extractor(images=image, return_tensors="pt").pixel_values
49
+
50
+ # Generate LaTeX formula
51
+ generated_ids = model.generate(pixel_values)
52
+ generated_texts = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
53
+
54
+ print("Generated LaTeX formula:", generated_texts[0])
55
+ ```
56
+
57
+ ## Training Script
58
+ The training script for this model can be found in the following repository: [GitHub](https://github.com/matthjs/DL-Im2Latex)
59
+
60
+ ---
61
+ license: agpl-3.0
62
+ ---