initial commit
Browse files- README.md +95 -0
- config.json +44 -0
- pytorch_model.bin +3 -0
- special_tokens_map.json +1 -0
- tokenizer.json +0 -0
- tokenizer_config.json +1 -0
README.md
ADDED
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language: sv
|
3 |
+
|
4 |
+
widget:
|
5 |
+
- text: "Jag har ätit en <mask>"
|
6 |
+
---
|
7 |
+
|
8 |
+
## KB-BART
|
9 |
+
|
10 |
+
**EXPERIMENTAL:** still work in progress.
|
11 |
+
|
12 |
+
BART trained on Swedish data.
|
13 |
+
|
14 |
+
|
15 |
+
## Usage
|
16 |
+
|
17 |
+
```python
|
18 |
+
from transformers import BartForConditionalGeneration, PreTrainedTokenizerFast
|
19 |
+
from transformers import pipeline
|
20 |
+
|
21 |
+
model = BartForConditionalGeneration.from_pretrained("KBLab/bart-base-swedish-cased")
|
22 |
+
tok = PreTrainedTokenizerFast(
|
23 |
+
tokenizer_file="tokenizer.json",
|
24 |
+
bos_token="<s>",
|
25 |
+
eos_token="</s>",
|
26 |
+
unk_token="<unk>",
|
27 |
+
pad_token="<pad>",
|
28 |
+
mask_token="<mask>",
|
29 |
+
cls_token="</s>",
|
30 |
+
sep_token="</s>",
|
31 |
+
)
|
32 |
+
|
33 |
+
model.eval()
|
34 |
+
|
35 |
+
input_ids = tok.encode(
|
36 |
+
"Jag har ätit en utsökt <mask> på restaurang vid <mask> .", return_tensors="pt"
|
37 |
+
)
|
38 |
+
|
39 |
+
|
40 |
+
# Simple greedy search
|
41 |
+
output_ids = model.generate(
|
42 |
+
input_ids,
|
43 |
+
min_length=15,
|
44 |
+
max_length=25,
|
45 |
+
num_beams=1,
|
46 |
+
do_sample=False,
|
47 |
+
)
|
48 |
+
tok.decode(output_ids[0])
|
49 |
+
# '</s><s> Jag har ätit en utsökt middag på restaurang vid havet på restaurang vid havet på restaurang vid havet.</s>'
|
50 |
+
|
51 |
+
|
52 |
+
# Sampling
|
53 |
+
output_ids = model.generate(
|
54 |
+
input_ids,
|
55 |
+
min_length=15,
|
56 |
+
max_length=20,
|
57 |
+
num_beams=1,
|
58 |
+
do_sample=True,
|
59 |
+
)
|
60 |
+
tok.decode(output_ids[0])
|
61 |
+
#'</s><s> Jag har ätit en utsökt god mat som de tagit in på restaurang vid avröjda</s>'
|
62 |
+
|
63 |
+
|
64 |
+
# Beam search
|
65 |
+
output_ids = model.generate(
|
66 |
+
input_ids,
|
67 |
+
min_length=15,
|
68 |
+
max_length=25,
|
69 |
+
no_repeat_ngram_size=3,
|
70 |
+
num_beams=8,
|
71 |
+
early_stopping=True,
|
72 |
+
do_sample=True,
|
73 |
+
num_return_sequences=6
|
74 |
+
)
|
75 |
+
tok.decode(output_ids[0])
|
76 |
+
# '</s><s> Jag har ätit en utsökt middag på restaurang vid havet. Jag har varit ute och gått en sväng.</s><pad><pad>'
|
77 |
+
|
78 |
+
|
79 |
+
# Diverse beam generation
|
80 |
+
output_ids = model.generate(
|
81 |
+
input_ids,
|
82 |
+
min_length=50,
|
83 |
+
max_length=100,
|
84 |
+
no_repeat_ngram_size=3,
|
85 |
+
num_beams=8,
|
86 |
+
early_stopping=True,
|
87 |
+
do_sample=False,
|
88 |
+
num_return_sequences=6,
|
89 |
+
num_beam_groups=6,
|
90 |
+
diversity_penalty=2.0,
|
91 |
+
)
|
92 |
+
tok.decode(output_ids[0])
|
93 |
+
# '</s><s> Jag har ätit en utsökt middag på restaurang vid havet. Jag har varit ute och gått en sväng.</s><pad><pad>'
|
94 |
+
|
95 |
+
```
|
config.json
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"activation_dropout": 0.0,
|
3 |
+
"activation_function": "gelu",
|
4 |
+
"architectures": [
|
5 |
+
"BartForConditionalGeneration"
|
6 |
+
],
|
7 |
+
"attention_dropout": 0.0,
|
8 |
+
"bos_token_id": 0,
|
9 |
+
"classifier_dropout": 0.0,
|
10 |
+
"d_model": 768,
|
11 |
+
"decoder_attention_heads": 16,
|
12 |
+
"decoder_ffn_dim": 3072,
|
13 |
+
"decoder_layerdrop": 0.0,
|
14 |
+
"decoder_layers": 6,
|
15 |
+
"decoder_start_token_id": 2,
|
16 |
+
"dropout": 0.1,
|
17 |
+
"encoder_attention_heads": 16,
|
18 |
+
"encoder_ffn_dim": 3072,
|
19 |
+
"encoder_layerdrop": 0.0,
|
20 |
+
"encoder_layers": 6,
|
21 |
+
"eos_token_id": 2,
|
22 |
+
"forced_eos_token_id": 2,
|
23 |
+
"id2label": {
|
24 |
+
"0": "LABEL_0",
|
25 |
+
"1": "LABEL_1",
|
26 |
+
"2": "LABEL_2"
|
27 |
+
},
|
28 |
+
"init_std": 0.02,
|
29 |
+
"is_encoder_decoder": true,
|
30 |
+
"label2id": {
|
31 |
+
"LABEL_0": 0,
|
32 |
+
"LABEL_1": 1,
|
33 |
+
"LABEL_2": 2
|
34 |
+
},
|
35 |
+
"max_position_embeddings": 1024,
|
36 |
+
"model_type": "bart",
|
37 |
+
"num_hidden_layers": 6,
|
38 |
+
"pad_token_id": 1,
|
39 |
+
"scale_embedding": false,
|
40 |
+
"torch_dtype": "float32",
|
41 |
+
"transformers_version": "4.12.3",
|
42 |
+
"use_cache": true,
|
43 |
+
"vocab_size": 50185
|
44 |
+
}
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f740768be24a442236315bcad0804f5f15c9ac452e6b2f6d80e89f088b2e21f2
|
3 |
+
size 557735955
|
special_tokens_map.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"bos_token": "<s>", "eos_token": "</s>", "unk_token": "<unk>", "sep_token": "</s>", "pad_token": "<pad>", "cls_token": "</s>", "mask_token": "<mask>"}
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tokenizer_config.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"bos_token": "<s>", "eos_token": "</s>", "unk_token": "<unk>", "pad_token": "<pad>", "mask_token": "<mask>", "cls_token": "</s>", "sep_token": "</s>", "tokenizer_class": "PreTrainedTokenizerFast"}
|