Adeptschneider commited on
Commit
d9776fb
1 Parent(s): 07ae47f

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +114 -0
README.md ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ datasets:
4
+ - uvci/Koumankan_mt_dyu_fr
5
+ language:
6
+ - fr
7
+ metrics:
8
+ - bleu
9
+ - chrf
10
+ library_name: adapter-transformers
11
+ pipeline_tag: translation
12
+ ---
13
+
14
+ # Adeptschneider/dyu-fr-joeynmt
15
+
16
+ A machine translation model that translates Dyula to French using the [JoeyNMT framework](https://github.com/joeynmt/joeynmt).
17
+
18
+
19
+ ## Model description
20
+
21
+ More information needed
22
+
23
+ ## Intended uses & limitations
24
+
25
+ More information needed
26
+
27
+ ## Training and evaluation data
28
+
29
+ More information needed
30
+
31
+ ## Usage
32
+
33
+ ### Load and use for inference
34
+
35
+ ```python
36
+ import torch
37
+ from joeynmt.config import load_config, parse_global_args
38
+ from joeynmt.prediction import predict, prepare
39
+ from huggingface_hub import snapshot_download
40
+
41
+ # Download model
42
+ snapshot_download(
43
+ repo_id="Adeptschneider/joeynmt-dyu-fr-v19.0",
44
+ local_dir="/path/to/save/locally"
45
+ )
46
+
47
+ # Define model interface
48
+ class JoeyNMTModel:
49
+ '''
50
+ JoeyNMTModel which load JoeyNMT model for inference.
51
+
52
+ :param config_path: Path to YAML config file
53
+ :param n_best: return this many hypotheses, <= beam (currently only 1)
54
+ '''
55
+ def __init__(self, config_path: str, n_best: int = 1):
56
+ seed = 42
57
+ torch.manual_seed(seed)
58
+ cfg = load_config(config_path)
59
+ args = parse_global_args(cfg, rank=0, mode="translate")
60
+ self.args = args._replace(test=args.test._replace(n_best=n_best))
61
+ # build model
62
+ self.model, _, _, self.test_data = prepare(self.args, rank=0, mode="translate")
63
+
64
+ def _translate_data(self):
65
+ _, _, hypotheses, trg_tokens, trg_scores, _ = predict(
66
+ model=self.model,
67
+ data=self.test_data,
68
+ compute_loss=False,
69
+ device=self.args.device,
70
+ rank=0,
71
+ n_gpu=self.args.n_gpu,
72
+ normalization="none",
73
+ num_workers=self.args.num_workers,
74
+ args=self.args.test,
75
+ autocast=self.args.autocast,
76
+ )
77
+ return hypotheses, trg_tokens, trg_scores
78
+
79
+ def translate(self, sentence) -> list:
80
+ '''
81
+ Translate the given sentence.
82
+
83
+ :param sentence: Sentence to be translated
84
+ :return:
85
+ - translations: (list of str) possible translations of the sentence.
86
+ '''
87
+ self.test_data.set_item(sentence.strip())
88
+ translations, _, _ = self._translate_data()
89
+ assert len(translations) == len(self.test_data) * self.args.test.n_best
90
+ self.test_data.reset_cache()
91
+ return translations
92
+
93
+ # Load model
94
+ config_path = "/path/to/lean_model/config_local.yaml" # Change this to the path to your model congig file
95
+ model = JoeyNMTModel(config_path=config_path, n_best=1)
96
+
97
+ # Translate
98
+ model.translate(sentence="i tɔgɔ bi cogodɔ")
99
+ ```
100
+
101
+ ## Training procedure
102
+
103
+ ### Training hyperparameters
104
+
105
+ More information needed
106
+
107
+ ### Training results
108
+
109
+ More information needed
110
+
111
+ ### Framework versions
112
+
113
+ - JoeyNMT 2.3.0
114
+ - Torch 2.0.1+cu118