billingsmoore commited on
Commit
7abede2
·
verified ·
1 Parent(s): 67ddb17

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +180 -121
README.md CHANGED
@@ -1,199 +1,258 @@
1
  ---
2
  library_name: transformers
3
- tags: []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  ---
5
 
6
- # Model Card for Model ID
7
-
8
- <!-- Provide a quick summary of what the model is/does. -->
9
-
10
 
 
11
 
12
  ## Model Details
13
 
14
  ### Model Description
15
 
16
- <!-- Provide a longer summary of what this model is. -->
17
-
18
- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
19
 
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
 
28
- ### Model Sources [optional]
 
 
 
 
29
 
30
- <!-- Provide the basic links for the model. -->
31
 
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
 
36
  ## Uses
37
 
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
 
40
  ### Direct Use
41
 
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
-
44
- [More Information Needed]
45
-
46
- ### Downstream Use [optional]
47
-
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
-
50
- [More Information Needed]
51
-
52
- ### Out-of-Scope Use
53
-
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
-
56
- [More Information Needed]
57
-
58
- ## Bias, Risks, and Limitations
59
-
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
-
62
- [More Information Needed]
63
-
64
- ### Recommendations
65
-
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
-
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
 
70
- ## How to Get Started with the Model
 
71
 
72
- Use the code below to get started with the model.
73
 
74
- [More Information Needed]
 
 
75
 
76
- ## Training Details
77
-
78
- ### Training Data
79
 
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
 
82
- [More Information Needed]
83
-
84
- ### Training Procedure
85
 
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
 
88
- #### Preprocessing [optional]
89
 
90
- [More Information Needed]
91
 
 
92
 
93
- #### Training Hyperparameters
94
 
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
 
97
- #### Speeds, Sizes, Times [optional]
98
-
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
-
101
- [More Information Needed]
102
-
103
- ## Evaluation
104
 
105
- <!-- This section describes the evaluation protocols and provides the results. -->
106
 
107
- ### Testing Data, Factors & Metrics
 
108
 
109
- #### Testing Data
 
 
110
 
111
- <!-- This should link to a Dataset Card if possible. -->
 
112
 
113
- [More Information Needed]
 
 
 
 
 
 
 
 
 
114
 
115
- #### Factors
116
 
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
 
 
118
 
119
- [More Information Needed]
 
 
 
120
 
121
- #### Metrics
 
 
122
 
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
 
125
- [More Information Needed]
 
 
 
 
 
 
 
 
 
126
 
127
- ### Results
 
128
 
129
- [More Information Needed]
 
 
130
 
131
- #### Summary
 
 
132
 
 
 
 
133
 
 
 
 
 
 
 
134
 
135
- ## Model Examination [optional]
136
 
137
- <!-- Relevant interpretability work for the model goes here -->
138
 
139
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
 
141
- ## Environmental Impact
142
-
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
-
145
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
-
147
- - **Hardware Type:** [More Information Needed]
148
- - **Hours used:** [More Information Needed]
149
- - **Cloud Provider:** [More Information Needed]
150
- - **Compute Region:** [More Information Needed]
151
- - **Carbon Emitted:** [More Information Needed]
152
 
153
- ## Technical Specifications [optional]
154
 
155
- ### Model Architecture and Objective
156
 
157
- [More Information Needed]
158
 
159
- ### Compute Infrastructure
160
 
161
- [More Information Needed]
162
 
163
- #### Hardware
164
 
165
- [More Information Needed]
166
 
167
- #### Software
168
 
169
- [More Information Needed]
170
 
171
- ## Citation [optional]
172
 
173
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
 
175
- **BibTeX:**
176
 
177
- [More Information Needed]
178
 
179
- **APA:**
 
 
180
 
181
- [More Information Needed]
182
 
183
- ## Glossary [optional]
184
 
185
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
 
 
186
 
187
- [More Information Needed]
188
 
189
- ## More Information [optional]
 
 
190
 
191
- [More Information Needed]
192
 
193
- ## Model Card Authors [optional]
194
 
195
- [More Information Needed]
196
 
197
  ## Model Card Contact
198
 
199
- [More Information Needed]
 
1
  ---
2
  library_name: transformers
3
+ tags:
4
+ - translation
5
+ - Tibetan
6
+ - Buddhism
7
+ - dharma
8
+ license: mit
9
+ language:
10
+ - bo
11
+ - en
12
+ metrics:
13
+ - bleu
14
+ - ter
15
+ - chrf
16
+ base_model:
17
+ - google-t5/t5-base
18
+ pipeline_tag: translation
19
  ---
20
 
21
+ # Model Card for mlotsawa-ground-small
 
 
 
22
 
23
+ This model is a transformers machine translation model for translating Tibetan Buddhist texts to English, produced as part of the larger [MLotsawa project](https://github.com/billingsmoore/MLotsawa)
24
 
25
  ## Model Details
26
 
27
  ### Model Description
28
 
29
+ This model is a finetuned T5 model (base size) with 223 million parameters. It is intended for translation of Tibetan Buddhist texts into English. It expects input in Uchen script.
30
+ This model uses the **[getok](https://huggingface.co/billingsmoore/getok-v0)** tokenizer.
31
+ Details on the training data and procedure can be found below.
32
 
33
+ This model is a *ground* model in that, while its performance is reasonably good, it is intended to be used as a base for further finetuning on either a larger corpus or a tradition-specific (i.e. Dzogchen) corpus for improved translation quality.
 
 
 
 
 
 
34
 
35
+ - **Developed by:** billingsmoore
36
+ - **Model type:** translation
37
+ - **Languages:** Tibetan, English
38
+ - **License:** MIT
39
+ - **Finetuned from model:** google-t5/t5-base
40
 
41
+ ### Model Sources
42
 
43
+ - **Repository:** [MLotsawa on GitHub](https://github.com/billingsmoore/MLotsawa)
 
 
44
 
45
  ## Uses
46
 
47
+ This model may be used directly for translation, or further finetuned for improved performance.
48
 
49
  ### Direct Use
50
 
51
+ This model can be used directly for translation using a transformers pipeline as in the code block below.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
 
53
+ ```python
54
+ from transformers import pipeline
55
 
56
+ pipe = pipeline('translation', 'billingsmoore/mlotsawa-ground-base', device='cpu') # select a device of your choice (i.e. 'cuda:0')
57
 
58
+ input = ["ཁྱེད་ལ་བསྟོད་ཅིང་གསོལ་བ་བཏབ་པའི་མཐུས༔",
59
+ "བདག་གི་ཚེ་བསོད་དཔལ་འབྱོར་རྒྱས་པ་དང་༔",
60
+ "འཇིགས་པ་བཅུ་དྲུག་རྐྱེན་ངན་བར་ཆད་སོལ༔"]
61
 
62
+ output = pipe(input)
 
 
63
 
64
+ translation = [elt['translation_text'] for elt in output]
65
 
66
+ print(translation)
67
+ ```
 
68
 
69
+ The code above will produce the following output.
70
 
71
+ >['Through the power of praising and praying to you', 'Increase my lifespan merit and prosperity', 'Remove the sixteen fears and obstacles of adversity.']
72
 
73
+ Alternatively the model can be used with a graphical user interface following [the instructions found here.](https://pypi.org/project/mlotsawa/)
74
 
75
+ ### Downstream Use
76
 
77
+ The performance of this model can be improved with additional finetuning. You might finetune using a larger dataset for better general performance or finetune on a specific set of material for improved performance on that subset (i.e. Dzogchen texts).
78
 
79
+ The model can be finetuned following the recipe below.
80
 
81
+ ```python
82
+ # Load Your Data
83
+ from datasets import load_dataset
 
 
 
 
84
 
85
+ dataset = load_dataset(<your dataset>)
86
 
87
+ # Load the Model and Tokenizer
88
+ from transformers import AutoTokenizer, DataCollatorForSeq2Seq, AutoModelForSeq2SeqLM
89
 
90
+ model = AutoModelForSeq2SeqLM.from_pretrained("billingsmoore/mlotsawa-ground-base", device_map="cuda:0") # this line assumes you want to use a single CUDA enabled gpu
91
+ tokenizer = AutoTokenizer.from_pretrained('billingsmoore/mlotsawa-ground-base')
92
+ data_collator = DataCollatorForSeq2Seq(tokenizer=tokenizer, model=model)
93
 
94
+ # Preprocess the Data
95
+ def translation_preprocess_function(examples):
96
 
97
+ # Prepare translation inputs and targets
98
+ translation_inputs = ['Translate Tibetan to English: ' + example for example in examples['bo']]
99
+ translation_targets = [example for example in examples['en']]
100
+
101
+ # Tokenize translation inputs and targets
102
+ translation_model_inputs = tokenizer(translation_inputs, text_target=translation_targets,
103
+ max_length=256, truncation=True, padding="max_length")
104
+
105
+
106
+ return translation_model_inputs
107
 
108
+ tokenized_dataset = dataset.map(translation_preprocess_function, batched=True)
109
 
110
+ # Define Evaluation Metrics
111
+ import numpy as np
112
+ import evaluate
113
 
114
+ # Load BLEU and CHRF metrics
115
+ bleu_metric = evaluate.load("sacrebleu")
116
+ chrf_metric = evaluate.load("chrf")
117
+ ter_metric = evaluate.load("ter")
118
 
119
+ def postprocess_text(preds, labels):
120
+ preds = [pred.strip() for pred in preds]
121
+ labels = [[label.strip()] for label in labels]
122
 
123
+ return preds, labels
124
 
125
+ def compute_metrics(eval_preds):
126
+ preds, labels = eval_preds
127
+ if isinstance(preds, tuple):
128
+ preds = preds[0]
129
+
130
+ # Decode predictions and labels
131
+ preds = np.where(preds != -100, preds, tokenizer.pad_token_id)
132
+ decoded_preds = tokenizer.batch_decode(preds, skip_special_tokens=True)
133
+ labels = np.where(labels != -100, labels, tokenizer.pad_token_id)
134
+ decoded_labels = tokenizer.batch_decode(labels, skip_special_tokens=True)
135
 
136
+ # Postprocess text
137
+ decoded_preds, decoded_labels = postprocess_text(decoded_preds, decoded_labels)
138
 
139
+ # Compute BLEU score
140
+ bleu_result = bleu_metric.compute(predictions=decoded_preds, references=decoded_labels)
141
+ bleu_score = bleu_result["score"]
142
 
143
+ # Compute CHRF score
144
+ chrf_result = chrf_metric.compute(predictions=decoded_preds, references=decoded_labels)
145
+ chrf_score = chrf_result["score"]
146
 
147
+ # Compute TER score
148
+ ter_result = ter_metric.compute(predictions=decoded_preds, references=decoded_labels)
149
+ ter_score = ter_result["score"]
150
 
151
+ # Return rounded results
152
+ metrics = {
153
+ "bleu": round(bleu_score, 4),
154
+ "chrf": round(chrf_score, 4),
155
+ "ter": round(ter_score, 4)
156
+ }
157
 
158
+ #print("Computed Metrics:", metrics)
159
 
160
+ return metrics
161
 
162
+ # Set Up Training Arguments and Optimizer
163
+ from transformers import Seq2SeqTrainingArguments, Seq2SeqTrainer, Adafactor, EarlyStoppingCallback
164
+ from accelerate import Accelerator
165
+
166
+ accelerator = Accelerator()
167
+
168
+ optimizer = Adafactor(
169
+ model.parameters(),
170
+ scale_parameter=True,
171
+ relative_step=False,
172
+ warmup_init=False,
173
+ lr=3e-4
174
+ )
175
+
176
+ model, optimizer = accelerator.prepare(model, optimizer)
177
+
178
+ training_args = Seq2SeqTrainingArguments(
179
+ output_dir=f"output-dir", # select an output directory of your choice
180
+ auto_find_batch_size=True,
181
+ predict_with_generate=True,
182
+ fp16=False,
183
+ push_to_hub=False,
184
+ eval_strategy='epoch',
185
+ save_strategy='epoch',
186
+ num_train_epochs=100, # select your preferred number of training epochs
187
+ load_best_model_at_end=True,
188
+ )
189
+
190
+ trainer = Seq2SeqTrainer(
191
+ model=model,
192
+ args=training_args,
193
+ train_dataset=tokenized_dataset['train'],
194
+ eval_dataset=tokenized_dataset['dev'],
195
+ processing_class=tokenizer,
196
+ optimizers=(optimizer, None),
197
+ data_collator=data_collator,
198
+ compute_metrics=compute_metrics,
199
+ callbacks=[EarlyStoppingCallback()]
200
+ )
201
+
202
+ trainer.train()
203
+ ```
204
 
205
+ ## Bias, Risks, and Limitations
 
 
 
 
 
 
 
 
 
 
206
 
207
+ This model is intended for the translation of Buddhist texts. Because of the complexity and importance of this material, all translations should be treated as preliminary and should never be used without the input of an experienced human translator.
208
 
209
+ Additionally, this model was trained exclusively on Tibetan Buddhist material and should not be expected to perform well on other material (i.e. vernacular Tibetan).
210
 
211
+ ## Training Details
212
 
213
+ ### Training Data
214
 
215
+ The training data for this model was 861,417 translation pairs from Buddhist texts. This data was collected from publically available material as well as material generously provided by Monlam AI and the Tibetan and Himalayan Library.
216
 
217
+ ### Training Procedure
218
 
219
+ The model underwent continued pretraining as well as finetuning as described below.
220
 
221
+ #### Pretraining
222
 
223
+ The model was pretrained on the training data for one epoch with a learning rate of 3e-4.The pretraining objective remained the original span corruption denoising task, in which random spans of input tokens are masked and the model is trained to reconstruct the missing content. This pretraining allowed the model to adapt to the new tokenizer and to learn the linguistic and structural characteristics of the Tibetan Buddhist materials.
224
 
225
+ #### Finetuning
226
 
227
+ The model was finetuned on the translation pairs for 50 epochs using the Adafactor optimizer and an initial learning rate of 3e-4.
228
 
229
+ ## Evaluation
230
 
231
+ The model was evaluated on test data with BLEU, chrF, and TER. The results are shown below.
232
 
233
+ BLEU|chrF|TER
234
+ ----|----|---
235
+ 4.08|20.85|86.74
236
 
237
+ These scores are exceptionally low, however actual translation results are relatively good. Sample translations are shown below.
238
 
239
+ From *Advice on Bending Mind Toward the Good* by Khenchen Ngawang Palzang | Translated by Joseph McClellan with editorial assistance from Ninjyed N.T., 2024.
240
 
241
+ | **Original** | **Human Translation** | **Machine Translation** |
242
+ |:-------------|:----------------------|:------------------------|
243
+ | གྲུབ་བརྒྱའི་སྤྱི་མེས་པཎ་ཆེན་བི་མ་ལ། །<br>བསམ་བཞིན་སྤྲུལ་པའི་ཟློས་གར་ཉེར་བཟུང་བ། །<br>རྒྱལ་བའི་དབང་པོ་ཀློང་ཆེན་རབ་འབྱམས་པ། །<br>འདི་ཙམ་མ་ཡིན་ཚེ་རབས་གཏན་གྱི་སྐྱབས། ། | Grandsire of a hundred siddhas—great scholar, Vimalamitra,<br>And you who fully embraced the spectacle of intentional emanation,<br>Lord of conquerors, Longchen Rabjam—<br>You are my unfailing refuge; not just now, but in the concatenation of my lives. | Great paṇḍita Vimalamitra, forefather of hundreds of siddhas,<br>Manifesting in the form of a play,<br>Lord of the victorious ones, Longchen Rabjam,<br>Not just this but the constant refuge throughout all my lives, |
244
 
245
+ From *Protection from All Fears A Prayer to Ārya Tārā from the Reality Ḍākinīs’ Secret Treasury (Chönyi Khandrö Sangdzö)* by Sera Khandro | Translated by Adam Pearcey, 2025.
246
 
247
+ | **Original** | **Human Translation** | **Machine Translation** |
248
+ |:-------------|:----------------------|:------------------------|
249
+ |ཀ་དག་སྤྲོས་བྲལ་འོད་གསལ་རིག་པའི་དབྱིངས༔<br>ལྷུན་གྲུབ་སྣང་ཆ་མ་འགགས་སྒྱུ་འཕྲུལ་གར༔<br>ཐུགས་རྗེ་རྒྱལ་བ་ཀུན་གྱི་ཡུམ་གཅིག་མ༔<br>རྗེ་བཙུན་ཨཱརྱ་ཏཱ་རེ་ཚེ་སྦྱིན་དཔལ༔<br>གསོལ་བ་འདེབས་སོ་རླུང་སེམས་དབང་བསྡུས་ནས༔<br>ཚེ་དང་བསོད་ནམས་འཕེལ་བར་མཛད་དུ་གསོལ༔ | Out of the primordially pure unelaborate space of luminous awareness,<br>As the magical manifestation of unobstructed spontaneous presence,<br>Arises the compassionate one, the one and only mother of all victorious ones,<br>Noble Lady Ārya Tārā, glorious bestower of longevity,<br>To you I pray! Take control of my vital winds and mind,<br>And increase my lifespan and merit! | Within the space of awareness—primordial purity free of elaboration—<br>Illusory dance of spontaneously present appearances unceasing<br>Only mother of all the buddhas of compassion<br>Noble Ārya Tārā glorious Tārā<br>To you I pray: bringing the vāyu-mind under control<br>And increase our lifespan and merit.|
250
 
 
251
 
252
+ ## Model Card Authors
253
 
254
+ billingsmoore
255
 
256
  ## Model Card Contact
257
 
258
+ billingsmoore[at]gmail[dot]com