megalaa commited on
Commit
e086fdb
1 Parent(s): 21b640d

Upload 12 files

Browse files
args.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"model_name": "multicoptic/entire_clean_corpus", "src_language": "eng", "tgt_language": "cop", "max_input_length": 128, "max_target_length": 128}
config.json ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "megalaa/en-cop-mul-norm-group-greekified",
3
+ "activation_dropout": 0.0,
4
+ "activation_function": "swish",
5
+ "add_bias_logits": false,
6
+ "add_final_layer_norm": false,
7
+ "architectures": [
8
+ "MarianMTModel"
9
+ ],
10
+ "attention_dropout": 0.0,
11
+ "bad_words_ids": [
12
+ [
13
+ 64109
14
+ ]
15
+ ],
16
+ "bos_token_id": 0,
17
+ "classif_dropout": 0.0,
18
+ "classifier_dropout": 0.0,
19
+ "custom_pipelines": {
20
+ "english-coptic-translation": {
21
+ "default": {
22
+ "model": {
23
+ "pt": "megalaa/en-cop-mul-norm-group-greekified"
24
+ }
25
+ },
26
+ "impl": "english_coptic_pipeline.EnglishCopticPipeline",
27
+ "pt": [
28
+ "AutoModelForSeq2SeqLM"
29
+ ],
30
+ "tf": [],
31
+ "type": "text"
32
+ }
33
+ },
34
+ "d_model": 512,
35
+ "decoder_attention_heads": 8,
36
+ "decoder_ffn_dim": 2048,
37
+ "decoder_layerdrop": 0.0,
38
+ "decoder_layers": 6,
39
+ "decoder_start_token_id": 64109,
40
+ "decoder_vocab_size": 64110,
41
+ "dropout": 0.1,
42
+ "encoder_attention_heads": 8,
43
+ "encoder_ffn_dim": 2048,
44
+ "encoder_layerdrop": 0.0,
45
+ "encoder_layers": 6,
46
+ "eos_token_id": 0,
47
+ "extra_pos_embeddings": 64110,
48
+ "forced_eos_token_id": 0,
49
+ "id2label": {
50
+ "0": "LABEL_0",
51
+ "1": "LABEL_1",
52
+ "2": "LABEL_2"
53
+ },
54
+ "init_std": 0.02,
55
+ "is_encoder_decoder": true,
56
+ "label2id": {
57
+ "LABEL_0": 0,
58
+ "LABEL_1": 1,
59
+ "LABEL_2": 2
60
+ },
61
+ "max_length": 512,
62
+ "max_position_embeddings": 512,
63
+ "model_type": "marian",
64
+ "normalize_before": false,
65
+ "normalize_embedding": false,
66
+ "num_beams": 4,
67
+ "num_hidden_layers": 6,
68
+ "pad_token_id": 64109,
69
+ "scale_embedding": true,
70
+ "share_encoder_decoder_embeddings": true,
71
+ "static_position_embeddings": true,
72
+ "torch_dtype": "float32",
73
+ "transformers_version": "4.38.1",
74
+ "use_cache": true,
75
+ "vocab_size": 64110
76
+ }
english_coptic_pipeline.py ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Dict
2
+ import numpy as np
3
+ import torch
4
+ from transformers import Pipeline
5
+ from transformers.utils import ModelOutput
6
+ from transformers import pipeline
7
+ from transformers.pipelines import PIPELINE_REGISTRY
8
+ from transformers import AutoModelForSeq2SeqLM
9
+ from huggingface_hub import Repository
10
+
11
+ SAHIDIC_TAG = "з"
12
+ BOHAIRIC_TAG = "б"
13
+
14
+ from transformers import GenerationConfig
15
+
16
+ GENERATION_CONFIG = GenerationConfig(
17
+ max_length=20,
18
+ max_new_tokens=128,
19
+ min_new_tokens=1,
20
+ min_length=0,
21
+ early_stopping=True,
22
+ do_sample=True,
23
+ num_beams=5,
24
+ num_beam_groups=1,
25
+ top_k=50,
26
+ top_p=0.95,
27
+ temperature=1.0,
28
+ diversity_penalty=0.0,
29
+ output_scores=True,
30
+ return_dict_in_generate=True,
31
+ )
32
+
33
+
34
+ class EnglishCopticPipeline(Pipeline):
35
+ def _sanitize_parameters(self, **kwargs):
36
+ preprocess_kwargs = {}
37
+ if "to_bohairic" in kwargs and kwargs["to_bohairic"]:
38
+ preprocess_kwargs["to_bohairic"] = True
39
+ forward_kwargs = {}
40
+ if "output_confidence" in kwargs and kwargs["output_confidence"]:
41
+ forward_kwargs["output_confidence"] = True
42
+
43
+ return preprocess_kwargs, forward_kwargs, {}
44
+
45
+ def preprocess(self, text, to_bohairic=False):
46
+ if to_bohairic:
47
+ text = f"{BOHAIRIC_TAG} {text}"
48
+ else:
49
+ text = f"{SAHIDIC_TAG} {text}"
50
+
51
+ return self.tokenizer.encode(text, return_tensors="pt")
52
+
53
+ def _forward(self, input_tensors, output_confidence=False) -> ModelOutput:
54
+ outputs = self.model.generate(
55
+ input_tensors[:, : self.tokenizer.model_max_length],
56
+ generation_config=GENERATION_CONFIG,
57
+ )
58
+
59
+ translated_text = self.tokenizer.decode(
60
+ outputs.sequences[0], skip_special_tokens=True
61
+ )
62
+
63
+ if output_confidence:
64
+ scores = outputs.scores
65
+ confidences = [
66
+ torch.softmax(score, dim=-1).max().item() for score in scores
67
+ ]
68
+ num_words = len(translated_text.split())
69
+ # scale the predicition probability by the number of words in the sentence
70
+ scaled_probability = np.exp(sum(np.log(confidences)) / num_words)
71
+ return translated_text, scaled_probability
72
+
73
+ return translated_text, None
74
+
75
+ def postprocess(self, outputs):
76
+ text, confidence = outputs
77
+ text = degreekify(text)
78
+
79
+ if confidence is None:
80
+ return {
81
+ "translation": text,
82
+ }
83
+ return {
84
+ "translation": text,
85
+ "confidence": confidence,
86
+ }
87
+
88
+
89
+ GREEK_TO_COPTIC = {
90
+ "α": "ⲁ",
91
+ "β": "ⲃ",
92
+ "γ": "ⲅ",
93
+ "δ": "ⲇ",
94
+ "ε": "ⲉ",
95
+ "ϛ": "ⲋ",
96
+ "ζ": "ⲍ",
97
+ "η": "ⲏ",
98
+ "θ": "ⲑ",
99
+ "ι": "ⲓ",
100
+ "κ": "ⲕ",
101
+ "λ": "ⲗ",
102
+ "μ": "ⲙ",
103
+ "ν": "ⲛ",
104
+ "ξ": "ⲝ",
105
+ "ο": "ⲟ",
106
+ "π": "ⲡ",
107
+ "ρ": "ⲣ",
108
+ "σ": "ⲥ",
109
+ "τ": "ⲧ",
110
+ "υ": "ⲩ",
111
+ "φ": "ⲫ",
112
+ "χ": "ⲭ",
113
+ "ψ": "ⲯ",
114
+ "ω": "ⲱ",
115
+ "s": "ϣ",
116
+ "f": "ϥ",
117
+ "k": "ϧ",
118
+ "h": "ϩ",
119
+ "j": "ϫ",
120
+ "c": "ϭ",
121
+ "t": "ϯ",
122
+ }
123
+
124
+
125
+ def degreekify(greek_text):
126
+ chars = []
127
+ for c in greek_text:
128
+ l_c = c.lower()
129
+ chars.append(GREEK_TO_COPTIC.get(l_c, l_c))
130
+ return "".join(chars)
generation_config.json ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bad_words_ids": [
3
+ [
4
+ 64109
5
+ ]
6
+ ],
7
+ "bos_token_id": 0,
8
+ "decoder_start_token_id": 64109,
9
+ "eos_token_id": 0,
10
+ "forced_eos_token_id": 0,
11
+ "max_length": 512,
12
+ "num_beams": 4,
13
+ "pad_token_id": 64109,
14
+ "renormalize_logits": true,
15
+ "transformers_version": "4.38.1"
16
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:55169bef13952d3624e764b9cfc12184dfe36b791dcd62ac6c00969732fcd649
3
+ size 308136760
source.spm ADDED
Binary file (790 kB). View file
 
special_tokens_map.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "eos_token": {
3
+ "content": "</s>",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "pad_token": {
10
+ "content": "<pad>",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "unk_token": {
17
+ "content": "<unk>",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ }
23
+ }
target.spm ADDED
Binary file (707 kB). View file
 
tokenizer_config.json ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "</s>",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "1": {
12
+ "content": "<unk>",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "64109": {
20
+ "content": "<pad>",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ }
27
+ },
28
+ "clean_up_tokenization_spaces": true,
29
+ "eos_token": "</s>",
30
+ "model_max_length": 512,
31
+ "pad_token": "<pad>",
32
+ "separate_vocabs": false,
33
+ "source_lang": "eng",
34
+ "sp_model_kwargs": {},
35
+ "target_lang": "mul",
36
+ "tokenizer_class": "MarianTokenizer",
37
+ "unk_token": "<unk>"
38
+ }
train_config.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"job_hash": "3d348028d8010224e22c79db67880e89", "evaluation_strategy": "steps", "learning_rate": 5e-05, "per_device_train_batch_size": 96, "per_device_eval_batch_size": 96, "weight_decay": 0, "save_total_limit": 4, "num_train_epochs": 12, "num_train_steps": null, "predict_with_generate": true, "eval_steps": 238, "logging_steps": 50, "label_smoothing_factor": 0, "commit_hash": "e045ea0"}
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:22aa8d502427aefee756f474d55cd2a0d9395db1d71f196d9e7a571d0b785272
3
+ size 4603
vocab.json ADDED
The diff for this file is too large to render. See raw diff