Update README.md
Browse files
README.md
CHANGED
@@ -6,9 +6,6 @@ language:
|
|
6 |
- 'no'
|
7 |
- en
|
8 |
pipeline_tag: text-generation
|
9 |
-
inference:
|
10 |
-
parameters:
|
11 |
-
temperature: 0.7
|
12 |
tags:
|
13 |
- translation
|
14 |
---
|
@@ -21,53 +18,17 @@ Translate text data from English to Swedish, or Swedish to English.
|
|
21 |
|
22 |
|
23 |
## How to use:
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
# (Optional) - define a stopping criteria
|
32 |
-
# We ideally want the model to stop generate once the response from the Bot is generated
|
33 |
-
class StopOnTokenCriteria(StoppingCriteria):
|
34 |
-
def __init__(self, stop_token_id):
|
35 |
-
self.stop_token_id = stop_token_id
|
36 |
-
|
37 |
-
def __call__(self, input_ids, scores, **kwargs):
|
38 |
-
return input_ids[0, -1] == self.stop_token_id
|
39 |
-
|
40 |
-
|
41 |
-
pipe = pipeline(
|
42 |
-
task="text-generation",
|
43 |
-
model="AI-Sweden-Models/gpt-sw3-6.7b-v2-translator",
|
44 |
-
device=device
|
45 |
-
)
|
46 |
-
|
47 |
-
stop_on_token_criteria = StopOnTokenCriteria(stop_token_id=pipe.tokenizer.bos_token_id)
|
48 |
-
text = "I like to eat ice cream in the summer."
|
49 |
-
|
50 |
-
# This will translate English to Swedish
|
51 |
-
# To translate from Swedish to English the prompt would be:
|
52 |
-
# prompt = f"<|endoftext|><s>User: Översätt till Engelska från Svenska\n{text}<s>Bot:"
|
53 |
-
|
54 |
-
prompt = f"<|endoftext|><s>User: Översätt till Svenska från Engelska\n{text}<s>Bot:"
|
55 |
-
|
56 |
-
input_tokens = pipe.tokenizer(prompt, return_tensors="pt").input_ids.to(device)
|
57 |
-
max_model_length = 2048
|
58 |
-
dynamic_max_length = max_model_length - input_tokens.shape[1]
|
59 |
-
|
60 |
-
response = pipe(
|
61 |
-
prompt,
|
62 |
-
max_length=dynamic_max_length,
|
63 |
-
truncation=True,
|
64 |
-
stopping_criteria=StoppingCriteriaList([stop_on_token_criteria])
|
65 |
-
)
|
66 |
-
|
67 |
-
print(response[0]["generated_text"].split("<s>Bot: ")[-1])
|
68 |
```
|
69 |
-
|
70 |
-
|
|
|
|
|
|
|
71 |
```
|
72 |
|
73 |
## Training & Data:
|
|
|
6 |
- 'no'
|
7 |
- en
|
8 |
pipeline_tag: text-generation
|
|
|
|
|
|
|
9 |
tags:
|
10 |
- translation
|
11 |
---
|
|
|
18 |
|
19 |
|
20 |
## How to use:
|
21 |
+
Swedish to English:
|
22 |
+
```bash
|
23 |
+
FROM ./gpt-sw3-6-7b-v2-translator-SIZE.gguf
|
24 |
+
TEMPLATE """"<|endoftext|><s>User: Översätt till Svenska från Engelska\n{{ .Prompt }}<s>Bot:""""
|
25 |
+
PARAMETER stop <s>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
```
|
27 |
+
English to Swedish:
|
28 |
+
```bash
|
29 |
+
FROM ./gpt-sw3-6-7b-v2-translator-SIZE.gguf
|
30 |
+
TEMPLATE """"<|endoftext|><s>User: Översätt till Engelska från Svenska\n{{ .Prompt }}<s>Bot:""""
|
31 |
+
PARAMETER stop <s>
|
32 |
```
|
33 |
|
34 |
## Training & Data:
|